-
Notifications
You must be signed in to change notification settings - Fork 129
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 #1362 from fbenke-pik/modeltest
Set up test structure for data validation
- Loading branch information
Showing
5 changed files
with
131 additions
and
0 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
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,20 @@ | ||
# | (C) 2006-2023 Potsdam Institute for Climate Impact Research (PIK) | ||
# | authors, and contributors see CITATION.cff file. This file is part | ||
# | of REMIND and licensed under AGPL-3.0-or-later. Under Section 7 of | ||
# | AGPL-3.0, you are granted additional permissions described in the | ||
# | REMIND License Exception, version 1.0 (see LICENSE file). | ||
# | Contact: [email protected] | ||
test_that("each output folder contains standard mif files", { | ||
dirs <- list.dirs("../../../output", recursive = FALSE, full.names = FALSE) | ||
for (dir in dirs) { | ||
d <- paste0("../../../output/", dir) | ||
r <- expect_true( | ||
length(list.files(path = d, pattern = "REMIND_generic_.*.mif")) == 2 && | ||
length(list.files(path = d, pattern = "REMIND_climate_.*.mif")) == 1 | ||
) | ||
|
||
if (!r) { | ||
print(paste0("some mifs are missing in ", dir)) | ||
} | ||
} | ||
}) |
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,37 @@ | ||
# | (C) 2006-2023 Potsdam Institute for Climate Impact Research (PIK) | ||
# | authors, and contributors see CITATION.cff file. This file is part | ||
# | of REMIND and licensed under AGPL-3.0-or-later. Under Section 7 of | ||
# | AGPL-3.0, you are granted additional permissions described in the | ||
# | REMIND License Exception, version 1.0 (see LICENSE file). | ||
# | Contact: [email protected] | ||
# Source: https://github.com/remindmodel/development_issues/issues/168 | ||
library(magclass) | ||
library(quitte) | ||
library(dplyr) | ||
test_that("liquids demand in buildings in NPi and NDC is not higher than baseline", { | ||
dirs <- list.dirs("../../../output", recursive = FALSE) | ||
data <- NULL | ||
for (d in dirs) { | ||
mifs <- list.files(path = d, pattern = "REMIND_generic_.*_withoutPlus.mif", full.names = TRUE) | ||
if (length(mifs) == 1) { | ||
m <- suppressWarnings(read.report(mifs[1], as.list = FALSE)["GLO", , "FE|Buildings|Liquids (EJ/yr)"]) | ||
data <- mbind(data, m) | ||
} | ||
} | ||
|
||
if (all(c("SSP2EU-Base", "SSP2EU-NPi", "SSP2EU-NDC") %in% getNames(data, dim = 1))) { | ||
xBase <- as.quitte(data[, , "SSP2EU-Base"]) | ||
x <- as.quitte(data[, , c("SSP2EU-NPi", "SSP2EU-NDC")]) | ||
# data frame with all data points where Base value is greater than NPi/NDC value, | ||
# excluding historical values | ||
x <- left_join(x, xBase, by = c("model", "region", "variable", "unit", "period")) %>% | ||
filter(value.x > value.y, period > 2025) | ||
} | ||
|
||
r <- expect_true(nrow(x) == 0) | ||
|
||
if (!r) { | ||
print("Examples of test violation:") | ||
print(head(x)) | ||
} | ||
}) |
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,32 @@ | ||
# | (C) 2006-2023 Potsdam Institute for Climate Impact Research (PIK) | ||
# | authors, and contributors see CITATION.cff file. This file is part | ||
# | of REMIND and licensed under AGPL-3.0-or-later. Under Section 7 of | ||
# | AGPL-3.0, you are granted additional permissions described in the | ||
# | REMIND License Exception, version 1.0 (see LICENSE file). | ||
# | Contact: [email protected] | ||
# Source: https://github.com/remindmodel/development_issues/issues/91 | ||
library(magclass) | ||
test_that("there are no negative electricity prices in historic years in EU regions", { | ||
dirs <- list.dirs("../../../output", recursive = FALSE) | ||
data <- NULL | ||
reg <- c("EU27", "DEU", "ECE", "ECS", "ENC", "ESC", "ESW", "EWN", "FRA") | ||
for (d in dirs) { | ||
mifs <- list.files(path = d, pattern = "REMIND_generic_.*_withoutPlus.mif", full.names = TRUE) | ||
if (length(mifs) == 1) { | ||
m <- suppressWarnings( | ||
read.report(mifs[1], as.list = FALSE)[ | ||
, , | ||
c( | ||
"Price|Secondary Energy|Electricity (US$2005/GJ)", | ||
"Price|Final Energy|Industry|Electricity (US$2005/GJ)" | ||
) | ||
] | ||
) | ||
if (all(reg %in% getRegions(m))) { | ||
data <- mbind(data, m[reg, seq(2005, 2025, 5), ]) | ||
} | ||
} | ||
} | ||
|
||
expect_true(length(data[data < 0 & !is.na(data)]) == 0) | ||
}) |
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,39 @@ | ||
# | (C) 2006-2023 Potsdam Institute for Climate Impact Research (PIK) | ||
# | authors, and contributors see CITATION.cff file. This file is part | ||
# | of REMIND and licensed under AGPL-3.0-or-later. Under Section 7 of | ||
# | AGPL-3.0, you are granted additional permissions described in the | ||
# | REMIND License Exception, version 1.0 (see LICENSE file). | ||
# | Contact: [email protected] | ||
library(magclass) | ||
library(quitte) | ||
library(dplyr) | ||
test_that("Non-ESM Investments never drop more than 50% in comparison to previous timestep until 2100", { | ||
dirs <- list.dirs("../../../output", recursive = FALSE) | ||
data <- NULL | ||
reg <- c( | ||
"CAZ", "CHA", "EUR", "IND", "JPN", "LAM", "MEA", | ||
"NEU", "OAS", "REF", "SSA", "USA", "GLO" | ||
) | ||
for (d in dirs) { | ||
mifs <- list.files(path = d, pattern = "REMIND_generic_.*_withoutPlus.mif", full.names = TRUE) | ||
if (length(mifs) == 1) { | ||
m <- suppressWarnings( | ||
read.report(mifs[1], as.list = FALSE) | ||
)[reg, , "Investments|Non-ESM (billion US$2005/yr)"] | ||
data <- mbind(data, m) | ||
} | ||
} | ||
data <- data[, getYears(data, as.integer = TRUE) <= 2100, ] | ||
x <- as.quitte(data) | ||
xPrev <- mutate(x, period_next := period + 5) | ||
xDiff <- inner_join(x, xPrev, by = c("period" = "period_next", "model", "scenario", "region", "variable", "unit")) %>% | ||
mutate(value := (value.x - value.y) / value.x) %>% | ||
filter(value < -0.5) | ||
|
||
r <- expect_true(nrow(xDiff) == 0) | ||
|
||
if (!r) { | ||
print("Examples of test violation:") | ||
print(head(xDiff)) | ||
} | ||
}) |