Skip to content

Commit

Permalink
Merge branch 'state_level_addSectors' into pop_downscaling
Browse files Browse the repository at this point in the history
  • Loading branch information
knoiva-indecon committed Jun 12, 2024
2 parents 55202ee + 785c7f7 commit f98044d
Show file tree
Hide file tree
Showing 15 changed files with 931 additions and 696 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_fredi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
### 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: Build FrEDI Package
name: 4. Build FrEDI Package

on: [workflow_dispatch]

Expand Down
114 changes: 82 additions & 32 deletions .github/workflows/test_fredi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,36 @@
### 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: Test FrEDI Package
name: 3. Test FrEDI Package

# on: [workflow_dispatch]
on:
workflow_dispatch:
inputs:
run_tests:
type: choice
description: Run general tests
description: Run general tests?
required: true
options:
- no
- yes
make_figures:
figH_results:
type: choice
description: Create report figures
description: Fig H results?
required: true
options:
- no
- yes
make_appx_figs:
type: choice
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
Expand All @@ -40,7 +54,7 @@ jobs:

- name: Send input status
run: |
echo "${{ inputs.run_tests }} ${{ 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
Expand All @@ -67,15 +81,12 @@ jobs:
upgrade = "never",
force = TRUE,
type = "source"
)'
)
'
- name: Run create_DoW_results
- name: Run tests & create figures
run: |
Rscript -e '
### Which tests to do
do_tests <- "${{ inputs.run_tests }}" == "true"
do_figs <- "${{ inputs.make_figures }}" == "true"
### Main repo path, FrEDI project path, scripts path
rPath0 <- ".";
pPath0 <- rPath0 |> file.path("FrEDI")
Expand All @@ -89,19 +100,36 @@ jobs:
tFiles0 <- tPath0 |> list.files(full.names=TRUE)
for(file_i in tFiles0){file_i |> source(); rm(file_i)}
### Load source
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_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")
oPath1 <- oPath0 |> file.path("general")
oPath2 <- oPath0 |> file.path("report_figures")
### Whether paths exist
exists0 <- oPath0 |> dir.exists()
exists1 <- oPath1 |> dir.exists()
exists2 <- oPath2 |> dir.exists()
### Check if path exists and, if not, create it
if(!exists0){ oPath0 |> dir.create(recursive = TRUE)}
if(!exists1){ oPath1 |> dir.create(recursive = TRUE)}
if(!exists2){ oPath2 |> dir.create(recursive = TRUE)}
### Test results
if(do_tests){
### Check if path exists and, if not, create it
exists0 <- oPath1 |> dir.exists()
if(!exists0){oPath1 |> dir.create(recursive = TRUE)}
### Run FrEDI
results0 <- run_fredi()
### Run tests
tests0 <- results0 |> general_fredi_test(
outPath = oPath1,
Expand All @@ -115,35 +143,37 @@ jobs:
save0 <- listResults |> save(file= oPath1 |> file.path("defaultScenarioTotals.rda")) |> try()
### Remove results
rm(results0, tests0, listResults)
}
rm(exists0, results0, tests0, listResults, save0)
} ### End if(do_tests)
### Create report results
### Create Fig H results
if(do_figH){
### Figure H results
results0 <- run_fredi(aggLevels=c("modelaverage", "national", "impactYear"))
results0 <- results0 |> filter(year %in% seq(2010, 2090, by=5))
save0 <- results0 |> write.csv(file=oPath2 |> file.path("FigH_results.csv"), row.names=F) |> try()
### Remove reslts
rm(results0, save0)
} ### End if(do_figH)
### Create report figures
if(do_figs){
### Load source
sPath0 |> file.path("create_DoW_results.R") |> source()
### Check if path exists and, if not, create it
exists0 <- oPath2 |> dir.exists()
if(!exists0){oPath2 |> dir.create(recursive = TRUE)}
### Create report figures
reports0 <- create_DoW_results(
outPath = oPath2,
saveFile = TRUE,
loadCode = "project",
totals = do_tots,
silent = FALSE,
testing = TRUE,
return = FALSE,
fpath = pPath0
)
### Figure H results
results0 <- run_fredi(aggLevels=c("modelaverage", "national", "impactYear"))
results0 <- results0 |> filter(year %in% seq(2010, 2090, by=5))
save0 <- results0 |> write.csv(file=oPath2 |> file.path("FigH_results.csv"), row.names=F) |> try()
}
} ### End if(do_figs)
'
- name: Upload Tests
Expand All @@ -156,12 +186,32 @@ jobs:
./FrEDI/data_tests/general/defaultScenarioTotals.rda
./FrEDI/data_tests/general/testResults_fredi_general.xlsx
- name: Upload Report Figures
- name: Upload FigH Results
if: |
inputs.figH_results == 'true'
uses: actions/upload-artifact@v3
with:
name: FigH results
path: |
./FrEDI/data_tests/report_figures/
- name: Upload Report Appendix Figures
if: |
inputs.make_appx_figs == 'true'
uses: actions/upload-artifact@v3
with:
name: Report appendix figures & data
path: |
./FrEDI/data_tests/report_figures/
- name: Upload Report Fig7 Figures
if: |
inputs.make_figures == 'true'
inputs.make_tots_figs == 'true'
uses: actions/upload-artifact@v3
with:
name: Report Data
name: Fig7 report figures & data
path: |
./FrEDI/data_tests/report_figures/
# ./FrEDI/data_tests/general/FigH_results.csv
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update_base_data.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Update Base System Data
name: 1. Update Base System Data

on:
workflow_dispatch:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update_sv_impactsList.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Update SV ImpactsList Data
name: 2. Update SV ImpactsList Data (as needed)

on:
workflow_dispatch:
Expand Down
38 changes: 27 additions & 11 deletions FrEDI/R/FrEDI-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,77 @@
#' README
#' FrEDI: The Framework for Evaluating Damages and Impacts
#'
#' [FrEDI] is an R package being developed by the U.S. Environmental Protection Agency (EPA). The functions and data provided by this package can be used to estimate climate change impacts for the contiguous United States (CONUS) using the Framework for Evaluating Damages and Impacts (FrEDI), developed as part of EPA's [Climate Change Impacts and Risk Analysis](https://epa.gov/cira/) (CIRA) project. [FrEDI] contains R code that implement FrEDI and allow users to project impacts from climate change and sea level rise for a selected set of sectors.
#'
#' For help getting started with [FrEDI], visit <https://usepa.github.io/FrEDI/articles/manual.html>.
#' FrEDI is an R package being developed by the U.S. Environmental Protection Agency (EPA). The functions and data provided by this package can be used to estimate climate change impacts for the contiguous United States (CONUS) using the [Framework for Evaluating Damages and Impacts (FrEDI)](https://epa.gov/cira/FrEDI/), developed as part of EPA's [Climate Change Impacts and Risk Analysis](https://epa.gov/cira/) (CIRA) project. FrEDI contains R code that implement FrEDI and allow users to project impacts from climate change and sea level rise for a selected set of sectors.
#'
#'
#'
#' For help getting started with FrEDI, visit <https://usepa.github.io/FrEDI/articles/manual.html>.
#'
#' For additional package documentation, see <https://usepa.github.io/FrEDI/index.html>.
#'
#' For more information on the Framework and the CIRA project, visit <https://epa.gov/cira/>, especially <https://epa.gov/cira/FrEDI/>.
#'
#'
#'
#' @section Overview of Functions:
#' The function [FrEDI::run_fredi()] provided in this package is the primary function implementing the [`FrEDI`](https://epa.gov/cira/FrEDI/) developed by the U.S. EPA for projecting annual climate impacts. The main inputs to [FrEDI::run_fredi()] are climate scenarios (temperature in degrees Celsius, global mean sea level rise in centimeters) and socioeconomic scenarios (U.S. gross domestic product, state population).
#'
#' [FrEDI] also contains functions to assist in the pre-processing of input scenarios and the post-processing of outputs.
#' The function [FrEDI::run_fredi()] provided in this package is the primary function implementing the [Framework for Evaluating Damages and Impacts (FrEDI)](https://epa.gov/cira/FrEDI/), developed by the U.S. EPA for projecting annual climate impacts. The main inputs to [FrEDI::run_fredi()] are climate scenarios (temperature in degrees Celsius, global mean sea level rise in centimeters) and socioeconomic scenarios (U.S. gross domestic product, state population).
#'
#' FrEDI also contains functions to assist in the pre-processing of input scenarios and the post-processing of outputs.
#'
#' * Pre-processing functions include [FrEDI::get_sectorInfo()], [FrEDI::import_inputs()], [FrEDI::convertTemps()], [FrEDI::temps2slr()].
#' * [FrEDI::get_sectorInfo()] allows users to access a list of sectors within `FrEDI` and related sector information.
#' * [FrEDI::import_inputs()] helps users in importing custom scenarios from user-specified comma-separated value (CSV) files.
#' * [FrEDI::convertTemps()] helps users to convert between global mean temperature and temperatures for the contiguous United States (CONUS) (both in degrees Celsius).
#' * [FrEDI::temps2slr()] helps users to estimate global mean sea level rise (GMSL, in centimeters) from global mean temperature in degrees Celsius.
#'
#' [FrEDI::aggregate_impacts()] is a post-processing helper function that helps users to aggregate and summarize the outputs of [FrEDI]. [FrEDI::aggregate_impacts()] can be used to calculate national totals, model averages, sum over impact types, and interpolate between multiple impact years (note that [FrEDI::run_fredi()] will automatically run [FrEDI::aggregate_impacts()] before returning outputs if the `aggLevels` argument is not `"none"`).
#' [FrEDI::aggregate_impacts()] is a post-processing helper function that helps users to aggregate and summarize the outputs of FrEDI. [FrEDI::aggregate_impacts()] can be used to calculate national totals, model averages, sum over impact types, and interpolate between multiple impact years (note that [FrEDI::run_fredi()] will automatically run [FrEDI::aggregate_impacts()] before returning outputs if the `aggLevels` argument is not `"none"`).
#'
#' Versions 2.3.0 and above include the `FrEDI` Social Vulnerability (SV) module for estimating impacts on socially vulnerable populations for select sectors. [FrEDI::get_sv_sectorInfo()] allows users to access a list of sectors within the FrEDI SV module and related sector information. The function [FrEDI::run_fredi_sv()] is the main function for the `FrEDI` SV module. [FrEDI::run_fredi_sv()] is designed to calculate impacts for a single sector at a time for a custom population scenario or one or more custom temperature or sea level rise scenarios. For more information on the data underlying the `FrEDI` SV module, see <https://www.epa.gov/cira/social-vulnerability-report/>.
#'
#' @section Overview of Package Contents:
#' [FrEDI] consists of files in the following directories:
#'
#'
#' @section Overview of Package Contents:
#'
#' FrEDI consists of files in the following directories:
#' * __R__. Contains function definitions (files ending in `".R"`) and configuration files (ending in `".rda"`).
#' * __data__. Contains R Data files ending in `".rdb"`, `".rds"`, and `".rdx"`, containing data included with the package.
#' * __help__ and __html__. Contain documentation for functions available to the user, including function descriptions, lists of arguments and outputs, and examples. See `"html/00Index.html"` or the individual R help functions for more information about individual functions.
#' * __Meta__. Contains RDS files (ending in `".rds"`) with information about the package contents.
#' * __extdata__. __extdata/scenarios__ Contains four CSV files for users to test the function for importing data. For more information on importing scenarios for use with [FrEDI::run_fredi()], refer to documentation for the function [FrEDI::import_inputs()].
#' * `"GCAM_scenario.csv"` contains a set of temperature scenarios that can be used with [FrEDI], including the default temperature scenario used by both [FrEDI::run_fredi()] and [FrEDI::run_fredi_sv()] (labeled `"description="Hector_GCAM_v5.3_ECS_3.0_REF"` in `"slr_from_GCAM.csv"` and `"ECS_3.0_ref_0"` in the [FrEDI::gcamScenarios] dataset)). Also see the documentation for the [FrEDI::gcamScenarios] dataset for more information.
#' * `"GCAM_scenario.csv"` contains a set of temperature scenarios that can be used with FrEDI, including the default temperature scenario used by both [FrEDI::run_fredi()] and [FrEDI::run_fredi_sv()] (labeled `"description="Hector_GCAM_v5.3_ECS_3.0_REF"` in `"slr_from_GCAM.csv"` and `"ECS_3.0_ref_0"` in the [FrEDI::gcamScenarios] dataset)). Also see the documentation for the [FrEDI::gcamScenarios] dataset for more information.
#' * `"State ICLUS Population.csv"` and `"Region ICLUS Population.csv"` contain the default population scenarios used by [FrEDI::run_fredi()] and [FrEDI::run_fredi_sv()], respectively (see [FrEDI::popScenario] and [FrEDI::popScenario_sv]).
#' * `"slr_from_GCAM.csv"` contains global mean sea level rise heights in centimeters (created from the reference temperature scenario).
#' * __extdata/sv__ Contains files used by the `FrEDI` SV module to calculate impacts.
#'
#' The `FrEDI` package contains a loadable dataset with default results `defaultResults`, which contains annual impacts produced by [FrEDI::run_fredi()] for the with the default options and default default scenarios (i.e., default temperature, GDP and regional population trajectories). Other loadable datasets provided by [FrEDI] are a set of driver scenarios ([FrEDI::gcamScenarios]), a state-level population scenario ([FrEDI::popScenario]) for use with [FrEDI::run_fredi()], and a region-level `popScenario_sv` for use with [FrEDI::run_fredi_sv()]. These data can be loaded into the workspace using the `data()` function.
#' The `FrEDI` package contains a loadable dataset with default results `defaultResults`, which contains annual impacts produced by [FrEDI::run_fredi()] for the with the default options and default scenarios (i.e., default temperature, GDP, and state population trajectories). Other loadable datasets provided by FrEDI are a set of driver scenarios ([FrEDI::gcamScenarios]), a state population scenario ([FrEDI::popScenario]) for use with [FrEDI::run_fredi()] or [FrEDI::import_inputs()], and a regional population scenario (`popScenario_sv`) for use with [FrEDI::run_fredi_sv()]. These data can be loaded into the workspace using the `data()` function.
#'
#' Typical use will involve `library(FrEDI)` or `require(FrEDI)`.
#'
#'
#'
#' @section Status:
#' Disclaimer: All code in this repository is being provided in a "draft" state and has not been reviewed or cleared by U.S. EPA. This status will be updated as models are reviewed.
#'
#'
#'
#' @section Dependencies:
#' [FrEDI] requires R (>= 4.2.0).
#' FrEDI requires R (>= 4.2.0).
#'
#'
#' [FrEDI] depends on:
#' FrEDI depends on:
#' * [tidyverse] (Easily Install and Load the 'Tidyverse'). The official documentation for [tidyverse] can be found [here](https://cran.r-project.org/web/packages/tidyverse/index.html). [tidyverse] can be installed using `install.packages("tidyverse")`, or see [link](https://tidyverse.tidyverse.org/) for more information.
#' * [ggpubr] ('ggplot2' Based Publication Ready Plots). The official documentation for [ggpubr] can be found [here](https://cran.r-project.org/web/packages/ggpubr/index.html). [ggpubr] can be installed using `install.packages("ggpubr")`, or see [link](https://rpkgs.datanovia.com/ggpubr/) for more information.
#' * [openxlsx] (Read, Write and Edit `xlsx` Files). The official documentation for [openxlsx] can be found [here](https://cran.r-project.org/web/packages/openxlsx/index.html). [openxlsx] can be installed using `install.packages("openxlsx")`.
#'
#'
#'
#' @section License:
#' This repository is released under the MIT License.
#'
#'
#'
#' @section EPA Disclaimer:
#' The United States Environmental Protection Agency (EPA) GitHub project code is provided on an "as is" basis and the user assumes responsibility for its use. EPA has relinquished control of the information and no longer has responsibility to protect the integrity, confidentiality, or availability of the information. Any reference to specific commercial products, processes, or services by service mark, trademark, manufacturer, or otherwise, does not constitute or imply their endorsement, recommendation or favoring by EPA. The EPA seal and logo shall not be used in any manner to imply endorsement of any commercial product or activity by EPA or the United States Government.
#'
Expand Down
Loading

0 comments on commit f98044d

Please sign in to comment.