@ -94,7 +94,7 @@ get_stats_ = function (endpoint, cache) {
#' @param cache Optional path to a directory were responses will be cached. If not NA, no requests will be made when a request for the given is already cached.
#' @param cache Optional path to a directory were responses will be cached. If not NA, no requests will be made when a request for the given is already cached.
#' @return Result of a Request to openSenseMap API
#' @return Result of a Request to openSenseMap API
@ -28,7 +28,7 @@ Its main goals are to provide means for:
Before we look at actual observations, lets get a grasp of the openSenseMap
Before we look at actual observations, lets get a grasp of the openSenseMap
datasets' structure.
datasets' structure.
```{r results = F}
```{r results = FALSE}
library(magrittr)
library(magrittr)
library(opensensmapr)
library(opensensmapr)
@ -48,7 +48,7 @@ couple of minutes ago.
Another feature of interest is the spatial distribution of the boxes: `plot()`
Another feature of interest is the spatial distribution of the boxes: `plot()`
can help us out here. This function requires a bunch of optional dependencies though.
can help us out here. This function requires a bunch of optional dependencies though.
```{r, message=F, warning=F}
```{r, message=FALSE, warning=FALSE}
if (!require('maps')) install.packages('maps')
if (!require('maps')) install.packages('maps')
if (!require('maptools')) install.packages('maptools')
if (!require('maptools')) install.packages('maptools')
if (!require('rgeos')) install.packages('rgeos')
if (!require('rgeos')) install.packages('rgeos')
@ -82,7 +82,7 @@ We should check how many sensor stations provide useful data: We want only those
boxes with a PM2.5 sensor, that are placed outdoors and are currently submitting
boxes with a PM2.5 sensor, that are placed outdoors and are currently submitting
measurements:
measurements:
```{r results = F, eval=FALSE}
```{r results = FALSE, eval=FALSE}
pm25_sensors = osem_boxes(
pm25_sensors = osem_boxes(
exposure = 'outdoor',
exposure = 'outdoor',
date = Sys.time(), # ±4 hours
date = Sys.time(), # ±4 hours
@ -104,7 +104,7 @@ We could call `osem_measurements(pm25_sensors)` now, however we are focusing on
a restricted area of interest, the city of Berlin.
a restricted area of interest, the city of Berlin.
Luckily we can get the measurements filtered by a bounding box:
Luckily we can get the measurements filtered by a bounding box:
```{r, results=F, message=F}
```{r, results=FALSE, message=FALSE}
library(sf)
library(sf)
library(units)
library(units)
library(lubridate)
library(lubridate)
@ -113,7 +113,7 @@ library(dplyr)
```
```
Since the API takes quite long to response measurements, especially filtered on space and time, we do not run the following chunks for publication of the package on CRAN.
Since the API takes quite long to response measurements, especially filtered on space and time, we do not run the following chunks for publication of the package on CRAN.
```{r bbox, results = F, eval=FALSE}
```{r bbox, results = FALSE, eval=FALSE}
# construct a bounding box: 12 kilometers around Berlin
# construct a bounding box: 12 kilometers around Berlin
berlin = st_point(c(13.4034, 52.5120)) %>%
berlin = st_point(c(13.4034, 52.5120)) %>%
st_sfc(crs = 4326) %>%
st_sfc(crs = 4326) %>%
@ -138,9 +138,9 @@ plot(pm25)
Now we can get started with actual spatiotemporal data analysis.
Now we can get started with actual spatiotemporal data analysis.
First, lets mask the seemingly uncalibrated sensors:
First, lets mask the seemingly uncalibrated sensors:
```{r, warning=F}
```{r, warning=FALSE}
outliers = filter(pm25, value > 100)$sensorId
outliers = filter(pm25, value > 100)$sensorId
bad_sensors = outliers[, drop = T] %>% levels()
bad_sensors = outliers[, drop = TRUE] %>% levels()