Skip to content

Commit

Permalink
Merge branch 'redesign' into sp-savetoggle
Browse files Browse the repository at this point in the history
  • Loading branch information
stephpenn1 authored Dec 18, 2023
2 parents 1e8a483 + bc7f3f7 commit d83ee88
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 35 deletions.
109 changes: 74 additions & 35 deletions h2/components/modules/mod_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,55 @@

graph_ui <- function(id) {
ns <- NS(id)
# fluidRow(
# selectInput(ns("variable"), "Select a variable to plot:",
# list("Carbon Cycle" = list("Atmospheric CO2" = CONCENTRATIONS_CO2(),
# "FFI Emissions" = FFI_EMISSIONS(),
# "LUC Emissions" = LUC_EMISSIONS()),
# "Concentrations" = list("N2O Concentration" = CONCENTRATIONS_N2O()),
# "Emissions" = list("Black Carbon Emissions" = EMISSIONS_BC(),
# "Organic Carbon Emissions" = EMISSIONS_OC()),
# "Forcings" = list("RF - Total" = RF_TOTAL(),
# "RF - Albedo" = RF_ALBEDO(),
# "RF - CO2" = RF_CO2(),
# "RF - N2O" = RF_N2O(),
# "RF - Black Carbon" = RF_BC(),
# "RF - Organic Carbon" = RF_OC(),
# "RF - Total SO2" = RF_SO2(),
# "RF - Volcanic Activity" = RF_VOL(),
# "RF - CH4" = RF_CH4())),
# selected = "Atmospheric CO2"),
# selectInput(ns("variable"), "Select a variable to plot:",
# c("Global Mean Temperature" = "global_tas",
# "Atmospheric CO2" = "CO2_concentration",
# "RF - Total" = "RF_tot",
# "RF - CO2" = "RF_CO2",
# "Atmospheric N2O" = CONCENTRATIONS_N2O()),
# selected = "global_tas"),

fluidRow(selectInput(ns("variable"), "Select a variable to plot:",
list("Carbon Cycle" = list("Atmospheric CO2" = CONCENTRATIONS_CO2(),
"Atmospheric Carbon Pool" = ATMOSPHERIC_CO2(), # i think this is the right var?
"FFI Emissions" = FFI_EMISSIONS(),
"LUC Emissions" = LUC_EMISSIONS()),
"Concentrations" = list("N2O Concentration" = CONCENTRATIONS_N2O()),
"Emissions" = list("Black Carbon Emissions" = EMISSIONS_BC(),
"Organic Carbon Emissions" = EMISSIONS_OC()),
"Forcings" = list("RF - Total" = RF_TOTAL(),
"RF - Albedo" = RF_ALBEDO(),
"RF - CO2" = RF_CO2(),
"RF - N2O" = RF_N2O(),
"RF - Black Carbon" = RF_BC(),
"RF - Organic Carbon" = RF_OC(),
"RF - Total SO2" = RF_SO2(),
"RF - Volcanic Activity" = RF_VOL(),
"RF - CH4" = RF_CH4()),
"Halocarbon Forcings" = list("CF4 Forcing"="RF_CF4", #function doesn't give the correct output?
"C2F6 Forcing"="RF_C2F6",
"HFC-23 Forcing"="RF_HFC23",
"HFC-4310 Forcing"="RF_HFC4310",
"HFC-125 Forcing"="RF_HFC125",
"HFC-143a Forcing"="RF_HFC143a",
"HFC-245fa Forcing"="RF_HFC245fa",
"SF6 Forcing"="RF_SF6",
"CFC-11 Forcing"="RF_CFC11",
"CFC-12 Forcing"="RF_CFC12",
"CFC-113 Forcing"="RF_CFC113",
"CFC-114 Forcing"="RF_CFC114",
"CFC-115 Forcing"="RF_CFC115",
"CCl4 Forcing"="RF_CCl4",
"CH3CCl3 Forcing"="RF_CH3CCl3",
"Halon-1211 Forcing"="RF_halon1211",
"Halon-1301 Forcing"="RF_halon1301",
"Halon-2402 Forcing"="RF_halon2402",
"CH3Cl Forcing"="RF_CH3Cl",
"CH3Br Forcing"="RF_CH3Br"),
"Methane" = list("Atmospheric CH4" = CONCENTRATIONS_CH4(),
"CH4 Emissions" = EMISSIONS_CH4()),
"SO2" = list("Anthropogenic SO2"=EMISSIONS_SO2(),
"Volcanic SO2"=VOLCANIC_SO2()),
"Temperature" = list("Global Mean Temp" = GLOBAL_TAS(),
"Equilibrium Global Temp" = GMST(), # i think?
"Ocean Surface Temp" = SST(),
"Ocean Air Temp" = OCEAN_TAS(),
"Heat Flux - Mixed Layer Ocean" = FLUX_MIXED(),
"Heat Flux - Interior Layer Ocean" = FLUX_INTERIOR(),
"Total Heat Flux - Ocean" = HEAT_FLUX()))),
# other variables can be found from the fetchvars help page
column(3,
actionButton(ns("plot"), "Plot"),
Expand All @@ -43,6 +67,13 @@ graph_server <- function(id, r6) {
observe({

if (r6$save == TRUE) {

# Get labels given input
key <- reactive({input$variable})
title <- title[[key()]]
ylabel <- units[[key()]]

# Filter data for selected variable
filtered_output <-
filter(r6$output[[r6$run_name()]], variable == r6$selected_var())

Expand All @@ -61,18 +92,24 @@ graph_server <- function(id, r6) {
) %>%
layout(
xaxis = list(title = "Year"),
yaxis = list(title = "Global Temperature (C)"),
title = "Global Temperature at Surface"
yaxis = list(title = ylabel),
title = title
)
})
}

if (r6$save == FALSE) {
browser()
# r6$selected_var <- reactive({input$variable})
#
# filtered_output <-
# filter(r6$output, variable == r6$selected_var())
#browser()
r6$selected_var <- reactive({input$variable})

# Get labels given input
key <- reactive({input$variable})
title <- title[[key()]]
ylabel <- units[[key()]]

# Filter data for selected variable
filtered_output <-
filter(r6$no_save, variable == r6$selected_var())

output$graph <- renderPlotly({
plot_ly(
r6$output,
Expand All @@ -88,12 +125,14 @@ graph_server <- function(id, r6) {
) %>%
layout(
xaxis = list(title = "Year"),
#yaxis = list(title = r6$selected_var()),
title = input$variable
yaxis = list(title = ylabel),
title = title
)
})
}
}) %>%
bindEvent(input$run, ignoreNULL = TRUE, ignoreInit = TRUE)
})
}

# add reset variables button
98 changes: 98 additions & 0 deletions h2/global.r
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,101 @@ HectorInputs <- R6Class(
}
)
)

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"
)

0 comments on commit d83ee88

Please sign in to comment.