Learn R Programming

⚠️There's a newer version (1.2.117) of this package.Take me there.

PWFSLSmoke R Package

Utilities for Working with Air Quality Monitoring Data

Background

The USFS Pacific Wildland Fire Sciences Lab AirFire team works to model wildland fire emissions and has created the BlueSky Modeling Framework. This system integrates a wide collection of models along a smoke modeling pipeline (fire information, fuel loadings, consumption modeling, emissions modeling, time rate of emissions modeling, plume height estimations, and smoke trajectory and dispersion modeling). The resulting model output has been integrated into many different smoke prediction systems and scientific modeling efforts.

The PWFSLSmoke R package is being developed for PWFSL to help modelers and scientists more easily work with PM2.5 data from monitoring locations across North America.

The package makes it easier to obtain data, perform analyses and generate reports. It includes functionality to:

  • download and easily work with regulatory PM2.5 data from the EPA and AirNow
  • download and quality control raw monitoring data from AIRSIS and WRCC
  • convert between UTC and local timezones
  • apply various algorithms to the data (nowcast, rolling means, aggregation, etc.)
  • provide interactive timeseries and maps through RStudio’s Viewer pane
  • create a variety of publication ready maps and timeseries plots

Installation

This package is designed to be used with R (>= 3.3) and RStudio so make sure you have those installed first.

Users will want to install the devtools package to have access to the latest version of the package from Github.

The following packages should be installed by typing the following at the RStudio console:

# Note that vignettes require knitr and rmarkdown
install.packages('knitr')
install.packages('rmarkdown')
install.packages('MazamaSpatialUtils')
devtools::install_github('mazamascience/PWFSLSmoke', build_vignettes=TRUE)

Any work with spatial data, e.g. assigning countries, states and timezones, will require installation of required spatial datasets. To get these datasets you should type the following at the RStudio console:

library(MazamaSpatialUtils)
dir.create('~/Data/Spatial', recursive=TRUE)
setSpatialDataDir('~/Data/Spatial')
installSpatialData()

Examples

Additional R Notebooks that demonstrate the functionality of the package can be found in the localNotebooks directory on github. These notebooks are not part of the package because they require installation of the MazamaSpatialUtils datasets.

To run them you should:

  • make sure you have the proper spatial data installed in ~/Data/Spatial/
  • make sure you have both the knitr and rmarkdown packages installed
  • download the localNotebooks/ directory
  • open a notebook with RStudio
  • click the "Knit" or "Preview" button in RStudio

This R package was created by Mazama Science and is being funded by the USFS Pacific Wildland Fire Sciences Lab.

Copy Link

Version

Install

install.packages('PWFSLSmoke')

Monthly Downloads

53

Version

1.0.20

License

GPL-3

Maintainer

Jonathan Callahan

Last Published

May 8th, 2018

Functions in PWFSLSmoke (1.0.20)

airsisDump_identifyMonitorType

Identify AIRSIS Dump File Monitor Type
addMazamaMetadata

Add State, Country and Timezone to a Dataframe
rawPlot_timeseries

Create Timeseries Plot from a Raw Dataframe
airsis_createMonitorObject

Obain AIRSIS Data and Create ws_monitor Object
epa_parseData

Parse Data from EPA
airnow_createMonitorObjects

Obain AirNow Data and Create ws_monitor Objects
monitor_isEmpty

Test for an Empty ws_monitor Object
AQI_es

Official Air Quality Index Levels, Names and Colors
Carmel_Valley

Carmel Valley Example Dataset
airnow_createMetaDataframes

Create Dataframes of AirNow Site Location Metadata
addGoogleAddress

Add Address Information to a Dataframe
airsis_identifyMonitorType

Identify AIRSIS Monitor Type
wrcc_createMonitorObject

Obtain WRCC Data and Create ws_monitor Object
addGoogleMetadata

Add Elevation and Address Information to a Dataframe
WRCC

WRCC Monitor Names and Unit IDs
airsis_BAM1020QualityControl

Apply Quality Control to Raw AIRSIS BAM1020 Dataframe
addIcon

Add Icons to a Map or RgoogleMap Plot
airsis_createDataDataframe

Create AIRSIS Data Dataframe
monitor_nowcast

Apply Nowcast Algorithm to ws_monitor Object
addUSGSElevation

Add Elevation Data to a Dataframe
airsisDump_parseData

Parse AIRSIS Dump File Data String
airsis_downloadData

Download Data from AIRSIS
monitorPlot_dailyBarplot

Create Daily Barplot
airnow_loadDaily

Load Recent Processed AirNow Monitoring Data
airnow_load

Load Processed AirNow Monitoring Data
monitor_combine

Combine List of ws_monitor Objects into Single ws_monitor Object
airnow_createDataDataframes

Return Reshaped, Dataframes of AirNow Data
airnow_loadLatest

Load Most Recent Processed AirNow Monitoring Data
AQI

Official Air Quality Index Levels, Names and Colors
logger.error

Python-Style Logging Statements
addAQILines

Add AQI Lines to a Plot
addAQIStackedBar

Create Stacked AQI Bar
logger.info

Python-Style Logging Statements
AIRSIS

AIRSIS Unit Types
logger.setup

Set Up Python-Style Logging
wrcc_load

Load Processed WRCC Monitoring Data
airsis_load

Load Processed AIRSIS Monitoring Data
monitorLeaflet

Leaflet Interactive Map of Monitoring Stations
airsis_EBAMQualityControl

Apply Quality Control to Raw AIRSIS EBAM Tibble
airsis_loadDaily

Load Recent AIRSIS Monitoring Data
logger.debug

Python-Style Logging Statements
airsis_parseData

Parse AIRSIS Data String
addShadedBackground

Add Shaded Background to a Plot
monitor_subsetData

Subset ws_monitor Object 'data' Dataframe
airsis_qualityControl

Apply Quality Control to Raw AIRSIS Dataframe
addAQILegend

Add an AQI Legend to a Map
airsisDump_createMonitorObject

Ingest AIRSIS Dump File and Create ws_monitor Object
esriMap_plotOnStaticMap

Plot a map from a RGB rasterBrick.
distance

Calculate the Distance Between Points
raw_enhance

Process Raw Monitoring Data to Create raw_enhance Object
esriMap_getMap

Download a Spatial Raster Object from ESRI
airnow_downloadHourlyData

Download Hourly Data from AirNow
epa_createDataDataframe

Create EPA Data Dataframe
logLevels

Log Levels
upgradeMeta_v1.0

Upgrade ws_monitor Metadata to Version 1.0
createEmptyMetaDataframe

Create Empty Site Location Metadata Dataframe
initializeMazamaSpatialUtils

Initialize Mazama Spatial Utils
airnow_qualityControl

Apply Quality Control to AirNow Dataframe
airnow_downloadParseData

Download and Aggregate Multiple Hourly Data Files from AirNow
epa_createMetaDataframe

Create Sites Metadata Dataframe
monitorPlot_hourlyBarplot

Create Hourly Barplot
logger.trace

Python-Style Logging Statements
epa_downloadData

Download Data from EPA
logger.fatal

Python-Style Logging Statements
monitor_collapse

Collapse a ws_monitor Object into a ws_monitor Object with a Single Monitor
skill_ROC

ROC Curve
monitorMap_performance

Create Map of Monitor Prediction Performance
addBullseye

Add a Bullseyes to a Map or RgoogleMap Plot
monitorMap

Create Map of Monitoring Stations
addClustering

Add Clustering Information to a Dataframe
monitorPlot_rollingMean

Create Rolling Mean Plot
rawPlot_timeOfDaySpaghetti

Create Time of Day Spaghetti Plot from a Raw Dataframe
monitor_join

Merge Data for Monitors with Shared monitorIDs
monitorPlot_timeOfDaySpaghetti

Create Time of Day Spaghetti Plot
monitor_isMonitor

Test for an correct structure of ws_monitor Object
airsis_createRawDataframe

Obain AIRSIS Data and Create a Raw Tibble
wrcc_loadLatest

Load Recent WRCC Monitoring Data
addShadedNight

Add Nighttime Shading to a Plot
monitor_subsetMeta

Subset ws_monitor Object 'meta' Dataframe
epa_load

Load Processed EPA Monitoring Data
monitorPlot_noData

Create Blank Plot with "No Data" Message
airsis_ESAMQualityControl

Apply Quality Control to Raw AIRSIS E-Sampler Dataframe
monitor_reorder

Reorder a ws_monitor Object
monitor_performance

Calculate Monitor Prediction Performance
wrcc_createRawDataframe

Obtain WRCC Data and Parse into Tibbler
monitor_timeAverage

Calculate Time Averages
monitor_subset

Subset ws_monitor Object
monitor_dailyStatistic

Calculate Daily Statistics
monitor_replaceData

Replace ws_monitor Data with Another Value
monitor_subsetBy

Subset ws_monitor Object with a Filter
wrcc_downloadData

Download Data from WRCC
epa_createMonitorObject

Download and Convert Hourly EPA Air Quality Data
logger.setLevel

Set Console Log Level
rawPlot_windRose

Create Wind Rose Plot from a Raw Dataframe
monitorDygraph

Create Interactive Time Series Plot
wrcc_createDataDataframe

Create WRCC Data Dataframe
airsis_availableUnits

Get Available Unit Identifiers from AIRSIS
airsis_createMetaDataframe

Create AIRSIS Site Location Metadata Dataframe
monitorEsriMap

Create an ESRI Map of ws_monitor Object
wrcc_createMetaDataframe

Create WRCC Site Location Metadata Dataframe
monitorPlot_timeseries

Create Timeseries Plot
skill_ROCPlot

ROC Plot
monitor_rollingMean

Calculate Rolling Means
loadDaily

Load Recent PM2.5 Monitoring Data
logger.warn

Python-Style Logging Statements
wrcc_loadDaily

Load Recent WRCC Monitoring Data
monitor_trim

Trim ws_monitor Time Axis to Remove NA Periods From Beginning and End
monitor_asDataframe

Return Monitor Data in a Single Dataframe
monitor_scaleData

Scale ws_monitor Data
monitor_subsetByDistance

Subset ws_monitor Object by Distance from Target Location
monitor_isolate

Isolate Individual Monitors
loadLatest

Load Recent PM2.5 Monitoring Data
parseDatetime

Parse Datetime Strings
wrcc_ESAMQualityControl

Apply Quality Control to Raw WRCC E-Sampler Tibble
wrcc_qualityControl

Apply Quality Control to Raw WRCC Tibble
rawPlot_pollutionRose

Create Pollution Rose Plot from a Raw Dataframe
wrccDump_createMonitorObject

Ingest WRCC Dump File and Create ws_monitor Object
wrcc_EBAMQualityControl

Apply Quality Control to Raw WRCC EBAM Titbble
wrcc_identifyMonitorType

Identify WRCC Monitor Type
monitor_dailyThreshold

Calculate Daily Counts of Values At or Above a Threshold
monitorGoogleMap

Create a Google Map of ws_monitor Object
raw_getHighlightDates

Return Day Stamps for Values Above a Threshold
monitor_aqi

Calculate hourly NowCast-based AQI values
skill_confusionMatrix

Confusion Matrix Statistics
monitor_distance

Calculate Distances From ws_monitor Monitors to Location of Interest
wrccDump_parseData

Parse WRCC Dump File String
timeInfo

Get Time Related Information
wrccDump_identifyMonitorType

Identify WRCC Dump File Monitor Type
CONUS

CONUS State Codes
AQI_en

Official Air Quality Index Levels, Names and Colors
Northwest_Megafires

Northwest Megafires Example Dataset
addGoogleElevation

Add Elevation Data to a Dataframe
airnow_downloadSites

Download AirNow Site Location Metadata
US_52

US State Codes
addMarker

Add Icons to a Map or RgoogleMap Plot
airsis_loadLatest

Load Recent AIRSIS Monitoring Data
wrcc_parseData

Parse WRCC Data String