Skip to content

Commit

Permalink
Merge branch 'main' of github.com:pik-piam/mredgebuildings into uvalues
Browse files Browse the repository at this point in the history
  • Loading branch information
fbenke-pik committed Sep 11, 2024
2 parents da9f48d + 61b80bd commit afa9495
Show file tree
Hide file tree
Showing 105 changed files with 6,156 additions and 699 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '1232870'
ValidationKey: '1397480'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand Down
23 changes: 1 addition & 22 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,8 @@
.RData
.Ruserdata
.DS_Store
R/convertWEO.R
R/readWEO.R
inst/extdata/.DS_Store
inst/extdata/regional/.DS_Store
inst/extdata/regional/regionmappingEUshares.csv
inst/extdata/regional/regionmappingIEA_ETP-Shares.csv
inst/extdata/regional/regionmappingISO-EDGE_EUR_ETP.csv
inst/extdata/regional/regionmappingWEO.csv
inst/extdata/sectoral/baitregression-files_test.csv
inst/regional/
inst/sectoral/
man/aggCells.Rd
man/blend.Rd
man/calcBAIT.Rd
man/calcBAITpars.Rd
man/calcCellHDDCDD.Rd
man/calcHDDCDDFactors.Rd
man/calcStackHDDCDD.Rd
man/cfac.Rd
man/checkDates.Rd
man/convertISIMIPbuildings.Rd
man/convertWEO.Rd
man/prepBaitInput.Rd
man/readISIMIPbuildings.Rd
man/readWEO.Rd
man/smooth.Rd
inst/sectoral/
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.6.2
date-released: '2024-06-11'
version: 0.7.0
date-released: '2024-08-29'
abstract: Prepare data to be used by the EDGE-Buildings model.
authors:
- family-names: Hasse
given-names: Robin
email: robin.hasse@pik-potsdam.de
orcid: 0000-0003-1818-3186
orcid: https://orcid.org/0000-0003-1818-3186
- family-names: Führlich
given-names: Pascal
email: pascal.fuehrlich@pik-potsdam.de
Expand Down
9 changes: 5 additions & 4 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-06-11
Version: 0.7.0
Date: 2024-08-29
Authors@R: c(
person("Robin", "Hasse", , "robin.hasse@pik-potsdam.de", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-1818-3186")),
Expand All @@ -20,11 +20,12 @@ Depends:
mrcommons (>= 1.35.0),
mrremind (>= 0.175.4)
Imports:
brick (>= 0.1.3),
brick (>= 0.5.0),
dplyr,
GDPuc,
ncdf4,
openxlsx,
purrr,
plyr,
pracma,
raster,
Expand All @@ -43,4 +44,4 @@ Suggests:
testthat
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
20 changes: 20 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export(calcCarrierPrices)
export(calcCostConstruction)
export(calcCostDemolition)
export(calcCostRenovation)
export(calcEfficiencyRegression)
export(calcFEUE)
export(calcFEUEefficiencies)
export(calcFEbyEUEC)
export(calcFEdemandBuildings)
export(calcFloorspacePast)
export(calcHeatingCapacity)
Expand All @@ -14,10 +18,12 @@ export(calcIEAPFU)
export(calcIEAfloorspace)
export(calcLifetimeParams)
export(calcMatchingReference)
export(calcPFUDB)
export(calcPopulationBuildings)
export(calcRenovationCostModel)
export(calcShareETP)
export(calcShareOdyssee)
export(calcShareTCEP)
export(calcSharesBuildingDemand)
export(calcSurface)
export(calcUEdemand)
Expand All @@ -35,6 +41,8 @@ export(convertEurostatBuildings)
export(convertGDL)
export(convertHDDCDD)
export(convertOdyssee)
export(convertPFUDB)
export(convertTCEP)
export(convertUNHouseholds)
export(fullEDGEBUILDINGS)
export(getFEbyEUEC)
Expand All @@ -55,9 +63,12 @@ export(readGDL)
export(readHotmaps)
export(readIEAfloorspace)
export(readOdyssee)
export(readPFUDB)
export(readTCEP)
export(readUNHouseholds)
export(toolCountryFillAvg)
export(toolDisaggregate)
export(toolSplitBiomass)
export(toolUnitConversion)
import(madrat)
import(magclass)
Expand Down Expand Up @@ -86,6 +97,7 @@ importFrom(dplyr,left_join)
importFrom(dplyr,matches)
importFrom(dplyr,mutate)
importFrom(dplyr,n)
importFrom(dplyr,pull)
importFrom(dplyr,reframe)
importFrom(dplyr,relocate)
importFrom(dplyr,rename)
Expand Down Expand Up @@ -122,9 +134,12 @@ importFrom(ncdf4,nc_open)
importFrom(openxlsx,read.xlsx)
importFrom(plyr,revalue)
importFrom(pracma,integral2)
importFrom(purrr,reduce)
importFrom(quadprog,solve.QP)
importFrom(quitte,aggregate_map)
importFrom(quitte,as.quitte)
importFrom(quitte,calc_addVariable)
importFrom(quitte,factor.data.frame)
importFrom(quitte,getPeriods)
importFrom(quitte,getRegs)
importFrom(quitte,inline.data.frame)
Expand All @@ -133,8 +148,12 @@ 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)
importFrom(stats,SSasymp)
importFrom(stats,as.formula)
importFrom(stats,coef)
importFrom(stats,dnorm)
importFrom(stats,lm)
Expand All @@ -160,6 +179,7 @@ importFrom(terra,writeCDF)
importFrom(tidyr,"%>%")
importFrom(tidyr,complete)
importFrom(tidyr,gather)
importFrom(tidyr,one_of)
importFrom(tidyr,pivot_longer)
importFrom(tidyr,pivot_wider)
importFrom(tidyr,replace_na)
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
69 changes: 69 additions & 0 deletions R/calcDensity.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#' Get Population Density
#'
#' @returns magpie object
#'
#' @author Hagen Tockhorn
#'
#' @importFrom madrat calcOutput
#' @importFrom dplyr select mutate rename
#' @importFrom quitte as.quitte
#' @importFrom magclass as.magpie


calcDensity <- function() {

# READ-IN DATA----------------------------------------------------------------

pop <- calcOutput("PopulationPast", aggregate = FALSE) %>%
as.quitte()

surf <- calcOutput("Surface", aggregate = FALSE) %>%
as.quitte()


# PARAMETERS------------------------------------------------------------------

# Conversion from 1-e6 --> 1e0
million2unit <- 1e6


# PROCESS DATA----------------------------------------------------------------

# Clean DFs
pop <- pop %>%
select(-"model", -"scenario", -"unit", -"variable") %>%
mutate(value = .data[["value"]] * million2unit) %>%
rename(population = "value")

surf <- surf %>%
select(-"model", -"scenario", -"unit", -"variable", -"period") %>%
rename(surface = "value")

# Calculate Density
dens <- left_join(pop, surf, by = "region") %>%
mutate(value = .data[["population"]] / (.data[["surface"]] * 1e3)) %>%
select(-"population", -"surface")


# Fill inf values with global density average
avgDens <- mean(dens[!is.infinite(dens$value), ]$value)

dens <- dens %>%
mutate(value = ifelse(is.infinite(.data[["value"]]),
avgDens,
.data[["value"]]))



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

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

return(list(x = data,
weight = NULL,
unit = "m^-2",
description = "Population Density in m^-2"))
}
Loading

0 comments on commit afa9495

Please sign in to comment.