Package 'fmi2'

Title: Finnish Meteorological Institute open data API R client
Description: R client for the Finnish Meteorological Institute (FMI) open data API. This package supersedes the obsolete fmi package. Client can be used to fetch geospatial over FMI's WFS <https://en.ilmatieteenlaitos.fi/open-data-manual-accessing-data> and converted into geospatial objects in R.
Authors: Joona Lehtomaki [aut, cre], Leo Lahti [aut] , Ilari Scheinin [ctb]
Maintainer: Joona Lehtomaki <[email protected]>
License: MIT + file LICENSE
Version: 0.2.0
Built: 2025-01-30 11:24:18 UTC
Source: https://github.com/rOpenGov/fmi2

Help Index


Describe FMI Variables

Description

Describe FMI observation variable(s).

Usage

describe_variables(x)

Arguments

x

character vector of observation variables to be described.

Details

FMI provides a machine-reabable (XML) description of different observation variables. Use this function to see the specifications of a given variable.

Value

tibble containing the following columns:

variable

Observation variable name

label

Variable (parameter) label used by the FMI

base_phenomenon

Base phenomenon that the variable is characterising

unit

Variabel unit

stat_function

Statistical function used the derive the variable value

agg_period

Aggregation time period

Author(s)

Joona Lehtomäki [email protected]

Examples

## Not run: 
     desc <- describe_variables(c("TG_PT12H_min", "rrday"))
  
## End(Not run)

FMI API

Description

Requests to FMI API.

Usage

fmi_api(request, storedquery_id = NULL, ...)

Arguments

request

character request type of either DescribeStoredQueries or getFeature.

storedquery_id

character id of the stored query id. If request is getFeature, then storedquery_id must be provided and otherwise it's ignored.

...

stored query specific parameters. NOTE: it's up to the high-level functions to check the validity of the parameters.

Details

Make a request to the FMI API. The base url is opendata.fmi.fi/wfs?service=WFS&version=2.0.0 to which other components defined by the arguments are appended.

This is a low-level function intended to be used by other higher level functions in the package.

Note that GET requests are used using httpcache meaning that requests are cached. If you want clear cache, use httpcache::clearCache(). To turn the cache off completely, use httpcache::cacheOff()

Value

fmi_api (S3) object with the following attributes:

content

XML payload.

path

path provided to get the resonse.

response

the original response object.

Author(s)

Joona Lehtomäki [email protected]

Examples

# List stored queries
  fmi_api(request = "DescribeStoredQueries")

Get a table of active FMI observation stations.

Description

Data is retrieved using a FMI API stored query.

Usage

fmi_stations()

Value

a tibble of active observation stations

Author(s)

Joona Lehtomaki [email protected]

See Also

https://en.ilmatieteenlaitos.fi/observation-stations


List and describe all valid parameters for a given stored query.

Description

For valid stored query IDs, see list_queries.

Usage

list_parameters(query_id)

Arguments

query_id

character string query ID.

Value

a tibble describing the valid parameters.

Author(s)

Joona Lehtomäki [email protected]

See Also

list_queries.

Examples

## Not run: 
    list_parameters("fmi::observations::weather::daily::timevaluepair")
  
## End(Not run)

List stored queries available over the FMI API.

Description

Stored queries are identifiers for data sets. The current version on the Open Data WFS service of the Finnish Meteorological Institute uses the stored queries extensively to enable users to select the features, areas and times they require as easily as possible. See the Open data WFS Service for more detailed information about the available stored queries and their request parameters.

Usage

list_queries(all = FALSE)

Arguments

all

logical should all stored queries available through the API be listed(default: FALSE)?

Value

tibble containing the following columns:

query_id

ID of the storied query.

query_desc

Description of the storied query.

no_parameters

Number of parameters.

function_name

Name of the function in fmi2 if wrapped, NA otherwise.

Author(s)

Joona Lehtomäki [email protected]

See Also

https://en.ilmatieteenlaitos.fi/open-data-manual-fmi-wfs-services

Examples

## Not run: 
  # List the stored queres that have been wrapped (i.e. are accessible) by
  # the fmi2 package
  list_queries()
  # List all stored queries available through the API
  list_queries(all = TRUE)

## End(Not run)

Weather observations

Description

Daily weather observations from weather stations.

Usage

obs_weather_daily(starttime, endtime, fmisid = NULL, place = NULL)

Arguments

starttime

character or Date start of the time interval in ISO-format. character will be coerced into a Date object.

endtime

character or Date end of the time interval in ISO-format. character will be coerced into a Date object. data.

fmisid

numeric FMI observation station identifier (see fmi_stations.

place

character location name for which to provide data.

Details

Default set contains daily precipitation rate, mean temperature, snow depth, and minimum and maximum temperature. By default, the data is returned from last 744 hours. At least one location parameter (geoid/place/fmisid/wmo/bbox) has to be given.

The FMI WFS stored query used by this function is ⁠fmi::observations::weather::daily::simple⁠. For more informations, see the FMI documentation page.

Value

sf object in a long (melted) form. Observation variables names are given in variable column. Following variables are returned:

rrday

Precipitation amount

snow

Snow depth

tday

Average air temperature

tmin

Minimum air temperature

tmax

Maximum air temperature

TG_PT12H_min

Ground minimum temperature

Note

For a complete description of the accepted arguments, see list_parameters("fmi::observations::weather::daily::simple").

See Also

https://en.ilmatieteenlaitos.fi/open-data-manual-fmi-wfs-services,

list_parameters


Hourly weather observations from weather stations.

Description

Default set contains hourly air temperature average, maximum and minimum, air relative humidity average, wind speed average, minumum (10 minute average) and maximum (10 minute average), wind direction average, wind gust speed maximum (3 second average), rain accumulated, rain intensity maximum, air pressure average and the most significant weather code. By default, the data is returned from last 24 hours. At least one location parameter (geoid/place/fmisid/wmo/bbox) has to be given.

Usage

obs_weather_hourly(starttime, endtime, fmisid = NULL)

Arguments

starttime

character begin of the time interval in ISO-format.

endtime

character end of time interval in ISO-format. data.

fmisid

numeric FMI observation station identifier (see fmi_stations.

Details

The FMI WFS stored query used by this function is ⁠fmi::observations::weather::hourly::simple⁠. For more informations, see the FMI documentation page.

Value

sf object in a long (melted) form. Observation variables names are given in variable column. Following variables are returned:

rrday

Precipitation amount

snow

Snow depth

tday

Average air temperature

tmin

Minimum air temperature

tmax

Maximum air temperature

TG_PT12H_min

Ground minimum temperature

Note

For a complete description of the accepted arguments, see list_parameters("fmi::observations::weather::hourly::simple").

See Also

https://en.ilmatieteenlaitos.fi/open-data-manual-fmi-wfs-services,

list_parameters


Transform a fmi_api object into a sf object.

Description

FMI API response object's XML (GML) content is temporarily wrtitten on disk and then immediately read back in into a sf object.

Usage

to_sf(api_obj)

Arguments

api_obj

fmi api object

Value

sf object

Note

For internal use, not exported.

Author(s)

Joona Lehtomäki [email protected]

See Also

fmi_api

Examples

## Not run: 
    response <- fmi_api(request = "getFeature",
                        storedquery_id = "fmi::observations::weather::daily::timevaluepair",
                        starttime = "2019-01-01", endtime = "2019-01-04",
                        fmisid = 100946)
    sf_obj <- to_sf(response)
  
## End(Not run)

Check if a provided ID number is a valid FMI SID.

Description

fmisid is a ID numbering system used by the FMI.

Usage

valid_fmisid(fmisid)

Arguments

fmisid

numeric or character ID number.

Value

logical

Author(s)

Joona Lehtomaki [email protected]

See Also

fmi_stations