Skip to content

Commit

Permalink
incorporated rest of PR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
hagento committed Aug 29, 2024
1 parent b35b95a commit d1b0778
Show file tree
Hide file tree
Showing 20 changed files with 315 additions and 285 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '1236714'
ValidationKey: '1397480'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cff-version: 1.2.0
message: If you use this software, please cite it using the metadata from this file.
type: software
title: 'mredgebuildings: Prepare data to be used by the EDGE-Buildings model'
version: 0.6.2
date-released: '2024-08-12'
version: 0.7.0
date-released: '2024-08-29'
abstract: Prepare data to be used by the EDGE-Buildings model.
authors:
- family-names: Hasse
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: mredgebuildings
Title: Prepare data to be used by the EDGE-Buildings model
Version: 0.6.2
Date: 2024-08-12
Version: 0.7.0
Date: 2024-08-29
Authors@R: c(
person("Robin", "Hasse", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-1818-3186")),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export(calcFEUE)
export(calcFEUEefficiencies)
export(calcFEbyEUEC)
export(calcFEdemandBuildings)
export(calcFloorspacePast)
export(calcHeatingCapacity)
export(calcHeatingSystem)
export(calcHouseholdSize)
Expand Down
31 changes: 9 additions & 22 deletions R/calcFloorspacePast.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
#' @author Robin Hasse, Antoine Levesque, Hagen Tockhorn
#'
#' @importFrom madrat readSource calcOutput toolCountryFill
#' @importFrom quitte as.quitte calc_addVariable factor.data.frame
#' @importFrom quitte as.quitte calc_addVariable factor.data.frame interpolate_missing_periods
#' @importFrom dplyr filter mutate select anti_join group_by left_join %>%
#' ungroup .data %>%
#' ungroup .data %>% group_modify
#' @importFrom rlang .data
#' @importFrom magclass mbind as.magpie collapseDim mselect
#' @importFrom tidyr spread
#' @importFrom tidyr spread replace_na
#'
#' @export

Expand All @@ -37,25 +37,12 @@ calcFloorspacePast <- function() {
}


#' Predict missing historic floorspace data
#'
#' A linear regression is performed to establish a general relationship between
#' floorspace per capita and gdp per capita and population density.
#' Predicted values are corrected w.r.t. to historical data where available,
#' otherwise the prediction is chosen.
#'
#' @param df data.frame containing floorspace per capita
#' @param gdppop data.frame containing gdp per capita
#' @param dens data.frame containing population density
#' @param endOfHistory upper temporal boundary of historic data
#' @param periodBegin lower temporal boundary of historic data
#'
#' @importFrom quitte factor.data.frame interpolate_missing_periods
#' @importFrom tidyr replace_na
#' @importFrom dplyr group_modify
#'
#' @returns floorspace per capita with filled missing entries

# Predict missing historic floorspace data
#
# A linear regression is performed to establish a general relationship between
# floorspace per capita and gdp per capita and population density.
# Predicted values are corrected w.r.t. to historical data where available,
# otherwise the prediction is chosen.
makeFloorspaceProjection <- function(df, gdppop, dens, endOfHistory, periodBegin) {

# Clean data
Expand Down
22 changes: 1 addition & 21 deletions R/calcPFUDB.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,6 @@ calcPFUDB <- function() {
}
}

# convert enduse "appliances" to "refrigerators" with respective scaling factor
addThermal <- function(df, mapping, fridgeShare) {
df <- df %>%
filter(.data[["enduse"]] != "lighting") %>%
left_join(mapping %>%
select(-"RegionCodeEUR", -"RegionCodeEUR_ETP", -"X") %>%
rename(region = "CountryCode") %>%
left_join(fridgeShare, by = "RegionCode") %>%
select(-"RegionCode"),
by = "region") %>%
mutate(value = ifelse(.data[["enduse"]] != "appliances",
.data[["value"]],
.data[["value"]] * .data[["share"]]),
enduse = ifelse(.data[["enduse"]] == "appliances",
"refrigerators",
as.character(.data[["enduse"]]))) %>%
select(-"share")
return(df)
}



# PARAMETERS -----------------------------------------------------------------
Expand Down Expand Up @@ -175,7 +155,7 @@ calcPFUDB <- function() {
mutate(value = ifelse(is.na(.data[["value.x"]]),
.data[["value.y"]],
.data[["value.x"]])) %>%
addThermal(regmappingEDGE, fridgeShare) %>%
toolAddThermal(regmappingEDGE, fridgeShare) %>%
select("region", "period", "carrier", "enduse", "value")


Expand Down
4 changes: 3 additions & 1 deletion R/calcShareETP.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ calcShareETP <- function(subtype = c("enduse", "carrier"), feOnly = FALSE) {
group_by(across(all_of(c("region", "period")))) %>%
mutate(value = proportions(.data[["value"]])) %>%
ungroup()
} else {
etpFilter <- shareCorr
}
}

Expand All @@ -188,7 +190,7 @@ calcShareETP <- function(subtype = c("enduse", "carrier"), feOnly = FALSE) {

# return only FE data
if (isTRUE(feOnly)) {
feData <- shareCorr %>%
feData <- etpFilter %>%
as.quitte() %>%
mutate(value = .data[["value"]] * PJ2EJ,
unit = "EJ") %>%
Expand Down
8 changes: 6 additions & 2 deletions R/calcShareOdyssee.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,17 @@ calcShareOdyssee <- function(subtype = c("enduse", "carrier", "enduse_carrier"),
meanApplightShares <- odyssee %>%
filter(.data[["enduse"]] %in% c("lighting", "appliances"),
!is.na(.data[["value"]])) %>%
group_by(across(all_of(c("region", "period", "sector", "carrier")))) %>%
group_by(across(all_of(c("period", "sector", "carrier", "enduse")))) %>%
mutate(value = sum(.data[["value"]], na.rm = TRUE)) %>%
ungroup() %>%
group_by(across(all_of(c("period", "sector", "carrier")))) %>%
mutate(value = proportions(.data[["value"]])) %>%
ungroup() %>%
group_by(across(all_of(c("period", "sector", "enduse")))) %>%
mutate(share = mean(.data[["value"]])) %>%
ungroup() %>%
select(all_of(c("period", "carrier", "sector", "enduse", "share")))
select(all_of(c("period", "carrier", "sector", "enduse", "share"))) %>%
unique()

# split existing aggregated data into "appliances" and "lighting"
applightData <- odysseeData %>%
Expand Down
Loading

0 comments on commit d1b0778

Please sign in to comment.