From f9742b5bfc265780a8447c91e56896eb3247f1e5 Mon Sep 17 00:00:00 2001 From: Stephanie Pennington Date: Mon, 3 Jun 2024 16:58:25 -0400 Subject: [PATCH] Move global lists to separate script for tests --- .../shinyApp/components/layout/global-lists.r | 107 +++++++++++++++++ inst/shinyApp/global.r | 109 +----------------- tests/testthat/test-globals.R | 8 +- 3 files changed, 112 insertions(+), 112 deletions(-) create mode 100644 inst/shinyApp/components/layout/global-lists.r diff --git a/inst/shinyApp/components/layout/global-lists.r b/inst/shinyApp/components/layout/global-lists.r new file mode 100644 index 0000000..4942e87 --- /dev/null +++ b/inst/shinyApp/components/layout/global-lists.r @@ -0,0 +1,107 @@ + +scenarios <- list("SSP 1-1.9"="input/hector_ssp119.ini", + "SSP 1-2.6"="input/hector_ssp126.ini", + "SSP 2-4.5"="input/hector_ssp245.ini", + "SSP 3-7.0"="input/hector_ssp370.ini", + "SSP 4-3.4"="input/hector_ssp434.ini", + "SSP 4-6.0"="input/hector_ssp460.ini", + "SSP 5-3.4OS"="input/hector_ssp534-over.ini", + "SSP 5-8.5"="input/hector_ssp585.ini") + +title <- list("CO2_concentration" = "Atmospheric CO2", + "atmos_co2" = "Atmospheric Carbon Pool", + "ffi_emissions" = "FFI Emissions", + "luc_emissions" = "LUC Emissions", + "N2O_concentration" = "N2O Concentration", + "BC_emissions" = "Black Carbon Emissions", + "OC_emissions" = "Organic Carbon Emissions", + "RF_tot" = "RF - Total", + "RF_albedo" = "RF - Albedo", + "RF_CO2" = "RF - CO2", + "RF_N2O" = "RF - N2O", + "RF_BC" = "RF - Black Carbon", + "RF_OC" = "RF - Organic Carbon", + "RF_SO2" = "RF - Total SO2", + "RF_VOL" = "RF - Volcanic Activity", + "RF_CH4" = "RF - CH4", + "RF_CF4" = "CF4 Forcing", + "RF_C2F6" = "C2F6 Forcing", + "RF_HFC23" = "HFC-23 Forcing", + "RF_HFC4310" = "HFC-4310 Forcing", + "RF_HFC125" = "HFC-125 Forcing", + "RF_HFC143a" = "HFC-143a Forcing", + "RF_HFC245fa" = "HFC-245fa Forcing", + "RF_SF6" = "SF6 Forcing", + "RF_CFC11" = "CFC-11 Forcing", + "RF_CFC12" = "CFC-12 Forcing", + "RF_CFC113" = "CFC-113 Forcing", + "RF_CFC114" = "CFC-114 Forcing", + "RF_CFC115" = "CFC-115 Forcing", + "RF_CCl4" = "CCl4 Forcing", + "RF_CH3CCl3" = "CH3CCl3 Forcing", + "RF_halon1211" = "Halon-1211 Forcing", + "RF_halon1301" = "Halon-1301 Forcing", + "RF_halon2402" = "Halon-2402 Forcing", + "RF_CH3Cl" = "CH3Cl Forcing", + "RF_CH3Br" = "CH3Br Forcing", + "CH4_concentration" = "Atmospheric CH4", + "CH4_emissions" = "CH4 Emissions", + "SO2_emissions" = "Anthropogenic SO2", + "SV" = "Volcanic SO2", + "global_tas" = "Global Mean Temperature", + "gmst" = "Equilibrium Global Temperature", + "sst" = "Ocean Surface Temperature", + "ocean_tas" = "Ocean Air Temperature", + "heatflux_mixed" = "Heat Flux - Mixed Layer Ocean", + "heatflux_interior" = "Heat Flux - Interior Layer Ocean", + "heatflux" = "Total Heat Flux - Ocean" +) + +units <- list("CO2_concentration" = "DegC", + "atmos_co2" = "Pg C", + "ffi_emissions" = "Pg C/yr", + "luc_emissions" = "Pg C/yr", + "N2O_concentration" = "ppbv N2O", + "BC_emissions" = "Tg", + "OC_emissions" = "Tg", + "RF_tot" = "RF - Total", + "RF_albedo" = "W/m2", + "RF_CO2" = "W/m2", + "RF_N2O" = "W/m2", + "RF_BC" = "W/m2", + "RF_OC" = "W/m2", + "RF_SO2" = "W/m2", + "RF_VOL" = "W/m2", + "RF_CH4" = "W/m2", + "RF_CF4" = "W/m2", + "RF_C2F6" = "W/m2", + "RF_HFC23" = "W/m2", + "RF_HFC4310" = "W/m2", + "RF_HFC125" = "W/m2", + "RF_HFC143a" = "W/m2", + "RF_HFC245fa" = "W/m2", + "RF_SF6" = "W/m2", + "RF_CFC11" = "W/m2", + "RF_CFC12" = "W/m2", + "RF_CFC113" = "W/m2", + "RF_CFC114" = "W/m2", + "RF_CFC115" = "W/m2", + "RF_CCl4" = "W/m2", + "RF_CH3CCl3" = "W/m2", + "RF_halon1211" = "W/m2", + "RF_halon1301" = "W/m2", + "RF_halon2402" = "W/m2", + "RF_CH3Cl" = "W/m2", + "RF_CH3Br" = "W/m2", + "CH4_concentration" = "ppbv CH4", + "CH4_emissions" = "Tg CH4", + "SO2_emissions" = "Gg SO2", + "SV" = "W/m2", + "global_tas" = "DegC", + "gmst" = "DegC", + "sst" = "DegC", + "ocean_tas" = "DegC", + "heatflux_mixed" = "W/m2", + "heatflux_interior" = "W/m2", + "heatflux" = "W/m2" +) diff --git a/inst/shinyApp/global.r b/inst/shinyApp/global.r index 937f2a9..cde1fd2 100644 --- a/inst/shinyApp/global.r +++ b/inst/shinyApp/global.r @@ -21,6 +21,7 @@ source("components/modules/mod_download.R", local = TRUE) source("components/modules/mod_tracking.R", local = TRUE) source("components/functions/func_graph_plots.R", local = TRUE) source("components/functions/func_custom_emissions.R", local = TRUE) +source("components/layout/global-lists.r", local = TRUE) theme_set(theme_minimal()) @@ -47,111 +48,3 @@ HectorInputs <- R6Class( # } ) ) - -scenarios <- list("SSP 1-1.9"="input/hector_ssp119.ini", - "SSP 1-2.6"="input/hector_ssp126.ini", - "SSP 2-4.5"="input/hector_ssp245.ini", - "SSP 3-7.0"="input/hector_ssp370.ini", - "SSP 4-3.4"="input/hector_ssp434.ini", - "SSP 4-6.0"="input/hector_ssp460.ini", - "SSP 5-3.4OS"="input/hector_ssp534-over.ini", - "SSP 5-8.5"="input/hector_ssp585.ini") - -title <- list("CO2_concentration" = "Atmospheric CO2", - "atmos_co2" = "Atmospheric Carbon Pool", - "ffi_emissions" = "FFI Emissions", - "luc_emissions" = "LUC Emissions", - "N2O_concentration" = "N2O Concentration", - "BC_emissions" = "Black Carbon Emissions", - "OC_emissions" = "Organic Carbon Emissions", - "RF_tot" = "RF - Total", - "RF_albedo" = "RF - Albedo", - "RF_CO2" = "RF - CO2", - "RF_N2O" = "RF - N2O", - "RF_BC" = "RF - Black Carbon", - "RF_OC" = "RF - Organic Carbon", - "RF_SO2" = "RF - Total SO2", - "RF_VOL" = "RF - Volcanic Activity", - "RF_CH4" = "RF - CH4", - "RF_CF4" = "CF4 Forcing", - "RF_C2F6" = "C2F6 Forcing", - "RF_HFC23" = "HFC-23 Forcing", - "RF_HFC4310" = "HFC-4310 Forcing", - "RF_HFC125" = "HFC-125 Forcing", - "RF_HFC143a" = "HFC-143a Forcing", - "RF_HFC245fa" = "HFC-245fa Forcing", - "RF_SF6" = "SF6 Forcing", - "RF_CFC11" = "CFC-11 Forcing", - "RF_CFC12" = "CFC-12 Forcing", - "RF_CFC113" = "CFC-113 Forcing", - "RF_CFC114" = "CFC-114 Forcing", - "RF_CFC115" = "CFC-115 Forcing", - "RF_CCl4" = "CCl4 Forcing", - "RF_CH3CCl3" = "CH3CCl3 Forcing", - "RF_halon1211" = "Halon-1211 Forcing", - "RF_halon1301" = "Halon-1301 Forcing", - "RF_halon2402" = "Halon-2402 Forcing", - "RF_CH3Cl" = "CH3Cl Forcing", - "RF_CH3Br" = "CH3Br Forcing", - "CH4_concentration" = "Atmospheric CH4", - "CH4_emissions" = "CH4 Emissions", - "SO2_emissions" = "Anthropogenic SO2", - "SV" = "Volcanic SO2", - "global_tas" = "Global Mean Temperature", - "gmst" = "Equilibrium Global Temperature", - "sst" = "Ocean Surface Temperature", - "ocean_tas" = "Ocean Air Temperature", - "heatflux_mixed" = "Heat Flux - Mixed Layer Ocean", - "heatflux_interior" = "Heat Flux - Interior Layer Ocean", - "heatflux" = "Total Heat Flux - Ocean" -) - -units <- list("CO2_concentration" = "DegC", - "atmos_co2" = "Pg C", - "ffi_emissions" = "Pg C/yr", - "luc_emissions" = "Pg C/yr", - "N2O_concentration" = "ppbv N2O", - "BC_emissions" = "Tg", - "OC_emissions" = "Tg", - "RF_tot" = "RF - Total", - "RF_albedo" = "W/m2", - "RF_CO2" = "W/m2", - "RF_N2O" = "W/m2", - "RF_BC" = "W/m2", - "RF_OC" = "W/m2", - "RF_SO2" = "W/m2", - "RF_VOL" = "W/m2", - "RF_CH4" = "W/m2", - "RF_CF4" = "W/m2", - "RF_C2F6" = "W/m2", - "RF_HFC23" = "W/m2", - "RF_HFC4310" = "W/m2", - "RF_HFC125" = "W/m2", - "RF_HFC143a" = "W/m2", - "RF_HFC245fa" = "W/m2", - "RF_SF6" = "W/m2", - "RF_CFC11" = "W/m2", - "RF_CFC12" = "W/m2", - "RF_CFC113" = "W/m2", - "RF_CFC114" = "W/m2", - "RF_CFC115" = "W/m2", - "RF_CCl4" = "W/m2", - "RF_CH3CCl3" = "W/m2", - "RF_halon1211" = "W/m2", - "RF_halon1301" = "W/m2", - "RF_halon2402" = "W/m2", - "RF_CH3Cl" = "W/m2", - "RF_CH3Br" = "W/m2", - "CH4_concentration" = "ppbv CH4", - "CH4_emissions" = "Tg CH4", - "SO2_emissions" = "Gg SO2", - "SV" = "W/m2", - "global_tas" = "DegC", - "gmst" = "DegC", - "sst" = "DegC", - "ocean_tas" = "DegC", - "heatflux_mixed" = "W/m2", - "heatflux_interior" = "W/m2", - "heatflux" = "W/m2" -) - diff --git a/tests/testthat/test-globals.R b/tests/testthat/test-globals.R index 8b84b4d..b2c3c5a 100644 --- a/tests/testthat/test-globals.R +++ b/tests/testthat/test-globals.R @@ -1,10 +1,11 @@ library(hector) +source("../../inst/shinyApp/components/layout/global-lists.r", local = TRUE) context("globals") test_that("globals: scenarios", { - expect_equal(scenarios, c("SSP 1-1.9"="input/hector_ssp119.ini", + expect_equal(scenarios, list("SSP 1-1.9"="input/hector_ssp119.ini", "SSP 1-2.6"="input/hector_ssp126.ini", "SSP 2-4.5"="input/hector_ssp245.ini", "SSP 3-7.0"="input/hector_ssp370.ini", @@ -18,7 +19,7 @@ test_that("globals: scenarios", { test_that("globals: titles", { - expect_equal(title, c("CO2_concentration" = "Atmospheric CO2", + expect_equal(title, list("CO2_concentration" = "Atmospheric CO2", "atmos_co2" = "Atmospheric Carbon Pool", "ffi_emissions" = "FFI Emissions", "luc_emissions" = "LUC Emissions", @@ -71,8 +72,7 @@ test_that("globals: titles", { test_that("globals: units", { - - expect_equal(units, c("CO2_concentration" = "DegC", + expect_equal(units, list("CO2_concentration" = "DegC", "atmos_co2" = "Pg C", "ffi_emissions" = "Pg C/yr", "luc_emissions" = "Pg C/yr",