Learn R Programming

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

AirSensor R Package

Process and display PM2.5 data from PurpleAir

Background

The AirSensor R package is being developed to help air quality analysts, scientists and interested members of the public more easily work with air quality data from consumer-grade air quality sensors. Initial focus is on PM2.5 measurements from sensors produced by PurpleAir.

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

  • download and easily work with PM2.5 data from PurpleAir
  • visualize raw "engineering" data from a PurpleAir sensor
  • visualize data quality using built-in analytics and plots
  • aggregate raw data onto an hourly axis
  • create interactive maps and time series plots
  • convert aggregated PurpleAir data into ws_monitor objects appropriate for

use with the PWFSLSmoke package

Institutional Support

The initial development of this package was funded by the South Coast Air Quality Management District with funds from an EPA STAR grant. The following disclaimer applies:

This package was prepared as part of a project funded through a Science to Achieve Results (STAR) grant award (RD83618401) from the U.S. Environmental Protection Agency to the South Coast Air Quality Management District (South Coast AQMD). The opinions, findings, conclusions, and recommendations are those of the author and do not necessarily represent the views of the U.S. EPA or the South Coast AQMD, nor does mention of trade names or commercial products constitute endorsement or recommendation for use. The U.S. EPA, the South Coast AQMD, their officers, employees, contractors, and subcontractors make no warranty, expressed or implied, and assume no legal liability for the information in this package. The U.S. EPA and South Coast AQMD have not approved or disapproved this package, and neither have passed upon the accuracy or adequacy of the information contained herein.

Additional funding was provided by the US Forest Service in support of the Interagency Wildland Fire Air Quality Response Program.

Mazama Science develops and maintains the package as part of its ongoing relationships with federal, state and local air quality agencies.

Installation

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

Until the package is available on CRAN or to get the latest development version, 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('MazamaCoreUtils')
install.packages('MazamaSpatialUtils')
devtools::install_github('MazamaScience/worldmet')   # forked version includes fix
devtools::install_github('MazamaScience/AirSensor')

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()

Copy Link

Version

Install

install.packages('AirSensor')

Monthly Downloads

45

Version

1.0.2

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Jonathan Callahan

Last Published

October 8th, 2020

Functions in AirSensor (1.0.2)

PurpleAirQC_hourly_AB_02

Apply hourly aggregation QC using "AB_O2" algorithm
PurpleAirQC_hourly_AB_03

Apply hourly aggregation QC using "AB_O4" algorithm
multi_ggplot

Display multiple plots on one page
PurpleAirSoH_dailyOtherFit

Daily fit values
PurpleAirSoH_dailyPctValid

Daily valid percentage
PurpleAirSoH_dailyABtTest

Daily t-test
PurpleAirSoH_dailyToIndex_00

Daily state of health index
pas_addAirDistrict

Add an air district to PurpleAir Synoptic Data
.flagOutliers

Flag outliers in vectorized data
PurpleAirSoH_dailyPctDC

Daily DC Signal percentage
ArchiveBaseDir

Base directory for pre-generated data
example_pas

Example Purple Air Synoptic dataset
example_pas_raw

Example raw Purple Air Synoptic dataset
example_pat_failure_B

Example PurpleAir Timeseries dataset exhibiting severe errors
PurpleAirSoH_dailyABFit

Daily linear model fit values
PurpleAirSoH_dailyPctReporting

Daily reporting percentage
pas_enhanceData

Enhance synoptic data from PurpleAir
pas_downloadParseRawData

Download synoptic data from PurpleAir
getArchiveBaseUrl

Get data archive base URL
initializeMazamaSpatialUtils

Initialize MazamaSpatialUtils package
pas_load

Load PurpleAir synoptic data
pas_leaflet

Leaflet interactive map of PurpleAir sensors
pas_getDeviceDeploymentIDs

Return timeseries identifiers from filtered PurpleAir Synoptic objects
pas_getIDs

Return IDs from filtered PurpleAir Synoptic objects
pas_upgrade

Upgrade pa_synoptic object format
.replaceOutliers

Replace outliers with rolling median
example_pat

Example PurpleAir Timeseries dataset
patData_aggregate

Aggregate PurpleAir Timeseries Data
.sample

General table row sampling
example_sensor

Example AirSensor Timeseries dataset
pat_aggregateOutlierCounts

Aggregate data with count of outliers in each bin
pat_aggregate

Aggregate PurpleAir Timeseries Object
pas_filter

General purpose filtering for PurpleAir Synoptic objects
pwfsl_loadLatest

Get PWFSLSmoke monitoring data
pas_addCommunityRegion

Add an air district to PurpleAir Synoptic Data
.plotOutliers

Plot flagged outliers
pas_filterArea

Rectangle area filtering for PurpleAir Synoptic objects
removeArchiveBaseDir

Remove data archive base directory
pas_isPas

Test for correct structure in a pa_synoptic object
pas_getColumn

Return column of data from filtered PurpleAir Synoptic objects
pas_isEmpty

Test for an empty pa_synoptic object
pas_filterNear

Find PurpleAir sensors within radial distance
sensor_filter

Data filtering for AirSensor objects
sensor_filterDate

Date filtering for AirSensor objects
getArchiveBaseDir

Get data archive base directory
example_sensor_scaqmd

Example AirSensor Timeseries dataset
pas_addUniqueIDs

Add Unique Identifiers to PurpleAir Synoptic Data
example_pat_failure_A

Example PurpleAir Timeseries dataset exhibiting moderate errors
pas_createNew

Load latest PurpleAir synoptic data
pas_addSpatialMetadata

Add Spatial Metadata to PurpleAIr Synoptic Data
pat_createAirSensor

Create an Air Sensor object
pat_filterDatetime

Datetime filtering for PurpleAir Timeseries objects
pas_staticMap

Static map of PurpleAir sensors
pat_internalFit

Linear model fitting of channel A and B time series data
pas_palette

Color palettes for PurpleAir
pat_createNew

Load latest PurpleAir time series data
sensor_loadLatest

Load hourly-aggregated PurpleAir data for a week
pas_getLabels

Return labels from filtered PurpleAir Synoptic objects
pat_createPATimeseriesObject

Combine PurpleAir raw dataframes
pat_downloadParseRawData

Download PurpleAir timeseries data
pat_loadLatest

Load PurpleAir time series data for a week
pas_hasSpatial

Test for spatial metadata in pa_synoptic object
pat_dygraph

Interactive time series plot
pat_filterDate

Date filtering for PurpleAir Timeseries objects
pat_filter

General purpose data filtering for PurpleAir Timeseries objects
sensor_loadMonth

Load hourly-aggregated PurpleAir data for a month
pat_isPat

Test for correct structure in a pat object
pat_isEmpty

Test for an empty pat object
removeArchiveBaseUrl

Remove data archive base URL
pat_dailySoHIndexPlot

Daily State of Health metric plot
pat_loadMonth

Load PurpleAir time series data for a month
scatterPlot

Matrix scatter plot variables in a data frame
setArchiveBaseDir

Set data archive base directory
sensor_pollutionRose

Pollution rose plot
pat_monitorComparison

Comparison of Purple Air and federal monitoring data
pat_multiPlot

Display multiple plots on one page
%>%

Pipe operator
pat_externalFit

Linear model fitting of PurpleAir and federal PWFSL time series data
pat_dailySoHIndex_00

State of Health index plot
pat_extractDataFrame

Extract dataframes from pat objects
sensor_isEmpty

Test for an empty sensor object
pat_dailySoH

Daily state of health
pwfsl_load

Get PWFSLSmoke monitoring data
sensor_isSensor

Test for correct structure in a sensor object
pat_trimDate

Trim a PurpleAir Timeseries object to full days
pat_dailySoHPlot

Daily State of Health metric plot
pat_upgrade

Upgrade PurpleAir Timeseries
pat_qc

Apply quality control on PurpleAir Timeseries object
pat_sample

Sample PurpleAir time series data
pat_outliers

Detect and replace time series outliers
pat_scatterPlotMatrix

Draw a matrix of PurpleAir Timeseries data scatter plots
sensor_filterDatetime

Datetime filtering for AirSensor objects
sensor_filterMeta

Metadata filtering for AirSensor objects
sensor_polarPlot

Plot bivariate polar plots with guassian smoothing
sensor_loadYear

Load hourly-aggregated PurpleAir data for a month
sensor_join

Join airsensor objects from different time periods
sensor_load

Load hourly-aggregated PurpleAir data
setArchiveBaseUrl

Set data archive base URL
spatialIsInitialized

Check if MazamaSpatialUtils has been initialized
pat_load

Load PurpleAir time series data for a time period
pat_distinct

Retain only distinct data records in pat$data
sensor_extractDataFrame

Extract dataframes from airsensor objects
timeseriesTbl_multiPlot

Faceted plot of a timeseries tibble
sensor_calendarPlot

Plot time series values in conventional calendar format
pat_join

Join PurpleAir time series data for a single sensor
AirSensor

Data access and analysis functions for PurpleAir sensor data
PurpleAirQC_hourly_AB_01

Apply hourly aggregation QC using "AB_O1" algorithm
ArchiveBaseUrl

Base URL for pre-generated data
PurpleAirQC_hourly_AB_00

Apply hourly aggregation QC using "AB_OO" algorithm