Skip to content

Commit

Permalink
fix: Ensure that all examples work; added example_pat_epa
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathancallahan committed Oct 30, 2024
1 parent 95ff55b commit 2139ee5
Show file tree
Hide file tree
Showing 118 changed files with 642 additions and 214 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Type: Package
Package: AirSensor2
Version: 0.5.3
Version: 0.5.4
Title: Process and Display Data from Air Quality Sensors
Authors@R: c(
person("Jonathan", "Callahan", email="[email protected]", role=c("aut","cre"))
Expand Down Expand Up @@ -38,7 +38,8 @@ Suggests:
markdown,
testthat (>= 2.1.0),
rmarkdown,
roxygen2
roxygen2,
webshot
Encoding: UTF-8
Language: en-US
LazyData: true
Expand Down
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# AirSensor2 0.5.4

- Updated various examples that referenced `example_pas` with the newer
`example_pas_pm25`.
- Added `example_pat_epa` with fields required to run `pat_applyCorrection()`.
- Fixed the bug in `pat_create()` that generated:
```
Elements `last_modified`, `privacy`, `model`, `hardware`, `firmware_version`, etc. don't exist.
```

# AirSensor2 0.5.3

Updated all Clarity functions to default to `format = "USFS2"` which returns
Expand Down
5 changes: 3 additions & 2 deletions R/AirSensor2.R → R/AirSensor2-package.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#'
#' @docType package
#' @keywords internal
"_PACKAGE"

#' @name AirSensor2
#' @title Air Quality Data Analysis for low-cost Sensors
#' @description
Expand Down
62 changes: 54 additions & 8 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' @encoding UTF-8
#' @title Example raw PurpleAir Synoptic dataset
#' @format A tibble with 39 rows and 18 columns of data.
#' @description The \code{example_pas_raw} dataset provides a quickly loadable
#' @description The \code{example_pas_pm25_raw} dataset provides a quickly loadable
#' version of raw PurpleAir synoptic data for practicing and code examples
#' This dataset contains data for sensors in a box around the Methow Valley
#' in Washington state and was generated on 2024-03-12 by running:
Expand Down Expand Up @@ -48,8 +48,11 @@
#' @encoding UTF-8
#' @title Example enhanced PurpleAir Synoptic dataset
#' @format A tibble with 2287 rows and 33 columns of data.
#' @description The \code{example_pas} dataset provides a quickly loadable
#' version of a \emph{pas} object for practicing and code examples.
#' @description The \code{example_pas_pm25} dataset provides a quickly loadable
#' version of a \emph{pas} object for practicing and code examples. This
#' object contains metadata appropriate for generating \emph{pat} objects
#' with \link{pat_create}.
#'
#' This dataset contains data for sensors in Washington and Oregon
#' and was generated on 2024-03-12 by running:
#'
Expand Down Expand Up @@ -84,8 +87,11 @@
#' @encoding UTF-8
#' @title Example enhanced PurpleAir Synoptic dataset
#' @format A tibble with 122 rows and 22 columns of data.
#' @description The \code{example_pas} dataset provides a quickly loadable
#' version of a \emph{pas} object for practicing and code examples.
#' @description The \code{example_pas_historical} dataset provides a quickly loadable
#' version of a \emph{pas} object for practicing and code examples. This
#' object contains fewer metadata fields than other \code{example_pas_~} objects
#' and is intended for use with \link{pas_lifespanPlot}.
#'
#' This dataset contains data for sensors in Washington and Oregon
#' and was generated on 2024-03-12 by running:
#'
Expand Down Expand Up @@ -119,8 +125,10 @@
#' @encoding UTF-8
#' @title Example enhanced PurpleAir Synoptic dataset
#' @format A tibble with 122 rows and 31 columns of data.
#' @description The \code{example_pas} dataset provides a quickly loadable
#' version of a \emph{pas} object for practicing and code examples.
#' @description The \code{example_pas_metadata} dataset provides a quickly loadable
#' version of a \emph{pas} object for practicing and code examples. This
#' object contains more metadata than other \code{example_pas_~} objects.
#'
#' This dataset contains data for sensors in Washington and Oregon
#' and was generated on 2024-03-12 by running:
#'
Expand Down Expand Up @@ -179,8 +187,46 @@
#' save(example_pat, file = "data/example_pat.rda")
#' #' }
#'
#' @seealso example_pas
#' @seealso example_pas_metadata
#' @source https://www2.purpleair.com
"example_pat"


#' @encoding UTF-8
#' @title Example PurpleAir Timeseries dataset with EPA fields
#' @format A list containing two tibbles named 'meta' and 'data'.
#' @description The \code{example_pat} dataset provides a quickly loadable
#' version of a \emph{pat} object for practicing and code examples. This
#' \emph{pat} object contains the `pm2.5_cf` fields required for the EPA
#' correction algorithm used in \link{pat_applyCorrection}.
#'
#' This dataset contains 24 hours worth of data for a single PurpleAir sensor
#' and was generated on 2024-10-30 by running:
#'
#' \preformatted{
#' library(AirSensor2)
#'
#' source("global_vars.R") # contains PurpleAir_API_READ_KEY
#'
#' example_pat_epa <-
#' pat_create(
#' api_key = PurpleAir_API_READ_KEY,
#' pas = example_pas_metadata,
#' sensor_index = "95189",
#' startdate = "2024-03-01",
#' enddate = "2024-03-03",
#' timezone = "America/Los_Angeles",
#' average = 0,
#' fields = PurpleAir_PAT_EPA_HOURLY_FIELDS
#' )
#'
#' save(example_pat_epa, file = "data/example_pat_epa.rda")
#' #' }
#'
#' @seealso example_pas_metadata
#' @source https://www2.purpleair.com
"example_pat_epa"




4 changes: 3 additions & 1 deletion R/pas_createNew.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@
#' location_type = 0
#' )
#'
#' pas %>% pas_leaflet()
#' if ( interactive() ) {
#' pas %>% pas_leaflet()
#' }
#'
#' }, silent = FALSE)
#' }
Expand Down
6 changes: 0 additions & 6 deletions R/pas_filterNearMonitor.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,5 @@ pas_filterNearMonitor <- function(

if ( FALSE ) {

library(AirMonitor)

pas <- example_pas %>% pas_filter(countyName == "Okanogan")
monitor <- NW_Megafires %>% monitor_filter(countyName == "Okanogan")
radius <- "1 km"


}
6 changes: 3 additions & 3 deletions R/pas_leaflet.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@
#' library(AirSensor2)
#'
#' if ( interactive() ) {
#' pas_leaflet(example_pas, parameter = "pm2.5_60minute")
#' pas_leaflet(example_pas_pm25, parameter = "pm2.5_60minute")
#'
#' pas_leaflet(example_pas, parameter = "temperature")
#' pas_leaflet(example_pas_pm25, parameter = "temperature")
#'
#' pas_leaflet(example_pas, parameter = "humidity")
#' pas_leaflet(example_pas_pm25, parameter = "humidity")
#' }

pas_leaflet <- function(
Expand Down
2 changes: 1 addition & 1 deletion R/pat_applyCorrection.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pat_applyCorrection <- function(
if ( FALSE ) {

api_key = PurpleAir_API_READ_KEY
pas = example_pas
pas = example_pas_pm25
sensor_index = "76545"
startdate = "2023-01-01"
enddate = "2023-01-08"
Expand Down
20 changes: 17 additions & 3 deletions R/pat_create.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#' # Create a pat object
#' pat <-
#' pat_create(
#' pas = example_pas,
#' pas = example_pas_pm25,
#' sensor_index = "76545",
#' startdate = "2023-01-01",
#' enddate = "2023-01-03",
Expand All @@ -76,7 +76,7 @@
#' # Run data download in parallel (faster)
#' pat <-
#' pat_create(
#' pas = example_pas,
#' pas = example_pas_pm25,
#' sensor_index = "76545",
#' startdate = "2023-01-01",
#' enddate = "2023-01-03",
Expand Down Expand Up @@ -338,9 +338,14 @@ pat_create <- function(
"sensorManufacturer"
)

# NOTE: Typically, the following names will not be found in pas_single:
# NOTE: last_modified, model, hardware, firmware_version, firmware_upgrade
available_metaNames <-
intersect(names(pas_single), pat_metaNames)

meta <-
pas_single %>%
dplyr::select(dplyr::all_of(pat_metaNames))
dplyr::select(dplyr::all_of(available_metaNames))

# TODO: This step can be removed when AirMonitor gets upgraded to replace
# TODO: 'zip' with 'postalCode'.
Expand Down Expand Up @@ -382,6 +387,15 @@ if ( FALSE ) {
verbose = TRUE



pas = example_pas_pm25
sensor_index = "76545"
startdate = "2023-01-01"
enddate = "2023-01-03"
timezone = "UTC"



pat <-
pat_create(
api_key = api_key,
Expand Down
6 changes: 3 additions & 3 deletions R/pat_createHourly.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@
#'
#' pat <-
#' pat_createHourly(
#' pas = example_pas,
#' pas = example_pas_pm25,
#' sensor_index = "76545",
#' startdate = "2023-01-01",
#' enddate = "2023-01-08",
#' timezone = "UTC",
#' verbose = TRUE
#' )
#'
#' View(pat$meta[1:100,])
#' View(pat$data[1:100,])
#'
#' }, silent = FALSE)
#' }
Expand Down Expand Up @@ -135,7 +135,7 @@ pat_createHourly <- function(
if ( FALSE ) {

api_key = PurpleAir_API_READ_KEY
pas = example_pas
pas = example_pas_pm25
sensor_index = "76545"
startdate = "2023-01-01"
enddate = "2023-01-09"
Expand Down
6 changes: 3 additions & 3 deletions R/pat_createRaw.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@
#'
#' pat <-
#' pat_createRaw(
#' pas = example_pas,
#' pas = example_pas_pm25,
#' sensor_index = "76545",
#' startdate = "2023-01-01",
#' enddate = "2023-01-03",
#' timezone = "UTC",
#' verbose = TRUE
#' )
#'
#' View(pat$meta[1:100,])
#' View(pat$data[1:100,])
#'
#' }, silent = FALSE)
#' }
Expand Down Expand Up @@ -129,7 +129,7 @@ pat_createRaw <- function(
if ( FALSE ) {

api_key = PurpleAir_API_READ_KEY
pas = example_pas
pas = example_pas_pm25
sensor_index = "76545"
startdate = "2023-01-01"
enddate = "2023-01-03"
Expand Down
2 changes: 1 addition & 1 deletion R/pat_filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#'
#' # Unhealthy values
#' example_pat %>%
#' pat_filter(pm2.5_atm_a > 55.5, pm2.5_atm_b > 55.5) %>%
#' pat_filter(pm2.5_atm_a > 25, pm2.5_atm_b > 25) %>%
#' pat_getData() %>%
#' head()
#'
Expand Down
7 changes: 3 additions & 4 deletions R/pat_toMonitor.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@
#'
#' # AirSensor2 package
#' library(AirSensor2)
#'
#' monitor <-
#' example_pat %>%
#' pat_toMonitor(
#' )
#' example_pat_epa %>%
#' pat_toMonitor()
#'
#' AirMonitor::monitor_timeseriesPlot(monitor, shadedNight = TRUE)
#'
#' }, silent = FALSE)
#' }

Expand Down
Binary file added data/example_pat_epa.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/404.html

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

2 changes: 1 addition & 1 deletion docs/LICENSE-text.html

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

2 changes: 1 addition & 1 deletion docs/articles/AirSensor2.html

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

2 changes: 1 addition & 1 deletion docs/articles/Citations.html

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

2 changes: 1 addition & 1 deletion docs/articles/Developer_Style_Guide.html

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

2 changes: 1 addition & 1 deletion docs/articles/Working_with_PurpleAir_API_Keys.html

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

2 changes: 1 addition & 1 deletion docs/articles/index.html

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

Loading

0 comments on commit 2139ee5

Please sign in to comment.