gibson_smhi_opendata: get SMHI in-situ data

gibson_smhi_opendataR Documentation

get SMHI in-situ data

Description

Download metadata and observations from the database of in-situ observation of the Swedish Meterological and Hydrological Institute (SMHI) by using the SMHI Open Data Meteorological Observations REST API (https://opendata-download-metobs.smhi.se). In particular, this function has been implemented and tested to download hourly data.

The database includes in-situ data measured by the network of sensors located at stations belonging to several different station holders (not only SMHI). One station has a unique owner. It is possible to retrieve both the measurements and the post-processing of the measured values, together with the correspondent quality flags when available. The post-pocessing usually aggregates the measured values in different ways (mean/max/min/...) over different time intervals (hours/days/months/years/...).

A single observed value returned by gibson_smhi_opendata can be univocally identified by the union of several pieces of information, such as (for our purposes): station_key, parameterId, date. The station_key identifies the station. The parameterId specifies the meteorological or climate element and the post-processing action by means of a numerical code (see https://opendata-download-metobs.smhi.se/api/version/1.0.json). The date specifies the observation time or timestamp (time standard is Coordinated Universal Time or UTC). For hourly data, the timestamp specifies the end of the aggregation period, se for example the page https://opendata-download-metobs.smhi.se/api/version/latest/parameter/1/station-set/all/period/latest-hour.json where the fields from and to give the extreme of the time aggregation period. The correspondent downloaded data https://opendata-download-metobs.smhi.se/api/version/latest/parameter/1/station-set/all/period/latest-hour/data.json report the end of the aggregation period as the date.

For convenience, it is possible to request the Weather and Climate Elements also by using their MET Norway's old element codes gibson_frost.

Have a look to smhi_opendata_assembler to find examples on how to post-process gibson_smhi_opendata results in order to obtain the desired output.

Usage

gibson_smhi_opendata(frost_oldElementCodes=NULL,
                     version="1.0",
                     station_set_all=T,
                     latest_hour=T,
                     try.again=1,
                     sleep_sec=5,
                     na.rm=T,
                     url.show=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.

try.again

numeric value specifying the number of request attemps before giving up

sleep_sec

numeric value, number of seconds to wait between two consecutive requests

na.rm

logical, if TRUE remove NAs from the output

url.show

logical, if TRUE the urls are shown to the user

Details

API Response Messages (HTTP_Status_Code Reason) are reported at https://opendata.smhi.se/apidocs/metobs/common.html#httpcodes.

The date is returned as it is downloaded from the API, which is UNIX time in milliseconds from 1970-01-01. For hourly data, the timestamp specifies the end of the aggregation period.

Value

A list with two objects is returned. The objects are: smhi_opendata_data, smhi_opendata_meta.

smhi_opendata_data. Data frame with column names: parameterId, station_key, date, value (observed value), qcode (quality flag), frost_oldElementCodes.

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.

smhi_opendata_meta. Data frame with column names: station_key, lon (longitude), lat (latitude), z (elevation m.a.m.s.l.), owner (station owner).

smhi_open_data has the dimension of the number of observations returned and the link between this structure and the others two is the station_key.

Note

data licence https://opendata.smhi.se/apidocs/metobs/index.html#license

Author(s)

Cristian Lussana

See Also

gibson_frost smhi_opendata_assembler

Examples


# load libraries
library(gibson)
library(jsonlite)
#


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