diff --git a/NAMESPACE b/NAMESPACE index 6ae9268..96b30c2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,2 +1,5 @@ # Generated by roxygen2: do not edit by hand +export(get_scenarios) +export(get_titles) +export(get_units) diff --git a/R/set_globals.R b/R/set_globals.R new file mode 100644 index 0000000..38bcefc --- /dev/null +++ b/R/set_globals.R @@ -0,0 +1,128 @@ + +#' Global scenario list with Hector input file +#' @export +get_scenarios <- function() { + + 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") + + return(scenarios) +} + +#' Global list of variable titles +#' @export +get_titles <- function() { + + 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") + + return(title) +} + +#' Global list of variable units +#' @export +get_units <- function() { + + 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") + + return(units) +} + + diff --git a/inst/shinyApp/global.r b/inst/shinyApp/global.r index 937f2a9..349d54b 100644 --- a/inst/shinyApp/global.r +++ b/inst/shinyApp/global.r @@ -22,6 +22,10 @@ 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) +scenarios <- get_scenarios() +units <- get_units() +title <- get_titles() + theme_set(theme_minimal()) # Define R6 class @@ -47,111 +51,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/man/get_scenarios.Rd b/man/get_scenarios.Rd new file mode 100644 index 0000000..37f6460 --- /dev/null +++ b/man/get_scenarios.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/set_globals.R +\name{get_scenarios} +\alias{get_scenarios} +\title{Global scenario list with Hector input file} +\usage{ +get_scenarios() +} +\description{ +Global scenario list with Hector input file +} diff --git a/man/get_titles.Rd b/man/get_titles.Rd new file mode 100644 index 0000000..2bade1b --- /dev/null +++ b/man/get_titles.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/set_globals.R +\name{get_titles} +\alias{get_titles} +\title{Global list of variable titles} +\usage{ +get_titles() +} +\description{ +Global list of variable titles +} diff --git a/man/get_units.Rd b/man/get_units.Rd new file mode 100644 index 0000000..cf9c15f --- /dev/null +++ b/man/get_units.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/set_globals.R +\name{get_units} +\alias{get_units} +\title{Global list of variable units} +\usage{ +get_units() +} +\description{ +Global list of variable units +} diff --git a/tests/testthat/test-globals.R b/tests/testthat/test-globals.R index eec4224..119860f 100644 --- a/tests/testthat/test-globals.R +++ b/tests/testthat/test-globals.R @@ -1 +1,125 @@ library(hector) + +test_that("globals: scenarios", { + + scenarios <- get_scenarios() + + 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", + "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")) + +}) + + +test_that("globals: titles", { + + title <- get_titles() + + expect_equal(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")) + +}) + +test_that("globals: units", { + + units <- get_units() + + expect_equal(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")) + +})