This package provides data ingestion functions for almost any data stored on the open data platform for environemental sensordata https://opensensemap.org. Its main goals are to provide means for:
Before we look at actual observations, lets get a grasp of the openSenseMap datasets’ structure.
## boxes total: 2407
##
## boxes by exposure:
## indoor mobile outdoor unknown
## 361 107 1919 20
##
## boxes by model:
## custom homeEthernet homeEthernetFeinstaub
## 400 92 51
## homeV2Ethernet homeV2EthernetFeinstaub homeV2Wifi
## 2 5 37
## homeV2WifiFeinstaub homeWifi homeWifiFeinstaub
## 116 202 165
## luftdaten_pms1003_bme280 luftdaten_pms3003_bme280 luftdaten_pms5003_bme280
## 2 2 13
## luftdaten_pms7003_bme280 luftdaten_sds011 luftdaten_sds011_bme280
## 5 69 295
## luftdaten_sds011_bmp180 luftdaten_sds011_dht11 luftdaten_sds011_dht22
## 27 58 866
##
## $last_measurement_within
## 1h 1d 30d 365d never
## 1161 1200 1377 1889 328
##
## oldest box: 2014-05-28 15:36:14 (CALIMERO)
## newest box: 2018-10-20 17:34:50 (Leussow Süd)
##
## sensors per box:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.000 4.000 4.000 4.683 5.000 33.000
This gives a good overview already: As of writing this, there are more than 700 sensor stations, of which ~50% are currently running. Most of them are placed outdoors and have around 5 sensors each. The oldest station is from May 2014, while the latest station was registered a couple of minutes ago.
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.
if (!require('maps')) install.packages('maps')
if (!require('maptools')) install.packages('maptools')
if (!require('rgeos')) install.packages('rgeos')
plot(all_sensors)
It seems we have to reduce our area of interest to Germany.
But what do these sensor stations actually measure? Lets find out. osem_phenomena()
gives us a named list of of the counts of each observed phenomenon for the given set of sensor stations:
## List of 548
## $ Temperatur : int 2192
## $ rel. Luftfeuchte : int 1961
## $ PM10 : int 1729
## $ PM2.5 : int 1726
## $ Luftdruck : int 1131
## $ Beleuchtungsstärke : int 635
## $ UV-Intensität : int 628
## $ Luftfeuchtigkeit : int 99
## $ Temperature : int 69
## $ Humidity : int 54
## $ Helligkeit : int 29
## $ Lautstärke : int 27
## $ UV : int 26
## $ Pressure : int 25
## $ Licht : int 20
## $ Schall : int 20
## $ Luftfeuchte : int 17
## $ PM01 : int 17
## $ Umgebungslautstärke : int 14
## $ Lämpötila : int 13
## $ Signal : int 13
## $ rel. Luftfeuchtigkeit : int 13
## $ Ilmanpaine : int 12
## $ Feinstaub PM10 : int 11
## $ Speed : int 11
## $ temperature : int 11
## $ Feinstaub PM2.5 : int 9
## $ Kosteus : int 8
## $ Temperatur DHT22 : int 8
## $ Valonmäärä : int 8
## $ Niederschlag : int 7
## $ UV-säteily : int 7
## $ Wassertemperatur : int 7
## $ Wind speed : int 7
## $ Windgeschwindigkeit : int 7
## $ humidity : int 7
## $ UV-Strahlung : int 6
## $ Windrichtung : int 6
## $ Battery : int 5
## $ Beleuchtungstärke : int 5
## $ Druck : int 5
## $ Ilmankosteus : int 5
## $ Light : int 5
## $ Regen : int 5
## $ Temp : int 5
## $ UV Index : int 5
## $ Sound : int 4
## $ Temperature 1 : int 4
## $ UV-Index : int 4
## $ UV-Säteily : int 4
## $ lautstärke : int 4
## $ pressure : int 4
## $ rel. Luftfeuchte 1 : int 4
## $ rel. Luftfeuchte DHT22 : int 4
## $ relative Luftfeuchtigkeit : int 4
## $ Air Pressure : int 3
## $ Air pressure : int 3
## $ Batterie : int 3
## $ Batteriespannung : int 3
## $ DS18B20_Probe01 : int 3
## $ DS18B20_Probe02 : int 3
## $ DS18B20_Probe03 : int 3
## $ DS18B20_Probe04 : int 3
## $ DS18B20_Probe05 : int 3
## $ Geschwindigkeit : int 3
## $ Illuminance : int 3
## $ Licht (digital) : int 3
## $ Luftdruck (BME280) : int 3
## $ Noise : int 3
## $ PM 10 : int 3
## $ PM 2.5 : int 3
## $ Radioaktivität : int 3
## $ Relative Humidity : int 3
## $ Temperatur (BME280) : int 3
## $ Temperatur 2 : int 3
## $ Temperatur HDC1008 : int 3
## $ Temperatura : int 3
## $ Temperature 2 : int 3
## $ UV-Licht : int 3
## $ Valoisuus : int 3
## $ WiFi Signal : int 3
## $ Wind Direction : int 3
## $ Wind Gust : int 3
## $ Wind Speed : int 3
## $ Wind direction : int 3
## $ rel. Luftfeuchte 2 : int 3
## $ rel.Luftfeuchtigkeit : int 3
## $ 1 : int 2
## $ 10 : int 2
## $ 2 : int 2
## $ 3 : int 2
## $ 4 : int 2
## $ 5 : int 2
## $ 6 : int 2
## $ 7 : int 2
## $ 8 : int 2
## $ 9 : int 2
## $ Anderer : int 2
## $ Außentemperatur : int 2
## [list output truncated]
Thats quite some noise there, with many phenomena being measured by a single sensor only, or many duplicated phenomena due to slightly different spellings. We should clean that up, but for now let’s just filter out the noise and find those phenomena with high sensor numbers:
## $Temperatur
## [1] 2192
##
## $`rel. Luftfeuchte`
## [1] 1961
##
## $PM10
## [1] 1729
##
## $PM2.5
## [1] 1726
##
## $Luftdruck
## [1] 1131
##
## $Beleuchtungsstärke
## [1] 635
##
## $`UV-Intensität`
## [1] 628
##
## $Luftfeuchtigkeit
## [1] 99
##
## $Temperature
## [1] 69
##
## $Humidity
## [1] 54
##
## $Helligkeit
## [1] 29
##
## $Lautstärke
## [1] 27
##
## $UV
## [1] 26
##
## $Pressure
## [1] 25
Alright, temperature it is! Fine particulate matter (PM2.5) seems to be more interesting to analyze though. 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 measurements:
pm25_sensors = osem_boxes(
exposure = 'outdoor',
date = Sys.time(), # ±4 hours
phenomenon = 'PM2.5'
)
## boxes total: 1014
##
## boxes by exposure:
## outdoor
## 1014
##
## boxes by model:
## custom homeEthernetFeinstaub homeV2EthernetFeinstaub
## 34 35 1
## homeV2WifiFeinstaub homeWifi homeWifiFeinstaub
## 24 4 53
## luftdaten_pms1003_bme280 luftdaten_pms5003_bme280 luftdaten_pms7003_bme280
## 1 7 2
## luftdaten_sds011 luftdaten_sds011_bme280 luftdaten_sds011_bmp180
## 35 193 16
## luftdaten_sds011_dht11 luftdaten_sds011_dht22
## 34 575
##
## $last_measurement_within
## 1h 1d 30d 365d never
## 979 989 1000 1007 6
##
## oldest box: 2016-06-02 12:09:47 (BalkonBox Mindener Str.)
## newest box: 2018-10-20 17:34:50 (Leussow Süd)
##
## sensors per box:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.000 4.000 4.000 4.637 5.000 12.000
Thats still more than 200 measuring stations, we can work with that.
Having analyzed the available data sources, let’s finally get some measurements. We could call osem_measurements(pm25_sensors)
now, however we are focusing on a restricted area of interest, the city of Berlin. Luckily we can get the measurements filtered by a bounding box:
## Linking to GEOS 3.6.1, GDAL 2.2.4, PROJ 4.9.3
## udunits system database from /usr/share/udunits
library(lubridate)
library(dplyr)
# construct a bounding box: 12 kilometers around Berlin
berlin = st_point(c(13.4034, 52.5120)) %>%
st_sfc(crs = 4326) %>%
st_transform(3857) %>% # allow setting a buffer in meters
st_buffer(set_units(12, km)) %>%
st_transform(4326) %>% # the opensensemap expects WGS 84
st_bbox()
pm25 = osem_measurements(
berlin,
phenomenon = 'PM2.5',
from = now() - days(3), # defaults to 2 days
to = now()
)
plot(pm25)
Now we can get started with actual spatiotemporal data analysis. First, lets mask the seemingly uncalibrated sensors:
outliers = filter(pm25, value > 100)$sensorId
bad_sensors = outliers[, drop = T] %>% levels()
pm25 = mutate(pm25, invalid = sensorId %in% bad_sensors)
Then plot the measuring locations, flagging the outliers:
Removing these sensors yields a nicer time series plot:
Further analysis: comparison with LANUV data TODO