Download and parse synoptic data for PurpleAir within the specified region.

The synoptic data provides access to data from many PurpleAir sensors at a moment in time and includes both metadata and recent PM2.5 averages for each sensor.

If show_only is used to request specific sensors, the bounding box information is ignored.

pas_downloadParseRawData(
  api_key = NULL,
  fields = SENSOR_DATA_AVG_PM25_FIELDS,
  location_type = 0,
  read_keys = NULL,
  show_only = NULL,
  modified_since = NULL,
  max_age = 3600 * 24 * 7,
  west = NULL,
  east = NULL,
  south = NULL,
  north = NULL,
  baseUrl = "https://api.purpleair.com/v1/sensors"
)

Arguments

api_key

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

fields

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

location_type

The location_type of the sensors. Possible values are: 0 = Outside, 1 = Inside or NULL = both.

read_keys

Optional comma separated list of sensor read_keys is required for private devices. It is separate to the api_key and each sensor has its own read_key. Submit multiple keys by separating them with a comma (,) character for example: key-one,key-two,key-three.

show_only

Optional comma separated list of sensor_index values. When provided, the results are limited only to the sensors included in this list.

modified_since

The modified_since parameter causes only sensors modified after the provided time stamp to be included in the results. Using the time_stamp value from a previous call (recommended) will limit results to those with new values since the last request. Using a value of 0 will match sensors modified at any time.

max_age

Number of seconds used to filter results to only include sensors modified or updated within the max_age seconds. Using a value of 0 will match all sensors.

west

Longitude of the western edge of the bounding box in which to find sensors.

east

Longitude of the eastern edge of the bounding box in which to find sensors.

south

Latitude of the southern edge of the bounding box in which to find sensors.

north

Latitude of the northern edge of the bounding box in which to find sensors.

baseUrl

Base URL for the PurpleAir API.

Value

Dataframe of synoptic PurpleAir data.

Examples

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

library(AirSensor)

initializeMazamaSpatialUtils()

pas_raw <-
  pas_downloadParseRawData(
    api_key = PURPLE_AIR_API_READ_KEY,
    fields = SENSOR_DATA_AVG_PM25_FIELDS,
    location_type = 0,
    modified_since = NULL,
    max_age = 3600 * 24,
    west = -125,
    east = -117,
    south = 42,
    north = 49
  )

View(pas_raw[1:100,])

}, silent = FALSE)
#> Error in pas_downloadParseRawData(api_key = PURPLE_AIR_API_READ_KEY, fields = SENSOR_DATA_AVG_PM25_FIELDS,  : 
#>   object 'PURPLE_AIR_API_READ_KEY' not found
# }