smhi_opendata_assembler | R Documentation |
The data are downloaded by using gibson_smhi_opendata
that is linked to the SMHI Open Data Meteorological Observations REST API (https://opendata-download-metobs.smhi.se).
The output is formatted and presented as a data frame where every row includes all the metadata and the observations for a specific source/timestamp.
The function has been implemented and tested to download hourly data.
smhi_opendata_assembler(frost_oldElementCodes=NULL,
version="1.0",
station_set_all=T,
latest_hour=T,
formatOUT="%Y-%m-%dT%H",
coords=data.frame(x="lon",y="lat",
proj4="+proj=longlat +datum=WGS84",
stringsAsFactors=F),
na.rm=T,
url.show=F,
verbose=F)
frost_oldElementCodes |
character vector with the abbreviations used to define weather and climate elements (before Frost-era). See Details for more information or https://frost.met.no/elementtable. |
version |
character string with the API version https://opendata.smhi.se/apidocs/metobs/version.html |
station_set_all |
logical. If TRUE then the station set is set to ”all” https://opendata.smhi.se/apidocs/metobs/stationSet.html. Note that according to the SMHI documentation station-set set to all is only possible in combination with ”latest hour” as period. |
latest_hour |
logical. If TRUE then the hourly data of the latest hour are downloaded. In fact, there is a predefined query to do that, see the JSON example at https://opendata.smhi.se/apidocs/metobs/data.html. |
formatOUT |
charater string specifying the date-time format of the output timestamps (see |
na.rm |
logical, if TRUE remove NAs from the output |
url.show |
logical, if TRUE the urls are shown to the user |
coords |
data frame specifying the coordinate reference systems (as proj4 strings http://proj4.org/) to include in the output together with the names of the easting and northing coordinate. |
verbose |
logical, if TRUE verbose mode is activated |
frost_oldElementCodes
abbreviations are listed at https://frost.met.no/elementtable. Not all abbreviations have been implemented (see frost_translate_oldElementCodes
).
The coordinate reference systems (CRS) are specified by means of proj4 strings http://proj4.org/. A list of proj4 string can be found at http://spatialreference.org/.
Further details on the coordinate conversion can be found at crs_transform
.
It is possible to specify more than one CRS to be included in the output.
The coordinate transformation is based on functions available through the packages sp
, rgdal
.
The observation timestamp (UTC) mark the end of the aggregation period.
The quality code can be ”either G (green), Y (yellow) or R (red) depending on the quality of the value”, see https://opendata.smhi.se/apidocs/metobs/schemas.html#specific under metObsSampleValueType and metObsIntervalValueType.
A data frame is returned. The number of columns depends on the input parameters. Each row includes all the metadata and observed values for a single sourceId/timestamp.
The column names are: timestamp
(end of the aggregation period), sourceId
(station), easting coordinate
for the 1st CRS, northing coordinate
for the 1st CRS, easting coordinate
for the 2nd CRS, northing coordinate
for the 2nd CRS, ... , z
(elevation a.m.s.l.), variable1
, variable1_qcode
, variable2
, variable2_qcode
, ...
The R-packages sp
and rgdal
are needed for the coordinate conversions. SMHI data licence https://opendata.smhi.se/apidocs/metobs/index.html#license.
Cristian Lussana
gibson_smhi_opendata
crs_transform
# load libraries
library(gibson)
#
res<-smhi_opendata_assembler(frost_oldElementCodes=c("FF","PR","TA","DD","RR_1","FG","UU"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.