-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from hagento/dev
New HDD/CDD calculation added
- Loading branch information
Showing
57 changed files
with
3,098 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")), | ||
|
@@ -23,8 +23,14 @@ Imports: | |
brick (>= 0.1.3), | ||
dplyr, | ||
GDPuc, | ||
ncdf4, | ||
openxlsx, | ||
plyr, | ||
pracma, | ||
raster, | ||
rlang, | ||
stringr, | ||
terra, | ||
quadprog, | ||
quitte, | ||
readxl, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | ||
} |
Oops, something went wrong.