mirror of
https://github.com/sensebox/opensensmapr
synced 2025-07-04 14:30:22 +02:00
Compare commits
No commits in common. "0e1d9e3cad6eb3c10793bf16bfdfbf07ac61263b" and "eec6f84806d6c8c56077fedf004ec6ba10cb5fda" have entirely different histories.
0e1d9e3cad
...
eec6f84806
10 changed files with 17 additions and 29 deletions
1
NEWS.md
1
NEWS.md
|
@ -8,7 +8,6 @@ This project does its best to adhere to semantic versioning.
|
||||||
- updated tests
|
- updated tests
|
||||||
- updated maintainer
|
- updated maintainer
|
||||||
- updated vignettes
|
- updated vignettes
|
||||||
- use precomputed data to create vignettes
|
|
||||||
- new features:
|
- new features:
|
||||||
- added param bbox for osem_boxes function
|
- added param bbox for osem_boxes function
|
||||||
- support of multiple grouptags
|
- support of multiple grouptags
|
||||||
|
|
|
@ -72,7 +72,7 @@ osem_measurements.default = function (x, ...) {
|
||||||
#' @describeIn osem_measurements Get measurements by a spatial filter.
|
#' @describeIn osem_measurements Get measurements by a spatial filter.
|
||||||
#' @export
|
#' @export
|
||||||
#' @examples
|
#' @examples
|
||||||
#' \dontrun{
|
#' \donttest{
|
||||||
#' # get measurements from sensors within a custom WGS84 bounding box
|
#' # get measurements from sensors within a custom WGS84 bounding box
|
||||||
#' bbox = structure(c(7, 51, 8, 52), class = 'bbox')
|
#' bbox = structure(c(7, 51, 8, 52), class = 'bbox')
|
||||||
#' m = osem_measurements(bbox, 'Temperatur')
|
#' m = osem_measurements(bbox, 'Temperatur')
|
||||||
|
|
|
@ -107,7 +107,7 @@ a bounding box spanning the whole world.
|
||||||
'height'
|
'height'
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
\dontrun{
|
\donttest{
|
||||||
# get measurements from sensors within a custom WGS84 bounding box
|
# get measurements from sensors within a custom WGS84 bounding box
|
||||||
bbox = structure(c(7, 51, 8, 52), class = 'bbox')
|
bbox = structure(c(7, 51, 8, 52), class = 'bbox')
|
||||||
m = osem_measurements(bbox, 'Temperatur')
|
m = osem_measurements(bbox, 'Temperatur')
|
||||||
|
|
Binary file not shown.
|
@ -43,10 +43,7 @@ So the first step is to retrieve *all the boxes*:
|
||||||
```{r download}
|
```{r download}
|
||||||
# if you want to see results for a specific subset of boxes,
|
# if you want to see results for a specific subset of boxes,
|
||||||
# just specify a filter such as grouptag='ifgi' here
|
# just specify a filter such as grouptag='ifgi' here
|
||||||
|
boxes = osem_boxes(cache = '.')
|
||||||
# boxes = osem_boxes(cache = '.')
|
|
||||||
boxes = readRDS('boxes_precomputed.rds') # read precomputed file to save resources
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
# Plot count of boxes by time {.tabset}
|
# Plot count of boxes by time {.tabset}
|
||||||
|
|
|
@ -45,9 +45,8 @@ So the first step is to retrieve *all the boxes*.
|
||||||
```{r download, results='hide', message=FALSE, warning=FALSE}
|
```{r download, results='hide', message=FALSE, warning=FALSE}
|
||||||
# if you want to see results for a specific subset of boxes,
|
# if you want to see results for a specific subset of boxes,
|
||||||
# just specify a filter such as grouptag='ifgi' here
|
# just specify a filter such as grouptag='ifgi' here
|
||||||
|
boxes_all = osem_boxes(cache = '.')
|
||||||
# boxes = osem_boxes(cache = '.')
|
boxes = boxes_all
|
||||||
boxes = readRDS('boxes_precomputed.rds') # read precomputed file to save resources
|
|
||||||
```
|
```
|
||||||
# Introduction
|
# Introduction
|
||||||
In the following we just want to have a look at the boxes created in 2022, so we filter for them.
|
In the following we just want to have a look at the boxes created in 2022, so we filter for them.
|
||||||
|
@ -66,7 +65,7 @@ summary(boxes) -> summary.data.frame
|
||||||
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=F, warning=F}
|
||||||
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')
|
||||||
|
|
|
@ -32,8 +32,7 @@ datasets' structure.
|
||||||
library(magrittr)
|
library(magrittr)
|
||||||
library(opensensmapr)
|
library(opensensmapr)
|
||||||
|
|
||||||
# all_sensors = osem_boxes(cache = '.')
|
all_sensors = osem_boxes(cache = '.')
|
||||||
all_sensors = readRDS('boxes_precomputed.rds') # read precomputed file to save resources
|
|
||||||
```
|
```
|
||||||
```{r}
|
```{r}
|
||||||
summary(all_sensors)
|
summary(all_sensors)
|
||||||
|
@ -48,7 +47,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=F, warning=F}
|
||||||
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 +81,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 = F}
|
||||||
pm25_sensors = osem_boxes(
|
pm25_sensors = osem_boxes(
|
||||||
exposure = 'outdoor',
|
exposure = 'outdoor',
|
||||||
date = Sys.time(), # ±4 hours
|
date = Sys.time(), # ±4 hours
|
||||||
|
@ -90,8 +89,6 @@ pm25_sensors = osem_boxes(
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
```{r}
|
```{r}
|
||||||
pm25_sensors = readRDS('pm25_sensors.rds') # read precomputed file to save resources
|
|
||||||
|
|
||||||
summary(pm25_sensors)
|
summary(pm25_sensors)
|
||||||
plot(pm25_sensors)
|
plot(pm25_sensors)
|
||||||
```
|
```
|
||||||
|
@ -104,16 +101,12 @@ 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. eval = FALSE}
|
||||||
library(sf)
|
library(sf)
|
||||||
library(units)
|
library(units)
|
||||||
library(lubridate)
|
library(lubridate)
|
||||||
library(dplyr)
|
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.
|
|
||||||
```{r bbox, results = F, 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) %>%
|
||||||
|
@ -121,6 +114,10 @@ berlin = st_point(c(13.4034, 52.5120)) %>%
|
||||||
st_buffer(set_units(12, km)) %>%
|
st_buffer(set_units(12, km)) %>%
|
||||||
st_transform(4326) %>% # the opensensemap expects WGS 84
|
st_transform(4326) %>% # the opensensemap expects WGS 84
|
||||||
st_bbox()
|
st_bbox()
|
||||||
|
```
|
||||||
|
|
||||||
|
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 results = F, eval=FALSE}
|
||||||
pm25 = osem_measurements(
|
pm25 = osem_measurements(
|
||||||
berlin,
|
berlin,
|
||||||
phenomenon = 'PM2.5',
|
phenomenon = 'PM2.5',
|
||||||
|
@ -128,17 +125,13 @@ pm25 = osem_measurements(
|
||||||
to = now()
|
to = now()
|
||||||
)
|
)
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
```{r}
|
|
||||||
pm25 = readRDS('pm25_berlin.rds') # read precomputed file to save resources
|
|
||||||
plot(pm25)
|
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, eval=FALSE}
|
||||||
outliers = filter(pm25, value > 100)$sensorId
|
outliers = filter(pm25, value > 100)$sensorId
|
||||||
bad_sensors = outliers[, drop = T] %>% levels()
|
bad_sensors = outliers[, drop = T] %>% levels()
|
||||||
|
|
||||||
|
@ -147,13 +140,13 @@ pm25 = mutate(pm25, invalid = sensorId %in% bad_sensors)
|
||||||
|
|
||||||
Then plot the measuring locations, flagging the outliers:
|
Then plot the measuring locations, flagging the outliers:
|
||||||
|
|
||||||
```{r}
|
```{r, eval=FALSE}
|
||||||
st_as_sf(pm25) %>% st_geometry() %>% plot(col = factor(pm25$invalid), axes = T)
|
st_as_sf(pm25) %>% st_geometry() %>% plot(col = factor(pm25$invalid), axes = T)
|
||||||
```
|
```
|
||||||
|
|
||||||
Removing these sensors yields a nicer time series plot:
|
Removing these sensors yields a nicer time series plot:
|
||||||
|
|
||||||
```{r}
|
```{r, eval=FALSE}
|
||||||
pm25 %>% filter(invalid == FALSE) %>% plot()
|
pm25 %>% filter(invalid == FALSE) %>% plot()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
BIN
vignettes/osemcache.c54710f66b662e29dd86b089962b0f598e47eddb.rds
Normal file
BIN
vignettes/osemcache.c54710f66b662e29dd86b089962b0f598e47eddb.rds
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Reference in a new issue