Skip to content

Commit

Permalink
Merge pull request #37 from robinhasse/complete_tgz
Browse files Browse the repository at this point in the history
Complete tgz with all input data for EDGE-B
  • Loading branch information
robinhasse authored Sep 13, 2024
2 parents 6388b02 + 8fbc746 commit c284da1
Show file tree
Hide file tree
Showing 34 changed files with 509 additions and 961 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '1418367'
ValidationKey: '1438488'
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.7.1
date-released: '2024-09-11'
version: 0.7.2
date-released: '2024-09-13'
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.7.1
Date: 2024-09-11
Version: 0.7.2
Date: 2024-09-13
Authors@R: c(
person("Robin", "Hasse", , "robin.hasse@pik-potsdam.de", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-1818-3186")),
Expand Down
8 changes: 4 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export(calcHeatingCapacity)
export(calcHeatingSystem)
export(calcHouseholdSize)
export(calcIEAPFU)
export(calcIEAfloorspace)
export(calcLifetimeParams)
export(calcMatchingReference)
export(calcPFUDB)
Expand All @@ -26,9 +25,10 @@ export(calcShareOdyssee)
export(calcShareTCEP)
export(calcSharesBuildingDemand)
export(calcSurface)
export(calcTCEP)
export(calcUEdemand)
export(calcUValue)
export(calcUvalues)
export(calcUValueSource)
export(convertCensusHub)
export(convertDaioglou)
export(convertDeetman2020)
Expand All @@ -40,6 +40,7 @@ export(convertEuropeanCommissionRenovation)
export(convertEurostatBuildings)
export(convertGDL)
export(convertHDDCDD)
export(convertHDDCDDtemp)
export(convertOdyssee)
export(convertPFUDB)
export(convertTCEP)
Expand All @@ -60,8 +61,8 @@ export(readEurObservER)
export(readEuropeanCommissionRenovation)
export(readEurostatBuildings)
export(readGDL)
export(readHDDCDDtemp)
export(readHotmaps)
export(readIEAfloorspace)
export(readOdyssee)
export(readPFUDB)
export(readTCEP)
Expand Down Expand Up @@ -148,7 +149,6 @@ importFrom(quitte,removeColNa)
importFrom(quitte,replace_column)
importFrom(quitte,revalue.levels)
importFrom(raster,writeRaster)
importFrom(readxl,read_excel)
importFrom(readxl,read_xlsx)
importFrom(rlang,.data)
importFrom(rlang,syms)
Expand Down
4 changes: 2 additions & 2 deletions R/calcEfficiencyRegression.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ calcEfficiencyRegression <- function() {
as.quitte()

# Get Mapping (ISO<->PFU)
regionmapping <- toolGetMapping("pfu_regionmapping.csv", type = "regional", where = "mredegebuildings")
regionmapping <- toolGetMapping("pfu_regionmapping.csv", type = "regional", where = "mredgebuildings")

# Get Population Data
pop <- calcOutput("PopulationPast", aggregate = FALSE) %>%
Expand Down Expand Up @@ -169,7 +169,7 @@ calcEfficiencyRegression <- function() {


return(list(x = parsFull,
weight = NA,
isocountries = FALSE,
description = "Regression Parameter for FE-UE-Efficiency Projection",
unit = ""))
}
7 changes: 3 additions & 4 deletions R/calcFloorspacePast.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ calcFloorspacePast <- function() {
mutate(pred = .data[["pred"]] * replace_na(.data[["factor"]], 1)) %>%

# fill missing values w/ predictions
mutate(value = .data[["pred"]] * replace_na(.data[["value"]], 1)) %>%
mutate(value = ifelse(is.na(.data[["value"]]), .data[["pred"]], .data[["value"]])) %>%

# select columns
select("region", "period", "variable", "unit", "demographic", "value")
Expand Down Expand Up @@ -128,12 +128,11 @@ calcFloorspacePast <- function() {
unit = "million m2")

# IEA data: take only India
ind <- readSource("IEAfloorspace", convert = FALSE) %>%
ind <- readSource("TCEP", subtype = "floorspace", convert = FALSE) %>%
as.quitte() %>%
filter(.data[["region"]] == "India",
.data[["period"]] %in% c(2000, 2011),
.data[["subsector"]] == "Residential") %>%
select(-"subsector") %>%
.data[["variable"]] == "Residential") %>%
mutate(variable = "floor space",
value = .data[["value"]] * 1000, # billion m2 -> million m2
unit = "million m2",
Expand Down
9 changes: 5 additions & 4 deletions R/calcGDPPop.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ calcGDPPop <- function() {

# LOAD DATA ------------------------------------------------------------------

gdp <- calcOutput("GDPPast", aggregate = FALSE, average2020 = FALSE) %>%
gdp <- calcOutput("GDP", aggregate = FALSE, average2020 = FALSE) %>%
mselect(variable = "gdp_SSP2") %>%
as.quitte()

pop <- calcOutput("PopulationPast", aggregate = FALSE) %>%
Expand All @@ -21,9 +22,9 @@ calcGDPPop <- function() {
# Join and Calculate
gdpPop <- gdp %>%
select(-"unit", -"model", -"variable", -"scenario") %>%
left_join(pop %>%
select(-"unit", -"model", -"variable", -"scenario"),
by = c("region", "period")) %>%
inner_join(pop %>%
select(-"unit", -"model", -"variable", -"scenario"),
by = c("region", "period")) %>%
mutate(value = .data[["value.x"]] / .data[["value.y"]],
variable = "gdppop in constant 2005 Int$PPP") %>%
select(-"value.x", -"value.y")
Expand Down
20 changes: 19 additions & 1 deletion R/calcHDDCDD.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#' @param multiscen boolean, does \code{mappingFile} cover more than one scenario?
#' @param rasDir absolute path to directory for saving raster files
#' @param cacheDir absolute path to directory for pre-calculated BAIT regression parameters
#' @param fromSource logical, if TRUE, read the previously calculated data that
#' is temporarily saved as a source
#'
#' @return magpie object of heating and cooling degree days
#'
Expand All @@ -26,7 +28,23 @@ calcHDDCDD <- function(mappingFile,
bait = FALSE,
multiscen = FALSE,
rasDir = NULL,
cacheDir = NULL) {
cacheDir = NULL,
fromSource = FALSE) {

if (isTRUE(fromSource)) {
# Read previously calculated data from source
hddcdd <- readSource("HDDCDDtemp")

weight <- hddcdd
weight[] <- 1

return(list(x = hddcdd,
min = 0,
weight = weight,
unit = "K.d/yr",
description = "Heating and cooling degree days"))
}


# initialize full calculation
makeCalculations <- function(f, m, n, tLim, countries, pop, hddcddFactor,
Expand Down
17 changes: 0 additions & 17 deletions R/calcIEAfloorspace.R

This file was deleted.

43 changes: 19 additions & 24 deletions R/calcShareOdyssee.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#' @importFrom madrat readSource toolCountryFill
#' @importFrom quitte as.quitte revalue.levels
#' @importFrom dplyr filter %>% mutate group_by across all_of left_join
#' summarise .data syms
#' summarise .data syms bind_rows pull
#' @importFrom tidyr separate replace_na complete
#' @importFrom utils tail
#' @export
Expand Down Expand Up @@ -81,7 +81,7 @@ calcShareOdyssee <- function(subtype = c("enduse", "carrier", "enduse_carrier"),
filter(.data[["variable"]] %in% paste0(vars, "_EJ"),
!is.na(.data[["value"]])) %>%
mutate(region = droplevels(.data[["region"]]),
variable = gsub("_.*$", "", .data[["variable"]])) %>%
variable = sub("_.*$", "", .data[["variable"]])) %>%
separate("variable", c("carrier", "sector", "enduse"), c(3, 8)) %>%
revalue.levels(carrier = carrierMap,
sector = sectorMap,
Expand Down Expand Up @@ -110,42 +110,37 @@ calcShareOdyssee <- function(subtype = c("enduse", "carrier", "enduse_carrier"),
filter(.data[["enduse"]] %in% c("lighting", "appliances"),
!is.na(.data[["value"]])) %>%
group_by(across(all_of(c("period", "sector", "carrier", "enduse")))) %>%
mutate(value = sum(.data[["value"]], na.rm = TRUE)) %>%
ungroup() %>%
summarise(value = sum(.data[["value"]], na.rm = TRUE), .groups = "drop") %>%
group_by(across(all_of(c("period", "sector", "carrier")))) %>%
mutate(value = proportions(.data[["value"]])) %>%
mutate(share = 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"))) %>%
unique()
select(-"value")

# split existing aggregated data into "appliances" and "lighting"
applightData <- odysseeData %>%
filter(.data[["variable"]] %in% paste0(vars, "_EJ"),
!is.na(.data[["value"]])) %>%
mutate(region = droplevels(.data[["region"]]),
variable = gsub("_.*$", "", .data[["variable"]])) %>%
variable = sub("_.*$", "", .data[["variable"]])) %>%
separate("variable", c("carrier", "sector", "enduse"), c(3, 8)) %>%
revalue.levels(carrier = carrierMap,
sector = sectorMap,
enduse = enduseMap) %>%
interpolate_missing_periods(expand.values = TRUE) %>%
pivot_wider(names_from = "enduse", values_from = "value") %>%
left_join(meanApplightShares,
by = c("period", "carrier", "sector"),
relationship = "many-to-many") %>%
mutate(value = .data[["appliances_light"]] * .data[["share"]]) %>%
select(all_of(c("region", "period", "carrier", "enduse", "sector", "value"))) %>%
unique()
filter(.data[["enduse"]] == "appliances_light") %>%
select(-"enduse") %>%
inner_join(meanApplightShares,
by = c("period", "carrier", "sector"),
relationship = "many-to-many") %>%
mutate(value = .data[["value"]] * .data[["share"]]) %>%
select("region", "period", "carrier", "enduse", "sector", "value")

# replace missing values
odyssee <- rbind(odyssee,
applightData %>%
anti_join(odyssee,
by = c("region", "period", "carrier", "enduse", "sector")) %>%
select(-"variable"))
odyssee <- applightData %>%
anti_join(odyssee,
by = c("region", "period", "carrier", "enduse", "sector")) %>%
bind_rows(odyssee)

}

if (feOnly) {
Expand Down Expand Up @@ -194,7 +189,7 @@ calcShareOdyssee <- function(subtype = c("enduse", "carrier", "enduse_carrier"),



# OUTPUT ---------------------------------------------------------------------
# OUTPUT -------------------------------------------------------------------

# Convert to magpie object
share <- share %>%
Expand Down
15 changes: 15 additions & 0 deletions R/calcTCEP.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#' IEA's Tracking clean energy progress 2014
#'
#' @param subtype character, type of data
#' @author Robin Hasse
#'
#' @importFrom madrat readSource
#' @export

calcTCEP <- function(subtype) {
return(list(x = readSource("TCEP", subtype, convert = FALSE),
min = 0,
isocountries = FALSE,
unit = "m2/cap",
description = "Floor space per capita"))
}
24 changes: 24 additions & 0 deletions R/calcUValueSource.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#' Passes U-values read from source
#'
#' @author Falk Benke, Robin Hasse
#'
#' @param subtype source of U-values
#' @export

calcUValueSource <- function(subtype = c("EUBuildingsObservatory", "ETSAP")) {

subtype <- match.arg(subtype)

x <- if (subtype == "EUBuildingsObservatory") {
readSource("EUBuildingsObservatory", convert = FALSE)
} else {
readSource("ETSAP", convert = FALSE)
}

return(list(x = x,
min = 0,
isocountries = FALSE,
unit = "W/m2K",
description = paste("U-values as reported by", subtype)
))
}
29 changes: 0 additions & 29 deletions R/calcUvalues.R

This file was deleted.

22 changes: 22 additions & 0 deletions R/convertHDDCDDtemp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#' Convert temporary HDD and CDD data
#'
#' The temporary data already is at EDGE-B regional resolution. It is uniformly
#' disaggregated to country level here to comply with the madrat framework
#' before it is aggregated to the identical resolution in fullEDGEBUILDINGS.
#'
#' @author Robin Hasse
#'
#' @param x MAgPIE object with HDD and CDD data at EDGE-B resolution
#' @returns HDD CDD data at country resolution
#'
#' @importFrom madrat toolGetMapping toolAggregate
#' @export

convertHDDCDDtemp <- function(x) {
mapping <- toolGetMapping(name = "regionmappingEDGE.csv",
type = "regional",
where = "mredgebuildings")

toolAggregate(x, mapping,
from = "RegionCodeEUR_ETP", to = "CountryCode")
}
Loading

0 comments on commit c284da1

Please sign in to comment.