Create a pat
object for a specific sensor_index
.
This function splits up the requested time range into multi-day intervals (as
required 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.
pat_create(
api_key = NULL,
pas = NULL,
sensor_index = NULL,
startdate = NULL,
enddate = NULL,
timezone = "UTC",
average = 0,
fields = PurpleAir_PAT_QC_FIELDS,
sleep = 0.5,
parallel = FALSE,
baseUrl = "https://api.purpleair.com/v1/sensors",
verbose = TRUE
)
PurpleAir API Read Key. If api_key = NULL
, it
will be obtained using getAPIKey("PurpleAir-read")
.
See MazamaCoreUtils::setAPIKey
.
Previously generated pas object containing sensor_index
.
PurpleAir sensor unique identifier.
Desired start time (ISO 8601) or POSIXct
.
Desired end time (ISO 8601) or POSIXct
.
Olson timezone used to interpret dates.
Temporal averaging in minutes performed by PurpleAir. One of: 0 (raw), 10, 30, 60 (hour), 360, 1440 (day).
Character string with PurpleAir field names for the Get Sensor Data API.
Seconds to sleep between API requests.
Logical specifying whether to attempt simultaneous downloads
using parallel::mcparallel
. (Not available
on Windows.)
Base URL for the PurpleAir API.
Logical controlling the generation of warning and error messages.
A PurpleAir Timeseries pat object.
Parallel processing using parallel = TRUE
is not available on
Windows machines.
[pat_createHourly()]
[pat_createRaw()]
# \donttest{
# 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()
# Create a pat object
pat <-
pat_create(
pas = example_pas_pm25,
sensor_index = "76545",
startdate = "2023-01-01",
enddate = "2023-01-03",
timezone = "UTC"
)
str(pat$meta)
# Run data download in parallel (faster)
pat <-
pat_create(
pas = example_pas_pm25,
sensor_index = "76545",
startdate = "2023-01-01",
enddate = "2023-01-03",
timezone = "UTC",
parallel = TRUE
)
}, silent = FALSE)
#> Warning: cannot open file 'global_vars.R': No such file or directory
#> Error in file(filename, "r", encoding = encoding) :
#> cannot open the connection
# }