pat_createRaw: Create a raw data PurpleAir timeseries dataset.

View source: R/pat_createRaw.R

pat_createRawR Documentation

Create a raw data PurpleAir timeseries dataset.

Description

Create a pat object for a specific sensor_index. This function splits up the requested time range into 2-day intervals (the maximum allowed by the PurpleAir API) and makes repeated calls to pat_downloadParseRawData(). The sleep parameter waits a small amount of time between API requests.

The PurpleAir API will respond with "rate limiting" errors unless sleep is set appropriately. When parallel = TRUE, sleep is ignored.

Usage

pat_createRaw(
  api_key = NULL,
  pas = NULL,
  sensor_index = NULL,
  startdate = NULL,
  enddate = NULL,
  timezone = "UTC",
  fields = PurpleAir_PAT_QC_FIELDS,
  sleep = 0.5,
  parallel = FALSE,
  baseUrl = "https://api.purpleair.com/v1/sensors",
  verbose = TRUE
)

Arguments

api_key

PurpleAir API Read Key. If api_key = NULL, it will be obtained using getAPIKey("PurpleAir-read"). See MazamaCoreUtils::setAPIKey.

pas

Previously generated pas object containing sensor_index.

sensor_index

PurpleAir sensor unique identifier.

startdate

Desired start time (ISO 8601) or POSIXct.

enddate

Desired end time (ISO 8601) or POSIXct.

timezone

Olson timezone used to interpret dates.

fields

Character string with PurpleAir field names for the Get Sensor Data API.

sleep

Seconds to sleep between API requests.

parallel

Logical specifying whether to attempt simultaneous downloads using parallel::mcparallel. (Not available on Windows.)

baseUrl

Base URL for the PurpleAir API.

verbose

Logical controlling the generation of warning and error messages.

Value

A raw PurpleAir Timeseries pat object.

Note

Parallel processing using parallel = TRUE is not available on Windows machines.

References

PurpleAir

PurpleAir API

PurpleAir Terms of service

PurpleAir Data license

PurpleAir Data Attribution

Examples


# Fail gracefully if any resources are not available
try({

# AirSensor2 package
library(AirSensor2)

# Set user's PurpleAir_API_READ_KEY
source('global_vars.R')
setAPIKey("PurpleAir-read", PurpleAir_API_READ_KEY)

# Initialize spatial datasets
initializeMazamaSpatialUtils()

pat <-
  pat_createRaw(
    pas = example_pas_pm25,
    sensor_index = "76545",
    startdate = "2023-01-01",
    enddate = "2023-01-03",
    timezone = "UTC",
    verbose = TRUE
  )

View(pat$data[1:100,])

}, silent = FALSE)


MazamaScience/AirSensor2 documentation built on Oct. 31, 2024, 1:39 a.m.