USEPA / FrEDI

FrEDI estimates annual physical and economic impacts from climate change to the U.S., through the 21st century
https://usepa.github.io/FrEDI
Other
11 stars 5 forks source link

Pop downscaling #172

Closed knoiva-indecon closed 2 months ago

knoiva-indecon commented 2 months ago

Merging in population downscaling functionality to state level

knoiva-indecon commented 2 months ago

Awesome, thanks for the review! I’ll make those edits later today or tomorrow.


From: Erin McDuffie @.> Sent: Thursday, July 4, 2024 4:27:50 PM To: USEPA/FrEDI @.> Cc: Karen Noiva @.>; Author @.> Subject: Re: [USEPA/FrEDI] Pop downscaling (PR #172)

Note: This email originated outside of IEc. Be cautious with any links or attachments.

@emcduffie requested changes on this pull request.

Looks great, just a few minor suggested text edits!


In FrEDI/R/FrEDI-package.Rhttps://github.com/USEPA/FrEDI/pull/172#discussion_r1666019850:

'

-#' 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), developed as part of EPA's Climate Change Impacts and Risk Analysis (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.

⬇️ Suggested change

-#' 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 (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. +#' FrEDI is an R package that is developed and maintained by the U.S. Environmental Protection Agency (EPA). The functions and data provided in this package can be used to project impacts of climate change within the contiguous United States (CONUS), under any custom temperature or socioeconomic trajectory, using the Framework for Evaluating Damages and Impacts (FrEDI) that was developed as part of EPA's Climate Change Impacts and Risk Analysis (CIRA) project. The FrEDI package contains R code that implements FrEDI and allows users to project annual impacts from climate change and sea level rise across over 20 impact sectors, geographic regions, and populations through the end of the 21st century (and optionally through 2300). While this framework does not currently account for all ways in which the American public may be impacted by future climate change, this type of detailed information helps EPA to better understand and communicate the types of potential impacts and risks from future climate change in the United States, as well as the potential benefits of greenhouse gas mitigation and adaptation. +See the FrEDI Technical Documentation for additional information about the underlying theory, design, structure, components, and capabilities of FrEDI, as well as examples of some of its intended uses and applications.


On FrEDI/R/FrEDI-package.Rhttps://github.com/USEPA/FrEDI/pull/172#discussion_r1666023217:

See suggested edits for the intro section (to better align with the intro of our TD)


On FrEDI/R/data.Rhttps://github.com/USEPA/FrEDI/pull/172#discussion_r1666025433:

At line 57, change to: Population scenario to use as an input to [FrEDI::run_fredi()] and [FrEDI::run_fredi_sv()]

Line 33 and 35: The 6 GCAM scenarios can be used as drivers from both run_fredi() and run_fredi_sv(), right? If so, please update to clarify. Do we also need to specify where the default GDP scenarios are from? Or is this documented elsewhere?


In FrEDI/R/import_inputs.Rhttps://github.com/USEPA/FrEDI/pull/172#discussion_r1666030362:

'

+#' Temperature Scenario. The file specified by tempfile must have two columns -- "year" and "temp_C" -- respectively containing the years associated with the temperature estimates and the temperatures (i.e., degrees of warming) in degrees Celsius relative to a baseline year of 1995 (i.e., the central year of a 1986-2005 reference period). +#' If expressed as CONUS temperatures, values in the "temp_C" column must be greater than or equal to zero degrees Celsius. +#' If values in "temp_C" have global rather than CONUS-specific temperatures, users should specify temptype = "global" when running import_inputs(), and import_inputs() will convert the temperatures to CONUS using [FrEDI::convertTemps] (with argument from = "global"). +#' Temperature inputs to [FrEDI::run_fredi()] must have at least one non-missing value in 2000 or earlier and at least one non-missing value in or after the final analysis year (as specified by the [FrEDI::run_fredi()] maxYear argument). +#' SLR Scenario. The file specified by slrfile must have two columns -- "year" and "slr_cm" -- respectively containing the years associated with the GMSL estimates and GMSL estimates, in centimeters, above a 2000 baseline year. +#' GMSL heights must be greater than or equal to zero. +#' The SLR scenario must have at least one non-missing value in 2000 or earlier and at least one non-missing value in or after the final analysis year (as specified by the [FrEDI::run_fredi()] maxYear argument). +#' GDP Scenario. The file specified by gdpfile must have two columns -- "year" and "gdp_usd" -- respectively containing the years associated with the GDP estimates and the estimates for U.S. GDP, in 2015$. +#' GDP values must be greater than or equal to zero. +#' The GDP scenario must have at least one non-missing value in 2010 or earlier and at least one non-missing value in or after the final analysis year (as specified by the [FrEDI::run_fredi()] maxYear argument). +#' Population Scenario. The file specified by popfile population must have at least two columns -- "year" and "pop" -- respectively containing the years associated with the population estimates and the population estimates. requires state-level population values. Whether a third column is required depends on the geographical scale of the data, as specified by the popArea argument. +#' If popArea = "state", the third column should be called "state" and contain the name of the state associated with each population estimate in a given year. If popArea = "regional", the third column should be called "region" and contain the NCA Region label associated with each population estimate in a given year. If popArea = "national" or popArea = "area", only the year and pop columns are required.

What does popArea = "area" mean? We have national, regional, and state, but what is 'area'? Can we clarify that here? Can we also clarify whether 'national' includes AK and HI or not. Thanks!


In FrEDI/R/import_inputs.Rhttps://github.com/USEPA/FrEDI/pull/172#discussion_r1666030562:

'

+#' If popArea = "national", [FrEDI::import_inputs()] will use historical U.S. Census data for the period 2010--2023 to allocate total national population to CONUS and non-CONUS regions (i.e., Alaska and Hawaii); U.S. Census values from 2023 are applied in allocations for years after 2023. +#' If popArea = "national" or or popArea = "area", [FrEDI::import_inputs()] uses ICLUS data and projections for the period 2010--2100 to allocate CONUS population to specific NCA regions; ICLUS values from 2100 are applied in allocations for years after 2100.

remove double 'or or'


In FrEDI/R/import_inputs.Rhttps://github.com/USEPA/FrEDI/pull/172#discussion_r1666031698:

@@ -63,17 +79,20 @@

' popInputFile <- scenariosPath |> file.path("State ICLUS Population.csv")

'

' ### Import inputs

-#' example_inputsList <- import_inputs( -#' slrfile = slrInputFile, -#' popfile = popInputFile, -#' temptype = "global" -#' ) +#' example_inputsList <- import_inputs(slrfile=slrInputFile, popfile=popInputFile, popArea="state")

'

' ### Use imports with FREDI:

' df_x <- run_fredi(inputsList=example_inputsList)

'

' @references Environmental Protection Agency (EPA). 2021. Technical Documentation on The Framework for Evaluating Damages and Impacts (FrEDI). Technical Report EPA 430-R-21-004, EPA, Washington, DC. Available at https://epa.gov/cira/FrEDI/.

Update to our latest TD: Environmental Protection Agency (EPA). 2024. Technical Documentation for the Framework for Evaluating Damages and Impacts (FrEDI). U.S. Environmental Protection Agency, EPA 430-R-24-001. www.epa.gov/cira/FrEDIhttp://www.epa.gov/cira/FrEDI


In FrEDI/R/run_fredi.Rhttps://github.com/USEPA/FrEDI/pull/172#discussion_r1666032696:

' Users can specify an optional list of custom scenarios with inputsList (for more information on the format of inputs, see [FrEDI::import_inputs()]). The function [FrEDI::import_inputs()] can be used to importing custom scenarios from CSV files. [FrEDI::import_inputs()] returns a list with elements tempInput, slrInput, gdpInput, and popInput, with each containing a data frame with a custom scenario for temperature, GMSL, GDP, and state-level population, respectively. If a user imports scenarios using [FrEDI::import_inputs()], they can pass the outputs of [FrEDI::import_inputs()] directly to the [FrEDI::run_fredi()] argument inputsList. Note that the documentation for [FrEDI::import_inputs()] can also provide additional guidance and specification on the formats for each scenario type.

'

-#' If inputsList=NULL, [FrEDI::run_fredi()] uses defaults for temperature, SLR, GDP, and population. Otherwise, [FrEDI::run_fredi()] looks for a list object passed to the argument inputsList. Within that list, [FrEDI::run_fredi()] looks for list elements tempInput, slrInput, gdpInput, and popInput containing data frames with custom scenarios for temperature, GMSL, GDP, and regional population, respectively. [FrEDI::run_fredi()] will default back to the default scenarios for any list elements that empty or NULL (in other words, running run_fredi( inputsList = list() ) returns the same outputs as running [FrEDI::run_fredi()]). +#' If inputsList = NULL, [FrEDI::run_fredi()] uses defaults for temperature, SLR, GDP, and population. Otherwise, [FrEDI::run_fredi()] looks for a list object passed to the argument inputsList. Within that list, [FrEDI::run_fredi()] looks for list elements tempInput, slrInput, gdpInput, and popInput containing data frames with custom scenarios for temperature, GMSL, GDP, and regional population, respectively. [FrEDI::run_fredi()] will default back to the default scenarios for any list elements that empty or NULL (in other words, running run_fredi(inputsList = list()) returns the same outputs as running [FrEDI::run_fredi()]).

update 'regional population' to 'state population'


In FrEDI/R/run_fredi_sv.Rhttps://github.com/USEPA/FrEDI/pull/172#discussion_r1666041510:

@@ -2,47 +2,49 @@

' Calculate climate change impacts on socially vulnerable (SV) populations throughout the 21st century for available sectors

'

' @description

-#' run_fredi_sv allows users to project annual average climate change impacts throughout the 21st century (2010-2090) for socially vulnerable (SV) populations for available sectors. Users can run [FrEDI::run_fredi_sv()] for individual sectors to generate annual physical impacts for SV populations. [FrEDI::run_fredi_sv()] can be run with default population and climate (temperature and sea level rise trajectories) or provide custom trajectories. The output of [FrEDI::run_fredi_sv()] is an R data frame object containing annual average physical impacts at five-year increments for the period 2010 to 2090. Users have the option to write outputs to Excel files that provide additional visualization of SV outputs. +#' run_fredi_sv allows users to project annual average climate change impacts throughout the 21st century (2010-2100) for socially vulnerable (SV) populations for available sectors. Users can run [FrEDI::run_fredi_sv()] for individual sectors to generate annual physical impacts for SV populations. [FrEDI::run_fredi_sv()] can be run with default population and climate (temperature and sea level rise trajectories) or provide custom trajectories. The output of [FrEDI::run_fredi_sv()] is an R data frame object containing annual average physical impacts at five-year increments for the period 2010 to 2100. Users have the option to write outputs to Excel files that provide additional visualization of SV outputs.

⬇️ Suggested change

-#' run_fredi_sv allows users to project annual average climate change impacts throughout the 21st century (2010-2100) for socially vulnerable (SV) populations for available sectors. Users can run [FrEDI::run_fredi_sv()] for individual sectors to generate annual physical impacts for SV populations. [FrEDI::run_fredi_sv()] can be run with default population and climate (temperature and sea level rise trajectories) or provide custom trajectories. The output of [FrEDI::run_fredi_sv()] is an R data frame object containing annual average physical impacts at five-year increments for the period 2010 to 2100. Users have the option to write outputs to Excel files that provide additional visualization of SV outputs. +#' run_fredi_sv allows users to project annual average climate change impacts throughout the 21st century (2010-2100) for socially vulnerable (SV) populations for available sectors. Users can run [FrEDI::run_fredi_sv()] for individual sectors to generate annual physical impacts for SV populations. [FrEDI::run_fredi_sv()] can be run with default population and climate (temperature and sea level rise trajectories) or using custom trajectories. The output of [FrEDI::run_fredi_sv()] is an R data frame object containing annual average physical impacts at five-year increments for the period 2010 to 2100. The basic structure, specific methodology, and underlying data supporting FrEDI-SV are derived from EPA’s independently peer-reviewed September 2021 report, Climate Change and Social Vulnerability in the United States: A Focus on Six Impacts


In FrEDI/R/utils_import_inputs.Rhttps://github.com/USEPA/FrEDI/pull/172#discussion_r1666044082:

Return

return(return_list) }

-###### rename_inputs ###### -### Created 2021.02.08. Last updated 2021.02.08

Up to you whether you want to keep these 'Last Updated' dates throughout all the code in the R package. If so, I would recommend going through and updating the relevant dates before merging.


In FrEDI/testing/utils_create_report_figures.Rhttps://github.com/USEPA/FrEDI/pull/172#discussion_r1666046469:

Plot DOW

plot_DoW <- function(

  • df0, ### Data (e.g., output from sum_impactsByDegree)
  • df0, ### Data (e.g., output from sum_impactsByDegree) types0 = c("GCM", "SLR"), ### Model type: GCM or SLR years0 = c(2010, 2090),

plot through 2100?


In FrEDI/testing/utils_create_report_figures.Rhttps://github.com/USEPA/FrEDI/pull/172#discussion_r1666046788:

@@ -906,77 +1024,77 @@ plot_DoW_by_sector <- function( theme = NULL ) ){

  • Values & Conditions

  • years0 <- c(2010, 2090)

plot 2100 results instead of 2090?

— Reply to this email directly, view it on GitHubhttps://github.com/USEPA/FrEDI/pull/172#pullrequestreview-2159430656, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ARMSNE7QWQAFM446LVQST7TZKWV4NAVCNFSM6AAAAABKIMCGSGVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDCNJZGQZTANRVGY. You are receiving this because you authored the thread.Message ID: @.***>

knoiva-indecon commented 2 months ago

@emcduffie : Merge #176 tries to meet your offline request to add some flexibility to input column names:

Added flexibility to column names: Now, if the driver column is not found, the import_inputs helper function will try to string match the input type against column names. If it finds a match:

  • If a temperature input, it will look for matches to strings "conus" and "global". If conus matches, it will use that column and set tempType to "conus". Else if global matches, it will use that column and set tempType to "global". Otherwise, it will use the first matched column.
  • If a population input, it will look for matches to strings "state", "region", "conus", and "global". It will check for a match and use the first associated column, and set popArea accordingly. E.g., if "reg_pop" is present, but "state_pop" isn't, "reg_pop" will be used and the popArea set to "regional".
  • Otherwise, the first matched column will be used as the value column.

The function will then rename the matched column to the expected column. No flexibility enhancements were made for ID columns.