smhi_opendata_assembler: download SMHI in-situ data and format the output

smhi_opendata_assemblerR Documentation

download SMHI in-situ data and format the output

Description

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.

Usage

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) 

Arguments

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 strptime help page)

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

Details

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.

Value

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, ...

Note

The R-packages sp and rgdal are needed for the coordinate conversions. SMHI data licence https://opendata.smhi.se/apidocs/metobs/index.html#license.

Author(s)

Cristian Lussana

See Also

gibson_smhi_opendata crs_transform

Examples


# load libraries
library(gibson)
#
res<-smhi_opendata_assembler(frost_oldElementCodes=c("FF","PR","TA","DD","RR_1","FG","UU"))

metno/gibson documentation built on Feb. 12, 2024, 7:25 a.m.