From 7c3e7d4357a7bdb748fc18ded47867002141a3e1 Mon Sep 17 00:00:00 2001 From: Karen Noiva Date: Fri, 24 May 2024 13:49:10 -0400 Subject: [PATCH] Edited workflow Edited workflow to better use github resources --- .github/workflows/test_fredi.yml | 22 +- FrEDI/scripts/create_DoW_results.R | 478 +++++++++++++++-------------- 2 files changed, 262 insertions(+), 238 deletions(-) diff --git a/.github/workflows/test_fredi.yml b/.github/workflows/test_fredi.yml index 2ce66829..a411d070 100644 --- a/.github/workflows/test_fredi.yml +++ b/.github/workflows/test_fredi.yml @@ -26,9 +26,16 @@ on: options: - no - yes - make_figures: + make_appx_figs: type: choice - description: Create report figures? + description: Create appendix figures for report? + required: true + options: + - no + - yes + make_tots_figs: + type: choice + description: Make figures for impact type totals? required: true options: - no @@ -47,7 +54,7 @@ jobs: - name: Send input status run: | - echo "${{ inputs.run_tests }} ${{ inputs.figH_results }} ${{ inputs.make_figures }}" + echo "${{ inputs.run_tests }} ${{ inputs.figH_results }} ${{ inputs.make_appx_figs }} ${{ inputs.make_tots_figs }}" - name: Setup R uses: r-lib/actions/setup-r@v2 @@ -97,9 +104,11 @@ jobs: sPath0 |> file.path("create_DoW_results.R") |> source() ### Which tests to do - do_tests <- "${{ inputs.run_tests }}" == "true" - do_figH <- "${{ inputs.figH_results }}" == "true" - do_figs <- "${{ inputs.make_figures }}" == "true" + do_tests <- "${{ inputs.run_tests }}" == "true" + do_figH <- "${{ inputs.figH_results }}" == "true" + do_appx <- "${{ inputs.make_appx_figs }}" == "true" + do_tots <- "${{ inputs.make_tots_figs }}" == "true" + do_figs <- do_appx | do_tots ### Where to save results oPath0 <- pPath0 |> file.path("data_tests") @@ -158,6 +167,7 @@ jobs: outPath = oPath2, saveFile = TRUE, loadCode = "project", + totals = do_tots, silent = FALSE, testing = TRUE, return = FALSE, diff --git a/FrEDI/scripts/create_DoW_results.R b/FrEDI/scripts/create_DoW_results.R index d487f457..a5237b85 100644 --- a/FrEDI/scripts/create_DoW_results.R +++ b/FrEDI/scripts/create_DoW_results.R @@ -204,24 +204,29 @@ create_DoW_results <- function( ###### Run scenarios to get results by type ### Run scenarios in FrEDI. Get model averages and national totals if(testing|do_msg) "Running integer scenarios..." |> message() + aggLvls0 <- c("modelaverage", "national") |> c("impactyear", "impacttype") + if(totals) aggLvls0 <- aggLvls0 |> c() df_int_byType <- inputs_df_int |> run_scenarios( col0 = "scenario", fredi = TRUE, sectors = sectors, - aggLevels = c("modelaverage", "national"), + # aggLevels = c("modelaverage", "national"), + aggLevels = aggLvls0, scenCols = c("scenario", "year", "temp_C_conus", "temp_C_global", "slr_cm"), joinCols = c("year"), return = TRUE, save = FALSE, outPath = dowPath ) + rm(aggLvls0) ### Glimpse results # if(return0) resultsList[["df_int_byType"]] <- df_int_byType if(testing) df_int_byType |> glimpse() ### Save results if(do_msg & saveFile) paste0("Saving integer scenario results by type...") |> message() - if(saveFile) df_int_byType |> save_data(fpath=dowPath, fname=rda_byType, ftype="rda") + if(saveFile & (!totals)) df_int_byType |> save_data(fpath=dowPath, fname=rda_byType, ftype="rda") + if(saveFile & totals ) df_int_byType |> save_data(fpath=dowPath, fname=rda_totals, ftype="rda") # for(scenario_i in cScenarios){ # ### Run scenario # df_i <- scenario_i |> run_scenario( @@ -240,153 +245,158 @@ create_DoW_results <- function( ###### ** Appendix Figs: DoW By Type ###### # codePath |> loadCustomFunctions() - if(testing|do_msg) "Summarizing GCM results by sector, impact type, degree of warming (DOW)..." |> message() - sum_gcm_byType <- df_int_byType |> sum_impacts_byDoW_years( - scenarios = c_scen_con, - bySector = TRUE, - sumCol = "annual_impacts", - impactYears = c("NA", "2010", "2090"), - models = c("GCM"), - adjVal = 1/10**9, ### Factor to multiply by - adjCol = "impact_billions", - silent = TRUE - ) - ### Glimpse - # if(return0) resultsList[["sum_gcm_byType"]] <- sum_gcm_byType - if(testing) sum_gcm_byType |> glimpse() - - ### Save summary table - if(do_msg & saveFile) paste0("Saving summary of GCM results by sector, impact type, degree of warming...") |> message() - if(saveFile) sum_gcm_byType |> save_data(fpath=appxPath, fname=csv_appx_gcm, ftype="csv", row.names=F) - - - ### Create Plots - # codePath |> loadCustomFunctions() - if(testing|do_msg) "Plotting GCM results by sector, impact type, degree of warming (DOW)..." |> message() - plots_gcm_byType <- sum_gcm_byType |> - # filter(sector %in% c_sectorNames[c(10)]) |> - filter(!(sector %in% c("Roads"))) |> - plot_DoW_by_sector( - models = c("GCM"), - yCol = "annual_impacts" + if(!totals){ + if(testing|do_msg) "Summarizing GCM results by sector, impact type, degree of warming (DOW)..." |> message() + sum_gcm_byType <- df_int_byType |> sum_impacts_byDoW_years( + scenarios = c_scen_con, + bySector = TRUE, + sumCol = "annual_impacts", + impactYears = c("NA", "2010", "2090"), + models = c("GCM"), + adjVal = 1/10**9, ### Factor to multiply by + adjCol = "impact_billions", + silent = TRUE ) - ### Glimpse - # if(return0) resultsList[["plots_gcm_byType"]] <- plots_gcm_byType - if(testing) plots_gcm_byType$GCM$`Extreme Temperature_2010`[["2010"]] |> print() - - ### Save - if(do_msg & saveFile) paste0("Saving plots of GCM results by sector, impact type, degree of warming...") |> message() - if(saveFile){ - ### Save plots as a data object - plots_gcm_byType |> save_data(fpath=appxPath, fname=rda_appx_gcm, ftype="rda") - - ### Save plots as image files - saved0 <- plots_gcm_byType |> save_appendix_figures( - df0 = sum_gcm_byType, - modelType = "GCM", ### Or SLR - fpath = appxPath, - device = img_dev, - res = imgRes, - units = imgUnits - ) ### End save_appendix_figures - } ### End if(saveFile) - rm(sum_gcm_byType, plots_gcm_byType) + ### Glimpse + # if(return0) resultsList[["sum_gcm_byType"]] <- sum_gcm_byType + if(testing) sum_gcm_byType |> glimpse() + + ### Save summary table + if(do_msg & saveFile) paste0("Saving summary of GCM results by sector, impact type, degree of warming...") |> message() + if(saveFile) sum_gcm_byType |> save_data(fpath=appxPath, fname=csv_appx_gcm, ftype="csv", row.names=F) + + + ### Create Plots + # codePath |> loadCustomFunctions() + if(testing|do_msg) "Plotting GCM results by sector, impact type, degree of warming (DOW)..." |> message() + plots_gcm_byType <- sum_gcm_byType |> + # filter(sector %in% c_sectorNames[c(10)]) |> + filter(!(sector %in% c("Roads"))) |> + plot_DoW_by_sector( + models = c("GCM"), + yCol = "annual_impacts" + ) + ### Glimpse + # if(return0) resultsList[["plots_gcm_byType"]] <- plots_gcm_byType + if(testing) plots_gcm_byType$GCM$`Extreme Temperature_2010`[["2010"]] |> print() + + ### Save + if(do_msg & saveFile) paste0("Saving plots of GCM results by sector, impact type, degree of warming...") |> message() + if(saveFile){ + ### Save plots as a data object + plots_gcm_byType |> save_data(fpath=appxPath, fname=rda_appx_gcm, ftype="rda") + + ### Save plots as image files + saved0 <- plots_gcm_byType |> save_appendix_figures( + df0 = sum_gcm_byType, + modelType = "GCM", ### Or SLR + fpath = appxPath, + device = img_dev, + res = imgRes, + units = imgUnits + ) ### End save_appendix_figures + } ### End if(saveFile) + rm(sum_gcm_byType, plots_gcm_byType) + } ### End if(!totals) ###### ** GCM Totals ###### - if(testing|do_msg) "Aggregating integer scenario results..." |> message() - #### Aggregate Impact Types, Impact Years - # df_int_totals <- df_int_byType |> run_scenarios( - # col0 = "scenario", - # fredi = FALSE, - # aggLevels = c("impactyear", "impacttype"), - # scenCols = c("scenario", "year", "temp_C_conus", "temp_C_global", "slr_cm"), - # joinCols = c("year") - # ) - group_totals <- c("sector", "variant", "impactType", "impactYear", "region", "state", "postal") |> - c("model_type", "model") |> - c("sectorprimary", "includeaggregate") |> - c("scenario", "temp_C_conus", "temp_C_global", "slr_cm") - agg_totals <- c("impactyear", "impacttype") - df_int_totals <- tibble() - for(scenario_i in cScenarios){ - ### Message user - "\n" |> paste0("Running scenario ", (cScenarios == scenario_i) |> which(), "/" , nScenarios, "...") |> message() - ### Get scenario by itself and drop scenario - df_i <- df_int_byType |> filter(scenario == scenario_i) - df_int_byType <- df_int_byType |> filter(scenario != scenario_i) - ### Aggregate scenario and add to dataframe - df_i <- df_i |> aggregate_impacts(aggLevels=agg_totals, groupByCols=group_totals) - df_int_totals <- df_int_totals |> rbind(df_i) - rm(df_i, scenario_i) - } ### End for(scenario_i in cScenarios) - rm(agg_totals, group_totals) - # rm(df_int_byType) - ### Glimpse results - # if(return0) resultsList[["df_int_totals"]] <- df_int_totals - if(testing) df_int_totals |> glimpse() - ### Save results - if(do_msg & saveFile) paste0("Saving aggregated integer scenario results...") |> message() - if(saveFile) df_int_totals |> save_data(fpath=dowPath, fname=rda_totals, ftype="rda") - # return(list(x=c_scen_con, y=c_scen_glo, z=df_int_totals)) - - ###### ** Fig 7 ###### - ###### ** -- Figure 7: DoW by Sector - ###### ** -- -- Data - ###### Summarize GCM sectors for degrees of warming - # codePath |> loadCustomFunctions() - if(testing|do_msg) "Summarizing GCM results by sector, degree of warming (DOW)..." |> message() - sum_gcm_totals <- df_int_totals |> sum_impacts_byDoW_years( - scenarios = c_scen_con, - bySector = FALSE, - sumCol = "annual_impacts", - impactYears = c("Interpolation"), - models = c("GCM"), - aggOnly = aggOnly, - years = gcmYears, - adjVal = 1/10**9, ### Factor to multiply by - adjCol = "impact_billions" - ) - rm(df_int_totals) - ### Glimpse - # if(return0) resultsList[["sum_gcm_totals"]] <- sum_gcm_totals - if(testing) sum_gcm_totals |> glimpse() - if(do_msg & saveFile) paste0("Saving summary of GCM results by sector, degree of warming...") |> message() - ### Save 2090 summary table - if(saveFile) sum_gcm_totals |> save_data(fpath=fig7Path, fname=csv_fig7_gcm, ftype="csv", row.names=F) - # return(list(x=c_scen_con, y=c_scen_glo, z=df_int_totals, w=sum_gcm_totals)) - - ###### ** -- -- Plots - #### Create plots - ### Scale isn't the same across sectors - # codePath |> loadCustomFunctions() - if(testing|do_msg) "Plotting GCM results by sector, degree of warming (DOW)..." |> message() - plots_dow_gcm <- sum_gcm_totals |> plot_DoW( - types0 = c("GCM"), ### Model type: GCM or SLR - years = gcmYears, - xCol = "driverValue", - yCol = "annual_impacts", - thresh0 = breakChars - ) - rm(sum_gcm_totals) - ### Glimpse - # if(return0) resultsList[["plots_dow_gcm"]] <- plots_dow_gcm - if(testing) plots_dow_gcm[["GCM_2090"]] |> print() - ### Save - # codePath |> loadCustomFunctions() - if(do_msg & saveFile) paste0("Saving plots of GCM results by sector, degree of warming...") |> message() - if(saveFile){ - ### Save plots as Rdata - plots_dow_gcm |> save_data(fpath=fig7Path, fname=rda_fig7_gcm, ftype="rda") - - ### Save plots as image files - saved0 <- plots_dow_gcm |> save_fig7_images( - modelType = "GCM", - fpath = fig7Path, - device = img_dev, - units = imgUnits + if(totals){ + # if(testing|do_msg) "Aggregating integer scenario results..." |> message() + # #### Aggregate Impact Types, Impact Years + # # df_int_totals <- df_int_byType |> run_scenarios( + # # col0 = "scenario", + # # fredi = FALSE, + # # aggLevels = c("impactyear", "impacttype"), + # # scenCols = c("scenario", "year", "temp_C_conus", "temp_C_global", "slr_cm"), + # # joinCols = c("year") + # # ) + # group_totals <- c("sector", "variant", "impactType", "impactYear", "region", "state", "postal") |> + # c("model_type", "model") |> + # c("sectorprimary", "includeaggregate") |> + # c("scenario", "temp_C_conus", "temp_C_global", "slr_cm") + # agg_totals <- c("impactyear", "impacttype") + # df_int_totals <- tibble() + # for(scenario_i in cScenarios){ + # ### Message user + # "\n" |> paste0("Running scenario ", (cScenarios == scenario_i) |> which(), "/" , nScenarios, "...") |> message() + # ### Get scenario by itself and drop scenario + # df_i <- df_int_byType |> filter(scenario == scenario_i) + # df_int_byType <- df_int_byType |> filter(scenario != scenario_i) + # ### Aggregate scenario and add to dataframe + # df_i <- df_i |> aggregate_impacts(aggLevels=agg_totals, groupByCols=group_totals) + # df_int_totals <- df_int_totals |> rbind(df_i) + # rm(df_i, scenario_i) + # } ### End for(scenario_i in cScenarios) + # rm(agg_totals, group_totals) + # # rm(df_int_byType) + # ### Glimpse results + # # if(return0) resultsList[["df_int_totals"]] <- df_int_totals + # if(testing) df_int_totals |> glimpse() + # ### Save results + # if(do_msg & saveFile) paste0("Saving aggregated integer scenario results...") |> message() + # if(saveFile) df_int_totals |> save_data(fpath=dowPath, fname=rda_totals, ftype="rda") + # # return(list(x=c_scen_con, y=c_scen_glo, z=df_int_totals)) + df_int_totals <- df_int_byType + rm(df_int_byType) + + ###### ** -- Figure 7: DoW by Sector + ###### ** -- -- Data + ###### Summarize GCM sectors for degrees of warming + # codePath |> loadCustomFunctions() + if(testing|do_msg) "Summarizing GCM results by sector, degree of warming (DOW)..." |> message() + sum_gcm_totals <- df_int_totals |> sum_impacts_byDoW_years( + scenarios = c_scen_con, + bySector = FALSE, + sumCol = "annual_impacts", + impactYears = c("Interpolation"), + models = c("GCM"), + aggOnly = aggOnly, + years = gcmYears, + adjVal = 1/10**9, ### Factor to multiply by + adjCol = "impact_billions" ) - } ### End if(saveFile) - rm(plots_dow_gcm) + rm(df_int_totals) + ### Glimpse + # if(return0) resultsList[["sum_gcm_totals"]] <- sum_gcm_totals + if(testing) sum_gcm_totals |> glimpse() + if(do_msg & saveFile) paste0("Saving summary of GCM results by sector, degree of warming...") |> message() + ### Save 2090 summary table + if(saveFile) sum_gcm_totals |> save_data(fpath=fig7Path, fname=csv_fig7_gcm, ftype="csv", row.names=F) + # return(list(x=c_scen_con, y=c_scen_glo, z=df_int_totals, w=sum_gcm_totals)) + + ###### ** -- -- Plots + #### Create plots + ### Scale isn't the same across sectors + # codePath |> loadCustomFunctions() + if(testing|do_msg) "Plotting GCM results by sector, degree of warming (DOW)..." |> message() + plots_dow_gcm <- sum_gcm_totals |> plot_DoW( + types0 = c("GCM"), ### Model type: GCM or SLR + years = gcmYears, + xCol = "driverValue", + yCol = "annual_impacts", + thresh0 = breakChars + ) + rm(sum_gcm_totals) + ### Glimpse + # if(return0) resultsList[["plots_dow_gcm"]] <- plots_dow_gcm + if(testing) plots_dow_gcm[["GCM_2090"]] |> print() + ### Save + # codePath |> loadCustomFunctions() + if(do_msg & saveFile) paste0("Saving plots of GCM results by sector, degree of warming...") |> message() + if(saveFile){ + ### Save plots as Rdata + plots_dow_gcm |> save_data(fpath=fig7Path, fname=rda_fig7_gcm, ftype="rda") + + ### Save plots as image files + saved0 <- plots_dow_gcm |> save_fig7_images( + modelType = "GCM", + fpath = fig7Path, + device = img_dev, + units = imgUnits + ) + } ### End if(saveFile) + rm(plots_dow_gcm) + } ### End if(totals) ###### SLR Results & Figures ###### ###### ** -- Format SLR Data ###### @@ -459,49 +469,51 @@ create_DoW_results <- function( ###### ** -- Appendix Figs: DoW By Type ###### # codePath |> loadCustomFunctions() - if(testing|do_msg) "Summarizing SLR results by sector, impact type, GMSL (cm)..." |> message() - sum_slr_byType <- get_fig7_slrImpacts( - slrDrivers = ciraSLRData[["slrCm" ]] |> filter(year >= 2010, year <= 2090), - slrImpacts = ciraSLRData[["slrImp"]] |> filter(year >= 2010, year <= 2090), - bySector = TRUE, - sumCol = "annual_impacts", - adjVal = 1/10**9, ### Factor to multiply by - adjCol = "impact_billions" - ) - ### Glimpse - # if(return0) resultsList[["sum_slr_byType"]] <- sum_slr_byType - if(testing) sum_slr_byType |> glimpse() - ### Save - if(do_msg & saveFile) paste0("Saving plot of SLR scenarios by year...") |> message() - if(saveFile) sum_slr_byType |> save_data(fpath=appxPath, fname=csv_appx_slr, ftype="csv", row.names=F) - - ### Create SLR plots - # codePath |> loadCustomFunctions() - if(testing|do_msg) "Plotting SLR results by sector, impact type, GMSL (cm)..." |> message() - plots_slr_byType <- sum_slr_byType |> plot_DoW_by_sector( - models = c("SLR"), - xCol = "year", - yCol = "annual_impacts" - ) - ### Glimpse - # if(return0) resultsList[["plots_slr_byType"]] <- plots_slr_byType - if(testing) plots_slr_byType$SLR$`Coastal Properties_all`[[1]] |> print() - ### Save - if(do_msg & saveFile) paste0("Saving plot of SLR scenarios by sector, impact type, GMSL (cm)...") |> message() - if(saveFile) { - ### Save plots as a data object - plots_slr_byType |> save_data(fpath=appxPath, fname=rda_appx_slr, ftype="rda") - - ### Save plots as image files - saved0 <- plots_slr_byType |> save_appendix_figures( - df0 = sum_slr_byType, - modelType = "SLR", ### Or SLR - fpath = appxPath, - device = img_dev, - res = imgRes, - units = imgUnits - ) ### End save_appendix_figures - } ### End if(saveFile) + if(!totals){ + if(testing|do_msg) "Summarizing SLR results by sector, impact type, GMSL (cm)..." |> message() + sum_slr_byType <- get_fig7_slrImpacts( + slrDrivers = ciraSLRData[["slrCm" ]] |> filter(year >= 2010, year <= 2090), + slrImpacts = ciraSLRData[["slrImp"]] |> filter(year >= 2010, year <= 2090), + bySector = TRUE, + sumCol = "annual_impacts", + adjVal = 1/10**9, ### Factor to multiply by + adjCol = "impact_billions" + ) + ### Glimpse + # if(return0) resultsList[["sum_slr_byType"]] <- sum_slr_byType + if(testing) sum_slr_byType |> glimpse() + ### Save + if(do_msg & saveFile) paste0("Saving plot of SLR scenarios by year...") |> message() + if(saveFile) sum_slr_byType |> save_data(fpath=appxPath, fname=csv_appx_slr, ftype="csv", row.names=F) + + ### Create SLR plots + # codePath |> loadCustomFunctions() + if(testing|do_msg) "Plotting SLR results by sector, impact type, GMSL (cm)..." |> message() + plots_slr_byType <- sum_slr_byType |> plot_DoW_by_sector( + models = c("SLR"), + xCol = "year", + yCol = "annual_impacts" + ) + ### Glimpse + # if(return0) resultsList[["plots_slr_byType"]] <- plots_slr_byType + if(testing) plots_slr_byType$SLR$`Coastal Properties_all`[[1]] |> print() + ### Save + if(do_msg & saveFile) paste0("Saving plot of SLR scenarios by sector, impact type, GMSL (cm)...") |> message() + if(saveFile) { + ### Save plots as a data object + plots_slr_byType |> save_data(fpath=appxPath, fname=rda_appx_slr, ftype="rda") + + ### Save plots as image files + saved0 <- plots_slr_byType |> save_appendix_figures( + df0 = sum_slr_byType, + modelType = "SLR", ### Or SLR + fpath = appxPath, + device = img_dev, + res = imgRes, + units = imgUnits + ) ### End save_appendix_figures + } ### End if(saveFile) + } ### if(!totals) ###### ** -- Figure 7: DoW by Sector ###### ### SLR sectors separately: @@ -509,51 +521,53 @@ create_DoW_results <- function( ### - Calculate national totals ### - Combine CIRA impacts and SLR trajectories # codePath |> loadCustomFunctions() - if(testing|do_msg) "Summarizing SLR results by sector, year, GMSL (cm)..." |> message() - sum_slr_totals <- get_fig7_slrImpacts( - slrDrivers = ciraSLRData[["slrCm" ]] |> filter(year >= 2010, year <= 2090), - slrImpacts = ciraSLRData[["slrImp"]] |> filter(year >= 2010, year <= 2090), - bySector = FALSE, - aggOnly = aggOnly, - years = slrYears, - adjVal = 1/10**9, ### Factor to multiply by - adjCol = "impact_billions" - ) - ### Glimpse - # if(return0) resultsList[["sum_slr_totals"]] <- sum_slr_totals - if(testing) sum_slr_totals |> glimpse() - # sum_gcm_totals |> glimpse() - ### Save - if(do_msg & saveFile) paste0("Saving summary of SLR results by sector, year, GMSL (cm)...") |> message() - if(saveFile) sum_slr_totals |> save_data(fpath=fig7Path, fname=csv_fig7_slr, ftype="csv", row.names=F) - - ###### ** -- Plots - ### Create the plots - # codePath |> loadCustomFunctions() - if(testing|do_msg) "Plotting SLR results by sector, year, GMSL (cm)..." |> message() - plots_dow_slr <- sum_slr_totals |> plot_DoW( - types0 = c("SLR"), ### Model type: GCM or SLR - yCol = "annual_impacts", - nCol = 2, - thresh0 = breakChars - ) - ### Glimpse - # if(return0) resultsList[["plots_dow_slr"]] <- plots_dow_slr - if(testing) plots_dow_slr[["SLR_all"]] |> print() - ### Save - if(do_msg) paste0("Saving plots of SLR results by sector, year, GMSL (cm)...") |> message() - if(saveFile & saveFile){ - ### Save plots as a data object - plots_dow_slr |> save_data(fpath=fig7Path, fname=rda_fig7_slr, ftype="rda") - - ### Save plots as image files - plots_dow_slr |> save_fig7_images( - modelType = "SLR", ### Or SLR - fpath = fig7Path, - device = img_dev, - units = imgUnits + if(totals){ + if(testing|do_msg) "Summarizing SLR results by sector, year, GMSL (cm)..." |> message() + sum_slr_totals <- get_fig7_slrImpacts( + slrDrivers = ciraSLRData[["slrCm" ]] |> filter(year >= 2010, year <= 2090), + slrImpacts = ciraSLRData[["slrImp"]] |> filter(year >= 2010, year <= 2090), + bySector = FALSE, + aggOnly = aggOnly, + years = slrYears, + adjVal = 1/10**9, ### Factor to multiply by + adjCol = "impact_billions" ) - } ### End if(saveFile) + ### Glimpse + # if(return0) resultsList[["sum_slr_totals"]] <- sum_slr_totals + if(testing) sum_slr_totals |> glimpse() + # sum_gcm_totals |> glimpse() + ### Save + if(do_msg & saveFile) paste0("Saving summary of SLR results by sector, year, GMSL (cm)...") |> message() + if(saveFile) sum_slr_totals |> save_data(fpath=fig7Path, fname=csv_fig7_slr, ftype="csv", row.names=F) + + ###### ** -- Plots + ### Create the plots + # codePath |> loadCustomFunctions() + if(testing|do_msg) "Plotting SLR results by sector, year, GMSL (cm)..." |> message() + plots_dow_slr <- sum_slr_totals |> plot_DoW( + types0 = c("SLR"), ### Model type: GCM or SLR + yCol = "annual_impacts", + nCol = 2, + thresh0 = breakChars + ) + ### Glimpse + # if(return0) resultsList[["plots_dow_slr"]] <- plots_dow_slr + if(testing) plots_dow_slr[["SLR_all"]] |> print() + ### Save + if(do_msg) paste0("Saving plots of SLR results by sector, year, GMSL (cm)...") |> message() + if(saveFile & saveFile){ + ### Save plots as a data object + plots_dow_slr |> save_data(fpath=fig7Path, fname=rda_fig7_slr, ftype="rda") + + ### Save plots as image files + plots_dow_slr |> save_fig7_images( + modelType = "SLR", ### Or SLR + fpath = fig7Path, + device = img_dev, + units = imgUnits + ) + } ### End if(saveFile) + } ### if(totals)