Skip to content

Commit

Permalink
Merge pull request #187 from USEPA/enhancement_newFlags
Browse files Browse the repository at this point in the history
Enhancement new flags
  • Loading branch information
emcduffie authored Aug 23, 2024
2 parents 018220e + 83d96f1 commit 2ff36f4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
7 changes: 4 additions & 3 deletions FrEDI/R/run_fredi.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@
#' If the user specifies `aggLevels = "none"`, [FrEDI::run_fredi()] returns a data frame with columns: `"sector"`, `"variant"`, `"impactType"`, `"impactYear"`, `"region"`, `"state"`, `"postal"`, `"model_type"`, `"model"`, `"sectorprimary"`, `"includeaggregate"`, `"physicalmeasure"`, `"driverType"`, `"driverUnit"`, `"driverValue"`, `"gdp_usd"`, `"national_pop"`, `"gdp_percap"`, `"state_pop"`, `"year"`, `"physical_impacts"`, and `"annual_impacts"`.
#'
#'
#' * Columns `"sector"`, `"variant"`, `"impactType"`, `"impactYear"`, `"region"`, `"state"`, `"postal"`, `"model_type"`, and `"model"` all contain observation identifiers (sector name, variant (i.e., sector variant or adaptation name), impact type, impact year, region, state, state postal code abbreviation, model type, and model, respectively).
#' * Column `"sectorprimary"` contains values indicating which variant (i.e., sector variant or adaptation name) is the primary one for the sector (`sectorprimary = 1`for primary variants and `sectorprimary = 0` for non-primary variants). This column can be used to filter the outputs of [FrEDI::run_fredi()] (e.g., as might be done before aggregating impacts over sectors).
#' * Column `"includeaggregate"` contains values indicating which sectors should be included when aggregating over sectors (`includeaggregate = 1`for primary sectors and `includeaggregate = 0` for non-primary sectors). For instance, sectors __ATS Temperature-Related Mortality__, __CIL Temperature-Related Mortality__, and __Extreme Temperature__ have values for temperature-related mortality. To avoid double counting, outputs of [FrEDI::run_fredi()] should be filtered to values for which `sectorprimary = 1` and `includeaggregate = 1`.
#' * Columns `"sector"`, `"variant"`, `"impactType"`, `"impactYear"`, `"region"`, `"state"`, `"postal"`, `"model_type"`, and `"model"` all contain observation identifiers (sector name, variant, impact type, impact year, region, state, state postal code abbreviation, model type, and model, respectively).
#' * Columns `"sectorprimary"` and `"includeaggregate"` contain values that provide information about how to treat sectors and when aggregating over sectors (e.g., summing impacts across sectors). Note that [FrEDI::FrEDI] does not currently provide functionality to aggregate over sectors; this information is provided for user convenience.
#' * Column `"sectorprimary"` contains values indicating which variant to use as the primary one for each sector: `sectorprimary = 1`for primary variants and `sectorprimary = 0` for non-primary variants. When aggregating impacts over sectors, users should filter the outputs of `run_fredi()` to variants with `sectorprimary == 1`.
#' * Column `"includeaggregate"` contains values that provide information about how to treat sectors when aggregating over sectors (e.g., summing impacts across sectors). Sectors that have a value of `includeaggregate == 0` should be dropped when aggregating results over sectors, to avoid potential double-counting of impacts for similar sectors. For instance, sectors __ATS Temperature-Related Mortality__, __CIL Temperature-Related Mortality__, and __Extreme Temperature__ have values for temperature-related mortality. To avoid double counting, outputs of [FrEDI::run_fredi()] should be filtered to values for which `includeaggregate > 0`. Sectors with a value of `includeaggregate > 0` can be included when aggregating over sectors; most sectors with a value of `includeaggregate > 0` will have a value of `includeaggregate = 1`. Values of `includeaggregate > 1` flag additional information about sectors; currently, only the __Suicide__ sector has a value of `includeaggregate > 1`, with a value of `includeaggregate = 2`. This flag indicates that the impacts from __Suicide__ can be included when summing values across sectors, but may have some overlap with impacts from __ATS Temperature-Related Mortality__. For more information about the potential overlap between impacts for __ATS Temperature-Related Mortality__ and __Suicide__, visit the technical documentation at <https://epa.gov/cira/FrEDI/>,
#' * Columns `"driverType"`, `"driverUnit"`, and `"driverValue"` contain information about the temperature and SLR scenarios.
#' * Columns `"gdp_usd"`, `"national_pop"`, `"gdp_percap"`, and `"state_pop"` contain information about the GDP and population scenarios.
#' * Columns `"physicalmeasure"` and `"physical_impacts"` contain information about physical impacts.
Expand Down
Binary file modified FrEDI/R/sysdata.rda
Binary file not shown.
Binary file modified FrEDI/data/defaultResults.rda
Binary file not shown.
13 changes: 8 additions & 5 deletions FrEDI/man/run_fredi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion FrEDI/man/run_fredi_sv.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions FrEDI/testing/utils_create_report_figures.R
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,10 @@ sum_impacts_byDoW <- function(

do_gcm <- "gcm" %in% (models |> tolower())

### Filter to includeaggregate==1
### Filter to includeaggregate>=1
### Filter to sector primary
### Filter to appropriate year
if(aggOnly){df0 <- df0 |> filter(includeaggregate==1)}
if(aggOnly){df0 <- df0 |> filter(includeaggregate>=1)}
if(primary){df0 <- df0 |> filter(sectorprimary ==1)}
if(do_gcm ){df0 <- df0 |> filter(year == year0)}

Expand Down Expand Up @@ -497,9 +497,9 @@ sum_impacts_byDoW_years <- function(
nYears <- years0 |> length()
primary <- !bySector

### Filter to includeaggregate==1
### Filter to includeaggregate>=1
### Filter to sector primary
if(aggOnly){df0 <- df0 |> filter(includeaggregate==1)}
if(aggOnly){df0 <- df0 |> filter(includeaggregate>=1)}
if(primary){df0 <- df0 |> filter(sectorprimary ==1)}

### Run scenarios
Expand Down Expand Up @@ -722,7 +722,7 @@ get_fig7_slrImpacts <- function(
sumCol = "annual_impacts",
# groupVars = c("variant", "impactType", "impactYear"),
impactYears = c("Interpolation", "NA", "2010", "2090"),
aggOnly = TRUE, ### Whether to filter to includeaggregate==1
aggOnly = TRUE, ### Whether to filter to includeaggregate>=1
years = c(2050, 2090),
adjVal = 1/10**9, ### Factor to multiply by
adjCol = "impact_billions"
Expand All @@ -739,10 +739,10 @@ get_fig7_slrImpacts <- function(
modelHeights <- modelLabels |> map(function(.x){str_split(string=.x, pattern="\\s")[[1]][1]}) |> unlist() |> as.numeric()

###### Format data ######
### Filter to includeaggregate==1
### Filter to includeaggregate>=1
### Filter to primary==1
### Filter to appropriate categories and years
if(aggOnly){slrImpacts <- slrImpacts |> filter(includeaggregate==1)}
if(aggOnly){slrImpacts <- slrImpacts |> filter(includeaggregate>=1)}
if(aggOnly){slrImpacts <- slrImpacts |> filter(sectorprimary==1)}
if(!bySector){slrImpacts <- slrImpacts |> filter(year %in% years)}

Expand Down Expand Up @@ -1145,7 +1145,7 @@ create_default_tablePlot <- function(x=1){
### Filter to values used to report
results0 <- results0 |>
filter(model %in% c("Interpolation", "Average")) |>
filter(includeaggregate == 1) |>
filter(includeaggregate >= 1) |>
filter(sectorprimary == 1) |>
filter(region == "National Total")
results0 |> glimpse()
Expand Down

0 comments on commit 2ff36f4

Please sign in to comment.