Skip to content

Commit

Permalink
update GCAM6.0 and GCAM7.0 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
klau506 committed Aug 27, 2024
1 parent 7c3a6bf commit 332d3be
Show file tree
Hide file tree
Showing 17 changed files with 15,133 additions and 45 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,21 @@ tests/testthat/testInputs/v_7.1/test7.1_standardized.RData
tests/testthat/testInputs/v_7.1/test7.1_standardized.xlsx
gcamv7.3_test.dat
gcamv7.4_test.dat
tests/testthat/testInputs/v_6.0/database_basexdb_ref_gcamv6.0_test.dat
tests/testthat/testInputs/v_7.0/database_basexdb_ref_gcamv7.0_test.dat
tests/testthat/testInputs/v_7.1/database_basexdb_ref_gcamv7.1.1_test.dat
tests/testthat/testInputs/v_7.1/database_basexdb_ref_gcamv7.1.2_test.dat
tests/testthat/testInputs/v_7.1/database_basexdb_ref_gcamv7.1.3_test.dat
tests/testthat/testInputs/v_7.1/database_basexdb_ref_gcamv7.1.4_test.dat
tests/testthat/testInputs/v_7.1/gcamv7.1.1_test_standardized.csv
tests/testthat/testInputs/v_7.1/gcamv7.1.1_test_standardized.RData
tests/testthat/testInputs/v_7.1/gcamv7.1.1_test_standardized.xlsx
tests/testthat/testInputs/v_7.1/gcamv7.1.2_test_standardized.csv
tests/testthat/testInputs/v_7.1/gcamv7.1.2_test_standardized.RData
tests/testthat/testInputs/v_7.1/gcamv7.1.2_test_standardized.xlsx
tests/testthat/testInputs/v_7.1/gcamv7.1.3_test_standardized.csv
tests/testthat/testInputs/v_7.1/gcamv7.1.3_test_standardized.RData
tests/testthat/testInputs/v_7.1/gcamv7.1.3_test_standardized.xlsx
tests/testthat/testInputs/v_7.1/gcamv7.1.4_test_standardized.csv
tests/testthat/testInputs/v_7.1/gcamv7.1.4_test_standardized.RData
tests/testthat/testInputs/v_7.1/gcamv7.1.4_test_standardized.xlsx
11 changes: 5 additions & 6 deletions R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -1594,8 +1594,7 @@ get_co2_price_global_tmp <- function(GCAM_version = "v7.0") {

#' Get CO2 Price Share
#'
#' Retrieves the CO2 price distribution between CO2 and CO2_ETS. If only one CO2 type is present, the share is set to 1.
#' If both types are present, the share is determined based on the last historical year for each type.
#' Retrieves the CO2 price share of each region or sector compared to the total CO2 price.
#'
#' @param GCAM_version Main GCAM compatible version: 'v7.0' (default), 'v7.1', or 'v6.0'.
#' @keywords internal co2 tmp
Expand All @@ -1621,7 +1620,7 @@ get_co2_price_share <- function(GCAM_version = "v7.0") {

co2_price_share_bysec <<- co2_clean %>%
dplyr::filter(year == get(paste('last_historical_year',GCAM_version,sep='_'), envir = asNamespace("gcamreport"))) %>%
# dplyr::select only reported sectors and do a right join, so that all sectors are present,
# select only reported sectors and do a right join, so that all sectors are present,
# even if the value is NA
dplyr::right_join(expand.grid(
var = c(
Expand Down Expand Up @@ -1675,7 +1674,7 @@ get_co2_price_fragmented_tmp <- function(GCAM_version = "v7.0") {

co2_price_fragmented <<-
co2_price_fragmented_pre %>%
dplyr::left_join(CO2_market_filteredReg, by = c("market"), multiple = "all") %>%
left_join_strict(CO2_market_filteredReg, by = c("market"), multiple = "all") %>%
dplyr::filter(stats::complete.cases(.)) %>%
dplyr::mutate(value = value /
get(paste('convert',GCAM_version,sep='_'), envir = asNamespace("gcamreport"))[['conv_C_CO2']] *
Expand Down Expand Up @@ -1733,7 +1732,7 @@ get_co2_price <- function(GCAM_version = "v7.0") {

# compute Global value using the emission weights
co2_price_world <- co2_price_regional %>%
dplyr::left_join(co2_price_share_bysec %>%
left_join_strict(co2_price_share_bysec %>%
dplyr::left_join(filter_variables(get(paste('co2_market_frag_map',GCAM_version,sep='_'), envir = asNamespace("gcamreport")), "co2_price_fragmented"),
by = "sector", multiple = "all") %>%
dplyr::select(-sector,-market,-year),
Expand Down Expand Up @@ -1879,7 +1878,7 @@ get_energy_price_fragmented <- function(GCAM_version = "v7.0") {
warning('ATTENTION: At least one scenario does not contain CO2 price')
}
if (!dplyr::all_of(unique(tmp1$market) %in% c(unique(CO2_market_filteredReg$market),NA))) {
missing_markets <- setdiff(unique(CO2_market_filteredReg$market), unique(CO2_market_filteredReg$market))
missing_markets <- setdiff(unique(tmp1$market), unique(CO2_market_filteredReg$market))
warning(sprintf('ATTENTION: The CO2 markets %s are not present in the `co2_market_new` mapping file.',
paste(missing_markets, collapse = ", ")))

Expand Down
Binary file modified data/final_energy_map_v6.0.rda
Binary file not shown.
Binary file modified data/final_energy_map_v7.0.rda
Binary file not shown.
Binary file modified data/final_energy_map_v7.1.rda
Binary file not shown.
25 changes: 25 additions & 0 deletions man/co2_market_v6.0.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions man/co2_market_v7.0.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/get_co2_price_share.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified tests/testthat/testInputs/v_6.0/test6.dat
Binary file not shown.
Loading

0 comments on commit 332d3be

Please sign in to comment.