Skip to content

Commit

Permalink
Merge pull request #23 from hagento/dev
Browse files Browse the repository at this point in the history
New HDD/CDD calculation added
  • Loading branch information
hagento authored Apr 8, 2024
2 parents efc530b + 68dc604 commit b08f2dd
Show file tree
Hide file tree
Showing 57 changed files with 3,098 additions and 120 deletions.
3 changes: 2 additions & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
ValidationKey: '984200'
ValidationKey: '1188540'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
AcceptedNotes: 'Unexported object imported by a .:::. call: .GDPuc:::wb_wdi.'
allowLinterWarnings: no
enforceVersionUpdate: no
5 changes: 5 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ jobs:
shell: Rscript {0}
run: lucode2:::validkey(stopIfInvalid = TRUE)

- name: Verify that lucode2::buildLibrary was successful
if: github.event_name == 'pull_request'
shell: Rscript {0}
run: lucode2:::isVersionUpdated()

- name: Checks
shell: Rscript {0}
run: |
Expand Down
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,30 @@
.Rhistory
.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
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: v0.3.2.9025
rev: v0.4.0
hooks:
- id: parsable-R
- id: deps-in-desc
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.5.0
date-released: '2023-11-23'
version: 0.6.0
date-released: '2024-03-27'
abstract: Prepare data to be used by the EDGE-Buildings model.
authors:
- family-names: Hasse
Expand Down
10 changes: 8 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.5.0
Date: 2023-11-23
Version: 0.6.0
Date: 2024-03-27
Authors@R: c(
person("Robin", "Hasse", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-1818-3186")),
Expand All @@ -23,8 +23,14 @@ Imports:
brick (>= 0.1.3),
dplyr,
GDPuc,
ncdf4,
openxlsx,
plyr,
pracma,
raster,
rlang,
stringr,
terra,
quadprog,
quitte,
readxl,
Expand Down
25 changes: 21 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export(calcCostDemolition)
export(calcCostRenovation)
export(calcFEdemandBuildings)
export(calcFloorspacePast)
export(calcHDDCDD)
export(calcHeatingCapacity)
export(calcHeatingSystem)
export(calcHouseholdSize)
Expand Down Expand Up @@ -111,16 +110,16 @@ importFrom(magclass,dimSums)
importFrom(magclass,getItems)
importFrom(magclass,getNames)
importFrom(magclass,getSets)
importFrom(magclass,getYears)
importFrom(magclass,lowpass)
importFrom(magclass,mbind)
importFrom(magclass,mselect)
importFrom(magclass,setNames)
importFrom(magclass,setYears)
importFrom(magclass,time_interpolate)
importFrom(ncdf4,nc_open)
importFrom(openxlsx,read.xlsx)
importFrom(plyr,revalue)
importFrom(pracma,integral2)
importFrom(quadprog,solve.QP)
importFrom(quitte,aggregate_map)
importFrom(quitte,as.quitte)
importFrom(quitte,calc_addVariable)
importFrom(quitte,getPeriods)
Expand All @@ -130,14 +129,32 @@ importFrom(quitte,interpolate_missing_periods)
importFrom(quitte,removeColNa)
importFrom(quitte,replace_column)
importFrom(quitte,revalue.levels)
importFrom(raster,writeRaster)
importFrom(readxl,read_xlsx)
importFrom(rlang,.data)
importFrom(stats,coef)
importFrom(stats,dnorm)
importFrom(stats,lm)
importFrom(stats,median)
importFrom(stats,na.omit)
importFrom(stats,nls)
importFrom(stats,predict)
importFrom(stats,pweibull)
importFrom(stringr,str_detect)
importFrom(stringr,str_split)
importFrom(stringr,str_sub)
importFrom(terra,aggregate)
importFrom(terra,classify)
importFrom(terra,ext)
importFrom(terra,nlyr)
importFrom(terra,rast)
importFrom(terra,regress)
importFrom(terra,res)
importFrom(terra,setGDALconfig)
importFrom(terra,subset)
importFrom(terra,tapp)
importFrom(terra,writeCDF)
importFrom(tidyr,"%>%")
importFrom(tidyr,complete)
importFrom(tidyr,gather)
importFrom(tidyr,pivot_longer)
Expand Down
82 changes: 82 additions & 0 deletions R/calcBAITpars.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#' calculate regression parameters for BAIT climate variables
#'
#' @description linear regression on historic data to determine regression
#' parameters for surface downdwelling shortwave radiation (rsds), near-surface
#' wind speed (sfcwind) and near-surface specific humidity (huss) with respect
#' to near-surface air temperature (tas).
#' The regression is done with on a simple linear model, where the historical
#' input data covers the years of 2000-2014. For rsds and sfcwind, a simple linear
#' relationship is assumed where for huss an exponential relation is assumed,
#' buildig upon the non-linear relation between water vapor pressure and temperature.
#'
#' @param model specify GCM responsible for data input
#'
#' @return terra SpatRaster covering one regression parameter per layer per cell
#'
#' @author Hagen Tockhorn
#'
#' @importFrom terra regress rast
#' @importFrom madrat toolGetMapping
#' @importFrom magclass as.magpie
#' @importFrom madrat readSource


calcBAITpars <- function(model = "GFDL-ESM4") {

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

files <- toolGetMapping("baitregression-files_test.csv", type = "sectoral") %>%
filter(.data[["gcm"]] == model)

vars <- unique(files$variable)

# nolint start
data <- sapply(vars, function(v) {
tmp <- sapply(files[files$variable == v, ]$file,
function(f) {
return(readSource("ISIMIPbuildings", subtype = f))
},
USE.NAMES = FALSE) %>%
rast()

return(tmp)
},
USE.NAMES = TRUE)
# nolint end

print("Reading completed")



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

# convert huss into log scale
data$huss <- log(data$huss)

# convert tas into [C]
data$tas <- data$tas - 273.15


# nolint start
regPars <- sapply(vars[vars != "tas"], function(v) {
x <- data[["tas"]]
y <- data[[v]]

r <- regress(x = x, y = y, formula = y ~ x)

names(r) <- c(paste0("a_", v), paste0("b_", v))
return(r)
},
USE.NAMES = FALSE) %>%
rast()
# nolint end



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

return(list(x = regPars,
class = "SpatRaster",
unit = "(unit)",
description = "Regression parameters for calcHDDCDD"))
}
Loading

0 comments on commit b08f2dd

Please sign in to comment.