Skip to content

Commit

Permalink
loop through individual plots
Browse files Browse the repository at this point in the history
haven't tested yet

BoulderCodeHub#83
  • Loading branch information
rabutler-usbr committed Nov 28, 2019
1 parent ebf3394 commit 44d309b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 30 deletions.
1 change: 1 addition & 0 deletions code/create_scenario.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ create_scenario <- function(name, scen_folders, ic, start_year,
scen_folders = scen_folders,
ic = ic,
ic_month = ic_month,
start_year = start_year,
std_ind_tables = std_ind_tables,
std_ind_figures = std_ind_figures
)
Expand Down
35 changes: 21 additions & 14 deletions code/create_std_ind_figures.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
create_std_ind_figures <- function(cs, sys_cond, mainScenGroup, yrs2show, ui)
create_std_ind_figures <- function(cs, sys_cond, scenario, ui)
{
critStatsFig1 <- plotCritStats(dplyr::filter(
cs,
AggName == mainScenGroup,
!(Variable %in% c('mead_min_lt_1020','lbSurplus'))
),
yrs2show,
ui$defaults$annText
sy <- ui[["scen_tree"]][[scenario]][["start_year"]]
ey <- ui[["ind_plots"]][["std_ind_figures"]][[scenario]][["end_year"]]
yrs2show <- sy:ey

ann_txt <- ui[["ind_plots"]][["std_ind_figures"]][[scenario]][["ann_text"]]

critStatsFig1 <- plotCritStats(
dplyr::filter(
cs,
AggName == scenario,
!(Variable %in% c('mead_min_lt_1020','lbSurplus'))
),
yrs2show,
ann_txt
)

critStatsFig2 <- plotCritStats(dplyr::filter(
cs,
AggName == mainScenGroup,
AggName == scenario,
!(Variable %in% c('mead_dec_lt_1025','lbSurplus'))
),
yrs2show,
ui$defaults$annText
ann_txt
)

# shortage surplus figure
Expand All @@ -24,10 +31,10 @@ create_std_ind_figures <- function(cs, sys_cond, mainScenGroup, yrs2show, ui)
dplyr::filter(
sys_cond,
Variable %in% c('lbShortage', 'lbSurplus'),
Agg == mainScenGroup
Agg == scenario
),
yrs2show,
names(mainScenGroup)
scenario
)

# stacked barplot of different shortage tiers
Expand All @@ -36,10 +43,10 @@ create_std_ind_figures <- function(cs, sys_cond, mainScenGroup, yrs2show, ui)
dplyr::filter(
sys_cond,
Variable %in% c('lbShortageStep1','lbShortageStep2','lbShortageStep3'),
Agg == mainScenGroup
Agg == scenario
),
yrs2show,
ui$defaults$annText
ann_txt
)

list(
Expand Down
24 changes: 11 additions & 13 deletions code/process_everything.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,22 @@ process_everything <- function(ui)
create_dcp_table(lb_dcp, ub_dcp, mainScenGroup, yrs2show, o_files)
}

# individual scenario figures -----------------
ind_figs <- list()
if (ui$create_figures$std_ind_figures) {
# individual scenario figures -----------------
# For now uses mainScenGroup
message("... creating individual scenario figures")

# now create figures only for the current "main scenario"
for (i in seq_along(ui[["ind_plots"]][["std_ind_figures"]])) {
if (i == 1) message("... creating individual scenario figures")
cur_scen <- names(ui[["ind_plots"]][["std_ind_figures"]])[i]
message(" ...", cur_scen)
# now create figures only for the current scenario
# defaults are ok for legendTitle, legLoc, nC, and annSize
# drop Mead LT 1025 from one plot and Mead LT 1020 from
# the other plot

ind_figs <- create_std_ind_figures(
cs, sys_cond,
mainScenGroup,
yrs2show,
ui
)
create_cs_csv(cs, mainScenGroup, o_files)
tmp <- create_std_ind_figures(cs, sys_cond, cur_scen, ui)
ind_figs <- c(ind_figs, tmp)

# TODO: figure out how to save this file; mostly just need unique name
#create_cs_csv(cs, mainScenGroup, o_files)
}

comp_figs <- list()
Expand Down
8 changes: 5 additions & 3 deletions code/specify_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ specify_ui <- function()
conditional_probs = FALSE,
pe_scatter_fig = FALSE,

pe_clouds = TRUE,
pe_clouds = FALSE,
heatmap = FALSE
)

Expand Down Expand Up @@ -166,7 +166,7 @@ specify_ui <- function()
list(ann_text = 'Results from June 2019 CRSS run', end_year = 2026)
)

ind_plot <- specify_individual_plots(all_scenarios, std_ind_figures, defaults)
ind_plots <- specify_individual_plots(all_scenarios, std_ind_figures, defaults)

# for the 5-year simple table
# value are the scenario group variable names (should be same as above)
Expand Down Expand Up @@ -344,6 +344,8 @@ specify_ui <- function()
plot_group = plot_group,
clouds = clouds,
mead_pe_scatter = mead_pe_scatter,
shortage_conditions = shortage_conditions
shortage_conditions = shortage_conditions,
ind_plots = ind_plots,
scen_tree = all_scenarios
)
}

0 comments on commit 44d309b

Please sign in to comment.