Skip to content

Commit

Permalink
rebase with new version
Browse files Browse the repository at this point in the history
  • Loading branch information
hagento committed Aug 29, 2024
2 parents cb68271 + 8aff157 commit b35b95a
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '1390130'
ValidationKey: '1236714'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
- id: mixed-line-ending

- repo: https://github.com/lorenzwalthert/precommit
rev: 7910e0323d7213f34275a7a562b9ef0fde8ce1b9 # frozen: v0.4.2
rev: bae853d82da476eee0e0a57960ee6b741a3b3fb7 # frozen: v0.4.3
hooks:
- id: parsable-R
- id: deps-in-desc
Expand Down
6 changes: 3 additions & 3 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ 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.0
date-released: '2024-05-16'
version: 0.6.2
date-released: '2024-08-12'
abstract: Prepare data to be used by the EDGE-Buildings model.
authors:
- family-names: Hasse
given-names: Robin
email: [email protected]
orcid: 0000-0003-1818-3186
orcid: https://orcid.org/0000-0003-1818-3186
- family-names: Führlich
given-names: Pascal
email: [email protected]
Expand Down
6 changes: 3 additions & 3 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.0
Date: 2024-05-16
Version: 0.6.2
Date: 2024-08-12
Authors@R: c(
person("Robin", "Hasse", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-1818-3186")),
Expand All @@ -20,7 +20,7 @@ Depends:
mrcommons (>= 1.35.0),
mrremind (>= 0.175.4)
Imports:
brick (>= 0.1.3),
brick (>= 0.5.0),
dplyr,
GDPuc,
ncdf4,
Expand Down
25 changes: 14 additions & 11 deletions R/calcCarrierPrices.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,9 @@ calcCarrierPrices <- function() {

# map ECEMF carriers
# assumption: liquids and gases remain fossil
carrierMap <- inline.data.frame(
"carrierECEMF; carrier",
"Gases - Fossil Gas; gases",
"Liquids - Oil; liquids",
"Liquids - Biomass; NA",
"Electricity; elec",
"Hydrogen; NA",
"Solids - Coal; coal",
"Solids - Biomass; biomod"
)
carrierMap <- toolGetMapping("carrierMapping_ECEMF.csv",
type = "sectoral",
where = "mredgebuildings")

# all considered price components
# (drop CO2 price as this is a scenario assumption)
Expand Down Expand Up @@ -186,7 +179,17 @@ calcCarrierPrices <- function() {

# Combine data ---------------------------------------------------------------

data <- rbind(prices, emi) %>%
data <- rbind(prices, emi)

# all carriers included?
carrier <- unique(getBrickMapping("heatingSystem.csv")["carrier"])
data <- data %>%
right_join(carrier, by = "carrier")
if (any(is.na(data))) {
stop("Incomplete mapping of energy carriers.")
}

data <- data %>%
as.quitte() %>%
as.magpie()

Expand Down
35 changes: 27 additions & 8 deletions R/calcCostRenovation.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ calcCostRenovation <- function(energyLadder = FALSE) {
## Heating mark down ====

# decrease installation cost if there is no technology switch
sameHsFactor <- 0.9
sameHsFactor <- 0.2



Expand Down Expand Up @@ -137,7 +137,7 @@ calcCostRenovation <- function(energyLadder = FALSE) {
as.quitte(na.rm = TRUE) %>%
select("region", "typ", "vin", "bs", capacity = "value")

# heating system installation cost: USD/kW -> USD/m2
# heating system purchasing cost: USD/kW -> USD/m2
heatingCost <- calcOutput("HeatingSystem",
subtype = "Purchasing cost",
aggregate = FALSE) %>%
Expand All @@ -157,19 +157,38 @@ calcCostRenovation <- function(energyLadder = FALSE) {
.data[["hsr"]])) %>%
left_join(heatingCost, by = c(hs.final = "hs"),
relationship = "many-to-many") %>%
mutate(heatingCost = ifelse(.data[["hs"]] == .data[["hsr"]],
sameHsFactor * .data[["heatingCost"]],
ifelse(.data[["hsr"]] == "0",
0,
.data[["heatingCost"]]))) %>%
mutate(heatingCost = ifelse(.data[["hsr"]] == "0",
0,
.data[["heatingCost"]])) %>%
select(-"hs.final")

# heating system installation cost (independent of capacity)
# rough numbers from BDEW Heizkostenvergleich cost/floor
installationCost <- inline.data.frame(
"typ; installationCost",
"SFH; 30",
"MFH; 10",
"Com; 6"
)
heatingCost <- heatingCost %>%
left_join(installationCost, by = "typ") %>%
mutate(installationCost = .data[["installationCost"]] *
ifelse(.data[["hsr"]] == "0",
0,
ifelse(.data[["hsr"]] == "reel",
0.1,
ifelse(.data[["hs"]] == .data[["hsr"]],
sameHsFactor,
1))),
heatingCost = .data[["heatingCost"]] + .data[["installationCost"]]) %>%
select(-"installationCost")

# mark up for installation of central heating system (piping, etc.)
# https://www.checkatrade.com/blog/cost-guides/central-heating-installation-cost/
heatingCost <- heatingCost %>%
mutate(heatingCost = .data[["heatingCost"]] +
ifelse(.data[["hs"]] == "reel" & !.data[["hsr"]] %in% c("0", "reel"),
3000 / 150 * 1.21, # units GBP/m2 * USD/GBP
3000 / 150 * 1.21, # units: GBP / m2 * USD/GBP # nolint: commented_code_linter.
0))

## Total ====
Expand Down
2 changes: 1 addition & 1 deletion R/calcHeatingCapacity.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ calcHeatingCapacity <- function(swissFormular = FALSE) {
heatCap <- ueDem / flh
} else {
# reference heating capacity from online tool (SFH, after 1994)
heatCapRef <- 0.060 # in kW/m2
heatCapRef <- 0.100 # in kW/m2


# heating degree days
Expand Down
34 changes: 29 additions & 5 deletions R/calcHeatingSystem.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#'
#' @author Robin Hasse
#'
#' @importFrom brick getBrickMapping
#' @importFrom madrat toolGetMapping readSource toolCountryFill
#' @importFrom magclass as.magpie getSets<- setNames mbind dimSums
#' time_interpolate
Expand All @@ -21,14 +22,22 @@ calcHeatingSystem <- function(subtype = c("Purchasing cost", "Efficiency")) {

subtype <- match.arg(subtype)

# all heating technologies
hsMap <- getBrickMapping("heatingSystem.csv")

# map heating technologies
hsMap <- toolGetMapping("technologyMapping_EU_ReferenceScenario.csv",
type = "sectoral", where = "mredgebuildings",
returnPathOnly = TRUE) %>%
euRefMap <- toolGetMapping("technologyMapping_EU_ReferenceScenario.csv",
type = "sectoral", where = "mredgebuildings",
returnPathOnly = TRUE) %>%
read.csv(comment.char = "") %>%
select(-"comment") %>%
pivot_longer(matches("^weight"), names_to = "typ", values_to = "weight") %>%
mutate(typ = sub("^weight(.*)$", "\\1", .data[["typ"]]))
mutate(typ = sub("^weight(.*)$", "\\1", .data[["typ"]])) %>%
right_join(unique(hsMap["hs"]), by = c(technologyBRICK = "hs"))

if (any(is.na(euRefMap))) {
stop("Incomplete mapping of heating technologies.")
}

# map building types to subsectors
typMap <- inline.data.frame(
Expand All @@ -53,7 +62,7 @@ calcHeatingSystem <- function(subtype = c("Purchasing cost", "Efficiency")) {
.data[["level"]] %in% c("Current", "central")) %>%
left_join(typMap, by = "subsector", relationship = "many-to-many") %>%
left_join(periodMap, by = "pointintime") %>%
left_join(hsMap, by = c("typ", "technology")) %>%
left_join(euRefMap, by = c("typ", "technology"), relationship = "many-to-many") %>%
select("region", "period", hs = "technologyBRICK", "typ", "unit", "value",
"weight") %>%
filter(!is.na(.data[["hs"]])) %>%
Expand All @@ -65,6 +74,21 @@ calcHeatingSystem <- function(subtype = c("Purchasing cost", "Efficiency")) {

switch(subtype,
`Purchasing cost` = {
# until here, H2 boilers are just condensing gas boilers. We add
# 2500€/unit for the conversion to 100% H2 readiness (cf. ISE
# Heizkostenvergleich) and assume 10kW/unit capacity
# (cf. BDEW Heizkostenvergleich). The mark up reduces linearly to half its
# value until 2050. The value is deflated (1.39) to be consistent.
data <- data.frame(period = c(2020, 2050),
hs = "h2bo",
h2MarkUp = c(250, 125) / 1.39) %>%
interpolate_missing_periods(unique(data[["period"]]),
value = "h2MarkUp",
expand.values = TRUE) %>%
right_join(data, by = c("period", "hs")) %>%
mutate(value = .data[["value"]] + replace_na(.data[["h2MarkUp"]], 0)) %>%
select(-"h2MarkUp")

# unit conversion EUR/kW -> USD/kW
usd2eur <- usd2eur()
data <- data %>%
Expand Down
54 changes: 34 additions & 20 deletions R/calcLifetimeParams.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
#'
#' @author Robin Hasse
#'
#' @importFrom brick getBrickMapping
#' @importFrom madrat readSource calcOutput
#' @importFrom magclass add_dimension as.magpie mselect getSets mbind
#' @importFrom quitte inline.data.frame
#' @importFrom dplyr .data %>% mutate filter everything
#' right_join
#' @importFrom tidyr pivot_longer
#' @export

Expand Down Expand Up @@ -62,27 +64,29 @@ calcLifetimeParams <- function(subtype) {
# delay is approximated by adding it to the scale
params <- inline.data.frame(
"subsector; hs; scale; shape",
"residential; ehp1; 16.88; 2" # Residential Air-Source Heat Pumps
"Res; ehp1; 16.88; 2" # Residential Air-Source Heat Pumps
)

# technologies given with typical ranges
ranges <- inline.data.frame(
"subsector; hs; from; to",
"residential; biom; 12; 25", # Residential Cordwood / Wood Pallet Stoves
"residential; gabo; 20; 30", # Residential Gas-Fired Boilers
"residential; reel; 15; 30", # Residential Electric Resistance (Unit) Heaters
"residential; libo; 18; 28" # Residential Oil-Fired Boilers
"Res; biom; 12; 25", # Residential Cordwood / Wood Pallet Stoves
"Res; h2bo; 20; 30", # Residential Gas-Fired Boilers
"Res; gabo; 20; 30", # Residential Gas-Fired Boilers
"Res; reel; 15; 30", # Residential Electric Resistance (Unit) Heaters
"Res; libo; 18; 28" # Residential Oil-Fired Boilers
)

# technologies given only with central estimate
central <- inline.data.frame(
"subsector; hs; mean",
"commercial; ehp1; 21", # Commercial Rooftop Heat Pumps
"commercial; gabo; 25", # Commercial Gas-Fired Boilers
"commercial; reel; 18", # Commercial Electric Resistance Heaters
"commercial; libo; 25", # Commercial Oil-Fired Boilers
"residential; dihe; 30", # value assumed, not from EIA
"commercial; dihe; 30" # value assumed, not from EIA
"subsector; hs; mean",
"Com; ehp1; 21", # Commercial Rooftop Heat Pumps
"Com; h2bo; 25", # Commercial Gas-Fired Boilers
"Com; gabo; 25", # Commercial Gas-Fired Boilers
"Com; reel; 18", # Commercial Electric Resistance Heaters
"Com; libo; 25", # Commercial Oil-Fired Boilers
"Res; dihe; 30", # value assumed, not from EIA
"Com; dihe; 30" # value assumed, not from EIA
)


Expand Down Expand Up @@ -147,23 +151,30 @@ calcLifetimeParams <- function(subtype) {
# assume residential biomass value for commercial
params <- params %>%
rbind(params %>%
filter(.data[["subsector"]] == "residential",
filter(.data[["subsector"]] == "Res",
.data[["hs"]] == "biom") %>%
mutate(subsector = "commercial"))
mutate(subsector = "Com"))

# assume biomass values for coal
params <- params %>%
rbind(params %>%
filter(.data[["hs"]] == "biom") %>%
mutate(hs = "sobo"))

# all technologies included?
hs <- getBrickMapping("heatingSystem.csv")
params <- params %>%
right_join(hs["hs"], by = "hs")
if (any(is.na(params))) {
stop("Incomplete mapping of heating technologies.")
}



### map to building types ####
typMap <- c(
SFH = "residential",
MFH = "residential",
Com = "commercial"
)
typMap <- getBrickMapping("buildingType.csv")
typMap <- stats::setNames(typMap[["subsector"]], typMap[["typ"]])

params <- params %>%
pivot_longer(c("scale", "shape"), names_to = "variable") %>%
as.magpie(datacol = "value")
Expand Down Expand Up @@ -218,7 +229,10 @@ calcLifetimeParams <- function(subtype) {
# weight: FE demand
feBuildings <- calcOutput("FEdemandBuildings", aggregate = FALSE) %>%
mselect(period = "y2020", collapseNames = TRUE)
if (!"typ" %in% getSets(params)) {
if ("typ" %in% getSets(params)) {
feBuildings <- feBuildings %>%
mselect(typ = getItems(params, "typ"))
} else {
feBuildings <- dimSums(feBuildings)
}

Expand Down
2 changes: 1 addition & 1 deletion R/usd2eur.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

usd2eur <- function(year = 2020) {
GDPuc:::wb_wdi %>% # nolint: undesirable_operator_linter.
filter(.data[["year"]] == year, .data[["iso3c"]] == "DEU") %>%
filter(.data[["year"]] == !!year, .data[["iso3c"]] == "DEU") %>%
getElement("MER (LCU per US$)") %>%
mean()
}
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Prepare data to be used by the EDGE-Buildings model

R package **mredgebuildings**, version **0.7.0**
R package **mredgebuildings**, version **0.6.2**

[![CRAN status](https://www.r-pkg.org/badges/version/mredgebuildings)](https://cran.r-project.org/package=mredgebuildings) [![R build status](https://github.com/pik-piam/mredgebuildings/workflows/check/badge.svg)](https://github.com/pik-piam/mredgebuildings/actions) [![codecov](https://codecov.io/gh/pik-piam/mredgebuildings/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mredgebuildings) [![r-universe](https://pik-piam.r-universe.dev/badges/mredgebuildings)](https://pik-piam.r-universe.dev/builds)

Expand Down Expand Up @@ -38,7 +38,7 @@ In case of questions / problems please contact Robin Hasse <robin.hasse@pik-pots

To cite package **mredgebuildings** in publications use:

Hasse R, Führlich P, Levesque A, Tockhorn H (2024). _mredgebuildings: Prepare data to be used by the EDGE-Buildings model_. R package version 0.7.0, <https://github.com/pik-piam/mredgebuildings>.
Hasse R, Führlich P, Levesque A, Tockhorn H (2024). _mredgebuildings: Prepare data to be used by the EDGE-Buildings model_. R package version 0.6.2, <https://github.com/pik-piam/mredgebuildings>.

A BibTeX entry for LaTeX users is

Expand All @@ -47,7 +47,11 @@ A BibTeX entry for LaTeX users is
title = {mredgebuildings: Prepare data to be used by the EDGE-Buildings model},
author = {Robin Hasse and Pascal Führlich and Antoine Levesque and Hagen Tockhorn},
year = {2024},
<<<<<<< HEAD
note = {R package version 0.7.0},
=======
note = {R package version 0.6.2},
>>>>>>> 8aff157d9945bce34154e6bab672c915009a6bf7
url = {https://github.com/pik-piam/mredgebuildings},
}
```
8 changes: 8 additions & 0 deletions inst/extdata/sectoral/carrierMapping_ECEMF.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
carrierECEMF,carrier
Gases - Fossil Gas,gases
Liquids - Oil,liquids
Liquids - Biomass,NA
Electricity,elec
Hydrogen,h2
Solids - Coal,coal
Solids - Biomass,biomod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
technology,technologyBRICK,weightSFH,weightMFH,weightCom,comment
Boilers gas (non-condensing),gabo,0.1,0.07,0.05,
Boilers gas condensing*,gabo,0.8,0.67,0.45,
Boilers gas condensing*,h2bo,1,0.75,0,
Boilers oil (non-condensing),libo,0.8,0.8,0.8,
Boilers oil condensing*,libo,0.2,0.2,0.2,
Wood stoves or boiler pellets,biom,1,1,1,
Expand All @@ -16,4 +17,5 @@ CHP fuel cell**,NA,,,,
District heating,dihe,1,1,1,
Large scale gas boilers (non-condensing),gabo,0,0.03,0.05,
Large scale gas boilers condensing,gabo,0,0.23,0.45,
Large scale gas boilers condensing,h2bo,0,0.25,1,
Wood stoves or boiler pellets,sobo,1,1,1,we assume similarity between wood stoves and coal heaters

0 comments on commit b35b95a

Please sign in to comment.