library(meteospain)
library(ggplot2)
library(ggforce)
library(units)
#> udunits database from /usr/share/xml/udunits/udunits2.xml
library(sf)
#> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.4.0; sf_use_s2() is TRUE
Meteoclimatic is a non-professional (amateur) network of automatic meteorological stations. This network cover all Spain, but does not offer quality testing of the data.
Meteoclimatic API only offers aggregated data for the current day,
so, in this case the resolution
parameter is limited to
“current_day”.
Meteoclimatic API does not accept multiple stations in the same
query. But it has station codes that can access the data from several
stations in the same geographic area (i.e. “ES” for all stations,
“ESCAT” for all stations in Catalunya, “ESCAT08” for all stations in
Barcelona province). So, the stations
is limited at length
one.
api_options <- meteoclimatic_options(stations = 'ESCAT08')
api_options
#> $resolution
#> [1] "current_day"
#>
#> $stations
#> [1] "ESCAT08"
Accessing station metadata for Meteoclimatic is simple:
get_stations_info_from('meteoclimatic', options = api_options)
#> Simple feature collection with 212 features and 3 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1.59 ymin: 41.22 xmax: 2.72 ymax: 42.3
#> Geodetic CRS: WGS 84
#> # A tibble: 212 × 4
#> service station_id station_name geometry
#> * <chr> <chr> <chr> <POINT [°]>
#> 1 meteoclimatic ESCAT0800000008591B Aiguafreda Aj. (… (2.25 41.77)
#> 2 meteoclimatic ESCAT0800000008328F Alella-Mirador (… (2.29 41.49)
#> 3 meteoclimatic ESCAT0800000008358A Arenys de Munt (… (2.54 41.61)
#> 4 meteoclimatic ESCAT0800000008310B Argentona (Barce… (2.39 41.56)
#> 5 meteoclimatic ESCAT0800000008915C Badalona - BCIN … (2.26 41.46)
#> 6 meteoclimatic ESCAT0800000008915A Badalona - Bufal… (2.24 41.46)
#> 7 meteoclimatic ESCAT0800000008912A Badalona - Centr… (2.25 41.45)
#> 8 meteoclimatic ESCAT0800000008911C Badalona - Dalt … (2.26 41.46)
#> 9 meteoclimatic ESCAT0800000008080A Badalona - Llefi… (2.23 41.44)
#> 10 meteoclimatic ESCAT0800000008912B Badalona - Progr… (2.24 41.45)
#> # ℹ 202 more rows
current_day_barcelona <- get_meteo_from('meteoclimatic', options = api_options)
#> ℹ Meteoclimatic is a non-professional network of automatic meteorological
#> stations.
#> No quality check is performed in this data, and errors in measures or
#> coordinates of stations can be present.
#> https://www.meteoclimatic.net/index
current_day_barcelona
#> Simple feature collection with 212 features and 9 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1.59 ymin: 41.22 xmax: 2.72 ymax: 42.3
#> Geodetic CRS: WGS 84
#> # A tibble: 212 × 10
#> timestamp service station_id station_name min_temperature
#> * <dttm> <chr> <chr> <chr> [°C]
#> 1 2024-10-16 13:15:00 meteoclimatic ESCAT08000000… Terrassa - … 18.1
#> 2 2024-10-16 13:15:00 meteoclimatic ESCAT08000000… Vacarisses … 15.8
#> 3 2024-10-16 13:15:00 meteoclimatic ESCAT08000000… Puigllançad… 6.4
#> 4 2024-10-16 13:15:00 meteoclimatic ESCAT08000000… Cadí Est- P… 3.8
#> 5 2024-10-16 13:15:00 meteoclimatic ESCAT08000000… Bagà (refug… 9
#> 6 2024-10-16 13:15:00 meteoclimatic ESCAT08000000… La Pobla de… 13.4
#> 7 2024-10-16 13:16:00 meteoclimatic ESCAT08000000… Vallromanes… 18
#> 8 2024-10-16 13:16:00 meteoclimatic ESCAT08000000… El Prat-Zon… 19.1
#> 9 2024-10-16 13:16:04 meteoclimatic ESCAT08000000… Gavà - Colo… 19.8
#> 10 2024-10-16 13:17:00 meteoclimatic ESCAT08000000… Cussons - S… 12.4
#> # ℹ 202 more rows
#> # ℹ 5 more variables: max_temperature [°C], min_relative_humidity [%],
#> # max_relative_humidity [%], precipitation [L/m^2], geometry <POINT [°]>
Visually:
current_day_barcelona |>
units::drop_units() |>
ggplot() +
geom_sf(aes(colour = max_temperature)) +
scale_colour_viridis_c()
current_day_barcelona |>
ggplot() +
geom_histogram(aes(x = max_relative_humidity))
#> Warning: The `scale_name` argument of `continuous_scale()` is deprecated as of ggplot2
#> 3.5.0.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> Warning: Removed 3 rows containing non-finite outside the scale range
#> (`stat_bin()`).