2c. Run Report Scenarios #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### https://github.com/actions/upload-artifact | |
### https://github.blog/changelog/2021-11-10-github-actions-input-types-for-manual-workflows/ | |
### https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows | |
### https://github.com/r-lib/actions/tree/v2/setup-r-dependencies | |
### https://docs.github.com/en/actions/using-jobs/using-conditions-to-control-job-execution | |
### Single line conditional can use ${{}} formulation. Multi-line conditional does not. | |
### For uploading artifacts: | |
### "path:" is the output path where Pandoc will write the compiled PDF. | |
### Note, this should be the same directory as the input paper.md | |
name: 2c. Run Report Scenarios | |
on: | |
workflow_dispatch: | |
inputs: | |
sector: | |
description: Which sectors do you want to run? Enter "all", "gcm", "slr", or specific sector name(s) (if more than one, separate with a comma) | |
required: true | |
type: string | |
default: "all" | |
# doScenarios: | |
# description: Do you want to generate scenario results for report figures? | |
# required: true | |
# type: choice | |
# options: | |
# - no | |
# - yes | |
figure_type: | |
description: Which type of scenario do you want to run? | |
required: true | |
type: choice | |
default: Appendix figures | |
options: | |
- Defaults to 2100 | |
- Constant temperatures to 2100 | |
- To 2300 | |
agg_lvls: | |
description: Which aggregation levels do you want to run? Enter "all", "none", "slr", any/all of "national", "modelaverage", "impacttype", and/or "impactyear" (do not enter quotation marks and if more than one, separate with a comma) | |
type: string | |
default: "all" | |
out_list: | |
description: Do you want to save a list with model provenance info? | |
required: true | |
type: choice | |
default: no | |
options: | |
- no | |
- yes | |
tempScenario: | |
description: If running scenarios to 2300, which temperature scenario do you want to use? "temp_0to6_to2300" = 0 to 6 degrees Celsius (CONUS) and "rff_temp_mean" = RFF mean temperature scenario (do not enter quotation marks) | |
required: true | |
type: choice | |
default: temp_0to6_to2300 | |
options: | |
- temp_0to6_to23000 | |
- rff_temp_mean | |
# max_year: | |
# type: numeric | |
# description: What is the maximum year? | |
# required: true | |
# default: 2100 | |
# options: | |
# - Defaults | |
# - Constant temperatures | |
# - Through 2300 | |
jobs: | |
run_scenarios: | |
runs-on: ubuntu-latest | |
env: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
name: Load Package Code | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Send input status | |
run: | | |
echo "ref_name = ${{ github.ref_name }}" | |
echo "sector = ${{ inputs.sector }}" | |
echo "figure_type = ${{ inputs.figure_type }}" | |
echo "tempScenario = ${{ inputs.tempScenario }}" | |
echo "agg_lvls = ${{ inputs.agg_lvls }}" | |
echo "out_list = ${{ inputs.out_list }}" | |
# echo "max_year = ${{ inputs.max_year }}" | |
- name: Setup R | |
uses: r-lib/actions/setup-r@v2 | |
- name: Setup R package dependencies | |
uses: r-lib/actions/setup-r-dependencies@v2 | |
with: | |
cache: true | |
cache-version: 1 | |
packages: | | |
any::tidyverse | |
any::devtools | |
any::openxlsx | |
any::ggpubr | |
### Install FrEDI from new branch and get results | |
- name: Test results | |
# if: | | |
# inputs.doScenarios == 'true' | |
run: | | |
Rscript -e ' | |
###### Libraries ### | |
require(tidyverse) | |
require(devtools) | |
require(openxlsx) | |
require(ggpubr) | |
###### Workflow Inputs ###### | |
# doScenarios <- "${{ inputs.doScenarios }}" %in% c("true", "yes") | |
newBranch <- "${{ github.ref_name }}" | |
sectors0 <- "${{ inputs.sector }}" | |
figure_type <- "${{ inputs.figure_type }}" | |
scenario0 <- "${{ inputs.tempScenario }}" | |
agg_lvls0 <- "${{ inputs.agg_lvls }}" | |
outList0 <- "${{ inputs.out_list }}" | |
# max_year <- "${{ inputs.max_year }}" | |
# "got here1" |> print() | |
###### Functions ###### | |
loadCode <- function(files0){for(file_i in files0){file_i |> source(); rm(file_i)}} | |
###### Paths ###### | |
### Main repo path, FrEDI project path, scripts path | |
rPath0 <- "."; | |
# pPath0 <- rPath0 |> file.path("FrEDI") | |
pPath0 <- rPath0 | |
# "got here1" |> print() | |
### Load scripts and testing functions | |
sPath0 <- pPath0 |> file.path("scripts") | |
tPath0 <- pPath0 |> file.path("testing") | |
sFiles0 <- sPath0 |> list.files(full.names=TRUE) | |
tFiles0 <- tPath0 |> list.files(full.names=TRUE) | |
rmd_file <- tFiles0[grepl(".rmd",tFiles0)] | |
tFiles0 <- tFiles0[!grepl(".rmd",tFiles0)] | |
# for(file_i in tFiles0){file_i |> source(); rm(file_i)} | |
sFiles0 |> loadCode() | |
tFiles0 |> loadCode() | |
### Check if path exists and, if not, create it | |
### Where to save results | |
oPath0 <- pPath0 |> file.path("data_tests") | |
exists0 <- oPath0 |> dir.exists() | |
if(!exists0) {oPath0 |> dir.create(recursive=TRUE)} | |
# "got here5" |> print() | |
###### Repo Info ###### | |
urlRepo <- "https://github.com/USEPA/FrEDI" | |
c(newBranch) |> print() | |
###### ** Install FrEDI from New Branch ###### | |
pPath0 |> devtools::load_all() | |
###### Values ###### | |
### Figure Type | |
agg_lvls0 <- agg_lvl0 |> standardize_actionStrings() | |
allCols0 <- "none" %in% (agg_lvls0 |> tolower()) | |
### Figure Type | |
figTypeLc <- fig_type |> tolower() | |
doConstant <- figTypeLC |> str_detect("constant") | |
doDefaults <- figTypeLC |> str_detect("default") | |
do2300 <- figTypeLC |> str_detect("2300") | |
### Max Year | |
max_year0 <- case_when(do2300 ~ 2300, .default = 2100) | |
### Sectors | |
sectors0 |> print() | |
sectors <- sectors0 |> get_action_sectors() | |
sectors |> print() | |
### Which years to report on for GCM, SLR sectors | |
gcmYears0 <- c(2010, 2090) | |
slrYears0 <- c(2050, 2090) | |
###### Run Scenarios ###### | |
###### ** Setup Scenarios ###### | |
### Run defaults | |
if(doDefaults) { | |
defPath <- oPath0 |> file.path("defaultResults") |> paste0(".", "rda") | |
defaultResults <- run_fredi(sectorList=sectors, aggLevels=agg_lvls0, allCols=allCols0) | |
defaultResults |> save(file=defPath) | |
oPath0 |> list.files() |> print() | |
} ### End if(!doDefaults) | |
### Run to 2300 | |
if(do2300) { | |
### rDataList$scenarioData$testScenarios calc_import_pop | |
defPath <- oPath0 |> file.path("resultsTo2300") |> paste0(".", "rda") | |
sortCols0 <- c("area", "region", "state", "year") | |
scenarios0 <- c("rff_gdp_mean", "rff_pop_mean") |> c(scenario0) | |
scenNames0 <- c("gdp", "pop", "temp") | |
inputs0 <- "testScenarios" |> get_frediDataObj(listSub="scenarioData") | |
inputs0 <- inputs0[(inputs0 |> names()) %in% scenarios0] |> set_names(scenNames0) | |
inputs0[["pop"]] <- inputs0[["pop"]] |> calc_import_pop(popArea="national", module="fredi") | |
resultsT02300 <- run_fredi(inputsList=list0, sectorList=sectors, aggLevels=agg_lvls0, allCols=allCols0, outputList=outList0) | |
resultsT02300 |> save(file=defPath) | |
oPath0 |> list.files() |> print() | |
} ### End if(!doDefaults) | |
### Constant temps | |
if(doConstant) { | |
### CONUS temps, Global temps | |
conusTemps <- list(temps=c(0:10) , tempLabels=c(0:10) , tempType="conus" , prefix="Other_Integer") | |
globalTemps <- list(temps=c(1.487, 2.198), tempLabels=c(1.5, 2), tempType="global", prefix="preI_global") | |
### Temps list | |
tempsList <- list(conus=conusTemps, global=globalTemps) | |
rm(conusTemps, globalTemps) | |
###### ** Run Scenarios ###### | |
### aggOnly=Whether to only include sectors for which "includeaggregate==1" in Fig 7 plots | |
### Run scenarios | |
dfResults <- run_constantTempScenarios( | |
sectors = sectors, | |
tempList = tempsList, | |
gcmYears = gcmYears0, | |
slrYears = slrYears0, | |
aggOnly = FALSE, | |
loadCode = "project", | |
silent = TRUE , | |
testing = FALSE, | |
fpath = pPath0, | |
saveFile = TRUE , | |
outPath = oPath0, | |
return = FALSE | |
) ### End run_constantTempScenarios | |
rm(dfResults) | |
} ### End if(doConstant) | |
###### Return ###### | |
"Finished running report scenarios." |> print() | |
oPath0 |> list.files() |> print() | |
' | |
- name: Upload Scenario Results | |
# if: | | |
# inputs.doScenarios == 'true' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: scenario_results | |
path: | | |
./data_tests/* | |