Skip to contents

Accessing the API endpoint v<version>/station, see https://dataset.api.hub.geosphere.at/v1/docs/getting-started.html.

Usage

gs_stationdata(
  mode,
  resource_id,
  parameters = NULL,
  start = NULL,
  end = NULL,
  station_ids,
  expert = FALSE,
  version = 1L,
  drop = TRUE,
  verbose = FALSE,
  format = NULL,
  limit = 2e+05,
  config = list()
)

Arguments

mode

character, specify mode of data.

resource_id

character, specify resource identifier of data.

parameters

character vector to define which parameters to process.

start, end

object of class Date, POSIXt, or character. In case of character in a non-ISO format format can be used (see below). Not needed (ignored) when mode = "current".

station_ids

integer vector with the station IDs to be processed.

expert

logical, defaults to FALSE. If TRUE the script will not check if the input arguments are valid. May result in unsuccessful requests but increases the speed as gs_datasets() and gs_metadata() do not have to be called (two API requests less).

version

integer, API version (defaults to 1L).

drop

logical, if TRUE parameters and times with no data are removed before returning the data.

verbose

logical, if set TRUE some more output will be produced.

format

NULL (default) or character string, used if start/end are characters in a specific (non ISO) format.

limit

integer, API data request limit. If the request sent by the user exceeds this limit, the request will be split into batches automatically. Set to 2e5 as the limit stated on the API documentation (1e6) will not be accepted.

config

empty list by default; can be a named list to be fowrarded to the httr::GET request if needed.

Value

If only data for one single station (length(station_ids) == 1) is requested, a zoo object will be returned if data is available. If no data is available, NULL will be returned.

When multiple stations are requested a list of zoo object (or NULL if no data is available) is returned. The name of the list corresponds to the station id requested.

Details

This function is a convenience function for downloading different sets of station data from the GeoSphere Austria data hub (formerly ZAMG). The API may change and additional resources may be added, for details see https://dataset.api.hub.geosphere.at/v1/docs/user-guide/endpoints.html.

To see what's available call gs_datasets("station").

The API has a limit for the number of elements for one request. The calculation is based on the number of expecte elements (i.e., number of stations times number of parameters times number of time steps). This function will pre-calculate the number of expected elements and split the request into batches along the time dimension - if needed.

Author

Reto Stauffer

Examples

######################################################################
## Latest observations for two tawes stations in Innsbruck.
## Parameters TL (air temperature 2m above ground), TS (air temperature 5cm
## above ground) and RR (amount of rain past 10 minutes).
innsbruck <- gs_stationdata(mode        = "current",
                            resource_id = "tawes-v1-10min",
                            parameters  = c("TL", "TS", "RR"),
                            station_ids = c(11121, 11320),
                            expert      = TRUE)
# Air temp
sapply(innsbruck, function(x) x$TL)
#> 11121 11320 
#>   1.5   1.6 
# Precipitation (rain)
sapply(innsbruck, function(x) x$RR)
#> 11121 11320 
#>     0     0 

if (FALSE) { # \dontrun{
######################################################################
## Example for synop data

## Loading meta information
meta <- gs_metadata(mode = "historical", resource_id = "synop-v1-1h")
## For station information check
head(meta$stations)
## For available parameters (for this mode/resource_id) check
head(meta$parameters)

## Getting data over 48 hours for one single station
## Note: If expert = FALSE (default) gs_stationdata()
## will internally call gs_metadata() once more to check
## if the requested station_ids as well as the parameters
## exist for the data set specified (mode/resource_id).
mayrhofen <- gs_stationdata(mode        = "historical",
                            resource_id = "synop-v1-1h",
                            start       = "2020-01-01",
                            end         = "2020-01-03",
                            parameters  = c("T", "Td", "ff"),
                            station_ids = 11330, verbose = TRUE)

library("zoo")
plot(mayrhofen, screen = c(1, 1, 2), col = c(2, 3, 4))

## Getting data over 48 hours for three stations simultanously
## Mayrhofen Tirol, Achenkirch Tirol (no data), and Innsbruck Airport Tirol
x <- gs_stationdata(mode        = "historical",
                    resource_id = "synop-v1-1h",
                    start       = "2020-01-01",
                    end         = "2020-01-03",
                    parameters  = c("T", "Td", "ff"),
                    station_ids = c(11330, 11328, 11120),
                    expert      = TRUE)
plot(x[["11330"]], screen = c(1, 1, 2), col = c(2, 3, 4))
is.null(x[["11328"]])
plot(x[["11120"]], screen = c(1, 1, 2), col = c(2, 3, 4))

######################################################################
## Example for daily climatological records
meta <- gs_metadata("historical", "klima-v1-1d")
achenkirch <- gs_stationdata(mode        = "historical",
                             resource_id = "klima-v1-1d",
                             start       = "2020-06-01",
                             end         = "2022-12-31",
                             parameters  = c("nied", "nied07", "nied19", "sonne"),
                             station_ids = 8807,
                             expert      = TRUE)
head(achenkirch)
plot(achenkirch, type = "h")


######################################################################
## Example for 10min KLIMA data
# meta$parameter contains available parameters,
# meta$stations  available stations
meta <- gs_metadata("historical", "klima-v1-10min")
uibk <-  gs_stationdata(mode        = "historical",
                        resource_id = "klima-v1-10min",
                        start       = "2010-11-01",
                        end         = "2011-02-01",
                        parameters  = c("TL", "FFAM", "FFX"),
                        station_ids = 11803,
                        expert      = TRUE)
plot(uibk,
     screens = c(1, 2, 2),
     col = c(2, 4, 8),
     ylab = c("temperature", "mean wind\nand gusts"))


######################################################################
## Example for 10min TAWES data
## NOTE/WARNING:
##   ! "tawes" is not quality controlled and provides limited
##   ! amount of data. Consider to use the "klima-v1-10min" data set which
##   ! provides long-term historical data for the same stations with the
##   ! same temporal resolution, however, the station IDs and
##   ! parameter names (as well as avilavle parameters) will differ
##   ! (check meta data).
# meta$parameter contains available parameters,
# meta$stations  available stations
meta <- gs_metadata("historical", "tawes-v1-10min")
uibk <- gs_stationdata(mode         = "historical",
                       resource_id  = "tawes-v1-10min",
                       start        = Sys.Date() - 30,
                       end          = Sys.Date(),
                       parameters   = c("TL", "TP", "FFAM", "FFX"),
                       station_ids  = 11320,
                       expert       = TRUE)
plot(uibk,
     screens = c(1, 1, 2, 2),
     col = c(2, 3, 4, 8),
     ylab = c("temperature\nand dewpoint", "mean wind\nand gusts"))


######################################################################
## Example for annual histalp data
gs_metadata("historical", "histalp-v1-1y")
bregenz <- gs_stationdata(mode        = "historical",
                          resource_id = "histalp-v1-1y",
                          start       = "1854-01-01",
                          end         = "2022-01-01",
                          parameters  = c("R01", "T01"),
                          station_ids = 23,
                          expert      = TRUE)
plot(bregenz, col = c(4, 2))
} # }