Skip to content

Commit

Permalink
Merge pull request #66 from JGCRI/permafrost
Browse files Browse the repository at this point in the history
Adds permafrost toggle with Hector Run
  • Loading branch information
stephpenn1 authored Feb 7, 2024
2 parents 121c6f7 + b054fbb commit 53bb9c2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions h2/components/functions/func_graph_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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(
Expand Down
15 changes: 8 additions & 7 deletions h2/components/modules/mod_run.R
Original file line number Diff line number Diff line change
Expand Up @@ -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%"),
Expand Down Expand Up @@ -101,6 +102,12 @@ run_server <- function(id, r6) {
core <- reactive({newcore(r6$ini_file())}) # create core

# 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)")
setvar(core(),NA,DIFFUSIVITY(),input$diff,"cm2/s")
Expand Down Expand Up @@ -164,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()))
}
1 change: 1 addition & 0 deletions h2/global.r
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 53bb9c2

Please sign in to comment.