Skip to contents

About

The goal of the appc package is to provide daily, high resolution, near real-time, model-based ambient air pollution exposure assessments. This is achieved by training a generalized random forest on several geomarkers to predict daily average EPA AQS concentrations from 2017 until the present at exact locations across the contiguous United States (see vignette("cv-model-performance") for more details). The appc package contains functions for generating geomarker predictors and the ambient air pollution concentrations. Predictor geomarkers include weather and atmospheric information, wildfire smoke plumes, elevation, and satellite-based aerosol diagnostics products. Source files included with the package train and evaluate models that can be updated with any release to use more recent AQS measurements and/or geomarker predictors.

Installing

Install the development version of appc from GitHub with:

# install.packages("remotes")
remotes::install_github("geomarker-io/appc")

Example

In R, create model-based predictions of ambient air pollution concentrations at exact locations on specific dates using the predict_pm25() function:

appc::predict_pm25(
  x = s2::as_s2_cell(c("8841b39a7c46e25f", "8841a45555555555")),
  dates = list(as.Date(c("2024-05-18", "2024-06-10")), as.Date(c("2023-06-22", "2023-08-15")))
)
#> ℹ (down)loading random forest model
#> ✔ (down)loading random forest model [8.6s]
#> 
#> ℹ checking that s2 are within the contiguous US
#> ✔ checking that s2 are within the contiguous US [53ms]
#> 
#> ℹ adding coordinates
#> ✔ adding coordinates [1.9s]
#> 
#> ℹ adding elevation
#> ✔ adding elevation [1.4s]
#> 
#> ℹ adding HMS smoke data
#> ✔ adding HMS smoke data [920ms]
#> 
#> ℹ adding NARR
#> ✔ adding NARR [793ms]
#> 
#> ℹ adding gridMET
#> ✔ adding gridMET [797ms]
#> 
#> ℹ adding MERRA
#> ✔ adding MERRA [1s]
#> 
#> ℹ adding time components
#> ✔ adding time components [20ms]
#> 
#> [[1]]
#> # A tibble: 2 × 2
#>    pm25 pm25_se
#>   <dbl>   <dbl>
#> 1  7.50   0.878
#> 2  5.46   0.592
#> 
#> [[2]]
#> # A tibble: 2 × 2
#>    pm25 pm25_se
#>   <dbl>   <dbl>
#> 1  5.07   0.932
#> 2  6.02   0.493

Installed geomarker data sources and the grf model are hosted as release assets on GitHub and are downloaded locally to the package-specific R user data directory (i.e., tools::R_user_dir("appc", "data")). These files are cached across all of an R user’s sessions and projects. (Specify an alternative download location by setting the R_USER_DATA_DIR environment variable; see ?tools::R_user_dir.)

See more examples in vignette("timeline-example").

S2 Geometry

The S2Geometry library is a hierarchical geospatial index that uses spherical geometry. The appc package uses s2 cells via the s2 package to specify geospatial locations. In R, s2 cells can be created using their character string representation, or by specifying latitude and longitude coordinates; e.g.:

s2::s2_lnglat(c(-84.4126, -84.5036), c(39.1582, 39.2875)) |> s2::as_s2_cell()
#> <s2_cell[2]>
#> [1] 8841ad122d9774a7 88404ebdac3ea7d1

Geomarker Assessment

Spatiotemporal geomarkers are used for predicting air pollution concentrations, but also serve as exposures or confounding exposures themselves. View information and options about each geomarker:

geomarker appc function
🌦 weather & atmospheric conditions get_gridmet_data(), get_narr_data()
🛰 satellite-based aerosol diagnostics get_merra_data()
🔥 wildfire smoke get_hms_smoke_data()
🗻 elevation get_elevation_summary()

Currently, get_urban_imperviousness(), get_traffic(), and get_nei_point_summary() are stashed in the /inst folder and are not integrated into this package.

Developing

Please note that the appc project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

To create and release geomarker data for release assets, as well as to create the AQS training data, train, and evaluate a generalized random forest model, install and use just to execute recipes in the justfile.