diff --git a/.buildlibrary b/.buildlibrary index 73aed147..d6873214 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '224202816' +ValidationKey: '224267960' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2f134668..243f46a1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/CITATION.cff b/CITATION.cff index cd9c9a45..543110e9 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -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: 'remind2: The REMIND R package (2nd generation)' -version: 1.134.4 -date-released: '2024-02-11' +version: 1.134.5 +date-released: '2024-02-15' abstract: Contains the REMIND-specific routines for data and model output manipulation. authors: - family-names: Rodrigues diff --git a/DESCRIPTION b/DESCRIPTION index 0f05abd3..0e465a35 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: remind2 Title: The REMIND R package (2nd generation) -Version: 1.134.4 -Date: 2024-02-11 +Version: 1.134.5 +Date: 2024-02-15 Authors@R: c( person("Renato", "Rodrigues", , "renato.rodrigues@pik-potsdam.de", role = c("aut", "cre")), person("Lavinia", "Baumstark", role = "aut"), diff --git a/README.md b/README.md index e362e703..984e828d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # The REMIND R package (2nd generation) -R package **remind2**, version **1.134.4** +R package **remind2**, version **1.134.5** [![CRAN status](https://www.r-pkg.org/badges/version/remind2)](https://cran.r-project.org/package=remind2) [![R build status](https://github.com/pik-piam/remind2/workflows/check/badge.svg)](https://github.com/pik-piam/remind2/actions) [![codecov](https://codecov.io/gh/pik-piam/remind2/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/remind2) [![r-universe](https://pik-piam.r-universe.dev/badges/remind2)](https://pik-piam.r-universe.dev/builds) @@ -49,7 +49,7 @@ In case of questions / problems please contact Renato Rodrigues . +Rodrigues R, Baumstark L, Benke F, Dietrich J, Dirnaichner A, Duerrwaechter J, Führlich P, Giannousakis A, Hasse R, Hilaire J, Klein D, Koch J, Kowalczyk K, Levesque A, Malik A, Merfort A, Merfort L, Morena-Leiva S, Pehl M, Pietzcker R, Rauner S, Richters O, Rottoli M, Schötz C, Schreyer F, Siala K, Sörgel B, Spahr M, Strefler J, Verpoort P, Weigmann P (2024). _remind2: The REMIND R package (2nd generation)_. R package version 1.134.5, . A BibTeX entry for LaTeX users is @@ -58,7 +58,7 @@ A BibTeX entry for LaTeX users is title = {remind2: The REMIND R package (2nd generation)}, author = {Renato Rodrigues and Lavinia Baumstark and Falk Benke and Jan Philipp Dietrich and Alois Dirnaichner and Jakob Duerrwaechter and Pascal Führlich and Anastasis Giannousakis and Robin Hasse and Jérome Hilaire and David Klein and Johannes Koch and Katarzyna Kowalczyk and Antoine Levesque and Aman Malik and Anne Merfort and Leon Merfort and Simón Morena-Leiva and Michaja Pehl and Robert Pietzcker and Sebastian Rauner and Oliver Richters and Marianna Rottoli and Christof Schötz and Felix Schreyer and Kais Siala and Björn Sörgel and Mike Spahr and Jessica Strefler and Philipp Verpoort and Pascal Weigmann}, year = {2024}, - note = {R package version 1.134.4}, + note = {R package version 1.134.5}, url = {https://github.com/pik-piam/remind2}, } ``` diff --git a/tests/testthat/test-convGDX2mif.R b/tests/testthat/test-convGDX2mif.R index 2766d1ae..8ad677bb 100644 --- a/tests/testthat/test-convGDX2mif.R +++ b/tests/testthat/test-convGDX2mif.R @@ -28,13 +28,15 @@ test_that("Test if REMIND reporting is produced as it should and check data inte } # finds for each AMT scenario the most recent, successfully converged GDX - .findAMTgdx <- function(gdxPaths = NULL) { + .findAMTgdx <- function(gdxPaths = NULL, scenario = NULL) { didremindfinish <- function(fulldatapath) { logpath <- paste0(stringr::str_sub(fulldatapath, 1, -14), "/full.log") return(file.exists(logpath) && any(grep("*** Status: Normal completion", readLines(logpath, warn = FALSE), fixed = TRUE))) } - gdx <- Sys.glob("/p/projects/remind/modeltests/output/*/fulldata.gdx") + gdx <- Sys.glob(paste0("/p/projects/remind/modeltests/remind/output/", scenario, "*/fulldata.gdx")) + datetimepattern <- "_[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}\\.[0-9]{2}\\.[0-9]{2}" + gdx <- gdx[grepl(paste0("^", scenario, datetimepattern, "$"), basename(dirname(gdx)))] stamp <- lapply(gdx, stringr::str_sub, -32, -14) %>% strptime(format = "%Y-%m-%d_%H.%M.%S") %>% as.numeric() @@ -42,7 +44,6 @@ test_that("Test if REMIND reporting is produced as it should and check data inte gdx <- gdx[Sys.time() - gdx$stamp < 30 * 24 * 60 * 60 & !is.na(gdx$stamp), ] gdx <- gdx[unlist(lapply(gdx$gdx, didremindfinish)), ] gdx <- gdx[order(gdx$stamp), ] - datetimepattern <- "_[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}\\.[0-9]{2}\\.[0-9]{2}" gdx$scenario <- sub(datetimepattern, "", basename(dirname(as.vector(gdx$gdx)))) for (scenarioname in unique(gdx$scenario)) { gdxPaths <- c(gdxPaths, as.character(tail(gdx[gdx$scenario == scenarioname, ]$gdx, n = 1))) @@ -50,14 +51,33 @@ test_that("Test if REMIND reporting is produced as it should and check data inte return(gdxPaths) } + checkPiamTemplates <- function(computedVariables) { + templates <- c("AR6", "AR6_NGFS", "NAVIGATE", "SHAPE", "ELEVATE") + for (template in templates) { + templateVariables <- template %>% + piamInterfaces::getREMINDTemplateVariables() %>% + unique() %>% + deletePlus() + expect_true(any(computedVariables %in% templateVariables)) + missingVariables <- setdiff(templateVariables, computedVariables) + if (length(missingVariables) > 0) { + warning("The following variables are expected in the piamInterfaces package ", + "for template ", template, + ", but cannot be found in the reporting generated by ", gdxPath, ":\n ", + paste(missingVariables, collapse = ",\n ")) + } + } + } + # uncomment to add current calibration gdxes # gdxPaths <- c(gdxPaths, Sys.glob("/p/projects/remind/inputdata/CESparametersAndGDX/*.gdx")) # uncomment to add debugging example gdx files # gdxPaths <- c(gdxPaths, Sys.glob("/p/projects/remind/debugging/gdx-examples/*.gdx")) # uncomment to add gdx files from most recent AMT runs - # gdxPaths <- c(gdxPaths, .findAMTgdx()) + gdxPaths <- c(gdxPaths, .findAMTgdx(scenario = "SSP2EU-NPi-AMT")) numberOfMifs <- 0 + for (gdxPath in gdxPaths) { numberOfMifs <- numberOfMifs + 1 @@ -66,6 +86,9 @@ test_that("Test if REMIND reporting is produced as it should and check data inte expect_no_warning(checkVariableNames(getNames(mifContent, dim = 3))) + computedVariables <- deletePlus(getItems(mifContent, dim = 3.3)) + computedVariables <- gsub("\\(\\)", "(unitless)", computedVariables) + checkPiamTemplates(computedVariables) magclass::write.report( x = magclass::collapseNames(mifContent), file = file.path(tempdir(), paste0(numberOfMifs, ".mif")), diff --git a/tests/testthat/test-piamInterfaces-NGFS.R b/tests/testthat/test-piamInterfaces-NGFS.R deleted file mode 100644 index b446cf79..00000000 --- a/tests/testthat/test-piamInterfaces-NGFS.R +++ /dev/null @@ -1,38 +0,0 @@ -library(gdx) - -test_that("Test if REMIND reporting produces mandatory variables for NGFS reporting", { - skip_if_not(as.logical(gdxrrw::igdx(silent = TRUE)), "gdxrrw is not initialized properly") - - # File is from NGFS4, scenario C_d_strain_d95high-rem-17 - gdxPath <- file.path(tempdir(), "fulldata.gdx") - utils::download.file("https://rse.pik-potsdam.de/data/example/remind2_test-NGFS_fulldata.gdx", - gdxPath, - mode = "wb", quiet = TRUE - ) - - mif <- suppressWarnings(convGDX2MIF(gdxPath, gdx_refpolicycost = gdxPath)) - - computedVariables <- deletePlus(getItems(mif, dim = 3.3)) - - computedVariables <- gsub("\\(\\)", "(unitless)", computedVariables) - - templateVariables <- deletePlus(unique( - piamInterfaces::getREMINDTemplateVariables("AR6"), - piamInterfaces::getREMINDTemplateVariables("AR6_NGFS") - )) - - expect_true(any(computedVariables %in% templateVariables)) - - missingVariables <- setdiff(templateVariables, computedVariables) - - if (length(missingVariables) > 0) { - warning( - "The following variables are expected in the piamInterfaces package, - but cannot be found in the reporting generated:\n ", - paste(missingVariables, collapse = ",\n ") - ) - } - # expect_true(length(missingVariables) == 0) - unlink(tempdir(), recursive = TRUE) - tempdir(TRUE) -}) diff --git a/tests/testthat/test-piamInterfaces-SHAPE.R b/tests/testthat/test-piamInterfaces-SHAPE.R deleted file mode 100644 index b11dcb23..00000000 --- a/tests/testthat/test-piamInterfaces-SHAPE.R +++ /dev/null @@ -1,37 +0,0 @@ -library(gdx) - -test_that("Test if REMIND reporting produces mandatory variables for SHAPE reporting", { - skip_if_not(as.logical(gdxrrw::igdx(silent = TRUE)), "gdxrrw is not initialized properly") - - gdxPath <- file.path(tempdir(), "fulldata.gdx") - - utils::download.file("https://rse.pik-potsdam.de/data/example/remind2_test-SHAPE_fulldata.gdx", - gdxPath, - mode = "wb", quiet = TRUE - ) - - mif <- suppressWarnings(convGDX2MIF(gdxPath, gdx_refpolicycost = gdxPath)) - - computedVariables <- deletePlus(getItems(mif, dim = 3.3)) - - computedVariables <- gsub("\\(\\)", "(unitless)", computedVariables) - - templateVariables <- deletePlus(unique( - piamInterfaces::getREMINDTemplateVariables("AR6"), - piamInterfaces::getREMINDTemplateVariables("SHAPE") - )) - - expect_true(any(computedVariables %in% templateVariables)) - - missingVariables <- setdiff(templateVariables, computedVariables) - - if (length(missingVariables) > 0) { - warning( - "The following variables are expected in the piamInterfaces package, - but cannot be found in the reporting generated:\n ", - paste(missingVariables, collapse = ",\n ") - ) - } - unlink(tempdir(), recursive = TRUE) - tempdir(TRUE) -})