From b054fbb8856b152f7e9e4f15e182be76a04561ef Mon Sep 17 00:00:00 2001 From: Ciara Donegan <82416895+ciara-donegan@users.noreply.github.com> Date: Thu, 1 Feb 2024 09:24:23 -0500 Subject: [PATCH] Permafrost status in title of plot Plot title shows whether permafrost is included or not --- h2/components/functions/func_graph_plots.R | 4 ++-- h2/components/modules/mod_run.R | 15 ++++++--------- h2/global.r | 1 + 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/h2/components/functions/func_graph_plots.R b/h2/components/functions/func_graph_plots.R index 9f42daf..90f4855 100644 --- a/h2/components/functions/func_graph_plots.R +++ b/h2/components/functions/func_graph_plots.R @@ -8,7 +8,7 @@ graph_plots <- function(r6) { {ggplot(last(r6$output)) + geom_line(aes(x = year, y = value, color = Scenario)) + labs(x = "Year", y = last(r6$output)$variable[1], - title = paste0("Run Name: ", last(r6$output)$run[1], "\n", "Variable: ", last(r6$output)$variable[1])) + + title = paste0("Run Name: ", last(r6$output)$run[1], "\n", "Variable: ", last(r6$output)$variable[1],"\nPermafrost: ",r6$permafrost)) + theme(legend.position = "bottom")} %>% plotly::ggplotly() @@ -17,7 +17,7 @@ graph_plots <- function(r6) { {ggplot(r6$no_save_output) + geom_line(aes(x = year, y = value, color = Scenario)) + labs(x = "Year", y = r6$no_save_output$variable[1], - title = paste0("Run Name: Unsaved Run\n", "Variable: ", r6$no_save_output$variable[1]))} %>% + title = paste0("Run Name: Unsaved Run\n", "Variable: ", r6$no_save_output$variable[1],"\nPermafrost: ",r6$permafrost))} %>% plotly::ggplotly() %>% layout( legend = list( diff --git a/h2/components/modules/mod_run.R b/h2/components/modules/mod_run.R index 3994f24..5c0ed32 100644 --- a/h2/components/modules/mod_run.R +++ b/h2/components/modules/mod_run.R @@ -12,6 +12,7 @@ run_ui <- function(id) { selected = "input/hector_ssp245.ini"), sliderInput(ns("time"), label="Select dates:", min = 1750, max = 2300, value = c(1900,2100), sep="", width = "90%", step=5), + materialSwitch(ns("permafrost"), "Include Permafrost Carbon", value = FALSE), h5("Model Parameters"), sliderInput(ns("alpha"), label="Aerosol forcing scaling factor", # AERO_SCALE() min = 0.01, max = 1, value = 1, width = "90%"), @@ -24,8 +25,7 @@ run_ui <- function(id) { sliderInput(ns("q10_rh"), label="Heterotrophic temperature sensitivity", # Q10_RH() min = 1, max = 5, value = 2, step=0.1, width = "90%"), sliderInput(ns("volscl"), label="Volcanic forcing scaling factor", # VOLCANIC_SCALE() - min = 0, max = 1, value = 1, width = "90%"), - materialSwitch(ns("permafrost"), "Include Permafrost Carbon", value = FALSE) + min = 0, max = 1, value = 1, width = "90%") ) ) @@ -104,6 +104,9 @@ run_server <- function(id, r6) { # Set parameters using inputs (function to only call setvar once in final version) if (input$permafrost == TRUE) { setvar(core(),0,PERMAFROST_C(),865,"Pg C") + r6$permafrost <- "On" + } else if (input$permafrost == FALSE) { + r6$permafrost <- "Off" } setvar(core(),NA,AERO_SCALE(),input$alpha,"(unitless)") setvar(core(),NA,BETA(),input$beta,"(unitless)") @@ -168,10 +171,4 @@ run_server <- function(id, r6) { }) -} - -# might be worth it to just run the core with all selectable variables. how much time would that add? -# issue seems to be that mod_run goes first, so input$variable just doesn't exist yet... maybe having -# that module containing all choices is a good idea - -# fetchvars(core,1745:2300,vars=list(CONCENTRATIONS_CO2(),FFI_EMISSIONS(),LUC_EMISSIONS(),CONCENTRATIONS_N2O,EMISSIONS_BC(),EMISSIONS_OC(),RF_TOTAL(),RF_ALBEDO(),RF_N2O(),RF_CO2(),RF_BC(),RF_OC(),RF_SO2(),RF_CH4(),RF_VOL())) +} \ No newline at end of file diff --git a/h2/global.r b/h2/global.r index 58fe4b1..b8cb551 100644 --- a/h2/global.r +++ b/h2/global.r @@ -29,6 +29,7 @@ HectorInputs <- R6Class( no_save_output = NULL, no_save = NULL, run_name = NA, + permafrost = NULL, save = NULL, inputs = NULL, selected_var = NULL,