loadStationData: Load station data

View source: R/loadStationData.R

loadStationDataR Documentation

Load station data

Description

Load observations data from station datasets in standard ASCII format.

Usage

loadStationData(
  dataset,
  var,
  stationID = NULL,
  lonLim = NULL,
  latLim = NULL,
  season = NULL,
  years = NULL,
  tz = "",
 
    projection = "+proj=longlat +init=epsg:4326 +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0",
  units = NULL,
  level = NULL,
  spatialTolerance = NULL
)

Arguments

dataset

A character string indicating the database to be accessed. This is usually a path to a local file or a URL pointing to a netCDF or NcML file in the case of netCDF and/or gridded datasets. For station data in standard ASCII format, this is the path to the directory the dataset lives in.

var

Variable code (character string). This is the name of the variable according to the R standard naming (see the next argument). For variables with vertical levels, the vertical level is specified next to the variable name followed by the “@” symbol (e.g. var = "z@700" for geopotential heigth at 700 mb isobaric surface pressure level). It is also possible to enter the variable name as originally coded in the dataset to skip data homogenization.

stationID

Optional. A character vector indicating the code names of the stations to be loaded.

lonLim

Vector of length = 2, with minimum and maximum longitude coordinates, in decimal degrees, of the bounding box selected. For single-point queries, a numeric value with the longitude coordinate. If NULL (default), the whole longitudinal range is selected (Note that this may lead to a large output object size).

latLim

Same as lonLim, but for the selection of the latitudinal range.

season

An integer vector specifying the desired season (in months, January = 1 ..., December = 12). Options include one to several (contiguous) months. Default to NULL, indicating a full year selection (same as season = 1:12).

years

Optional vector of years to select. Default (NULL) to all available years. If the requested variable is static (e.g. orography) it will be ignored.

tz

A time zone specification to be used for the conversion of dates, if one is required (i.e., if the time zone of the dataset does not correspond to the system-specific one; see timezones for details). Default to unspecified (i.e. tz = "").

projection

Optional. Coordinate projection that is passed to attribute projection in the output object, providing geo-referencing information for more advanced spatial operations/conversions. Preferable, this should be indicated in the form of CRS character string following the PROJ.4 specifications. Default is set to WGS84 lon-lat coordinates.

units

Optional (but strongly advised when possible). This is a character string indicating the units of the variable. This should be whenever possible compatible with the udunits valid (“parseable”) definitions. See C4R.vocabulary for examples of standard unit string definitions.

level

Optional character of the atmospheric level. This information about the variable will be included in the output grid. Requires knowledge about the dataset.

spatialTolerance

Numeric. The use of this argument is NOT RECOMMENDED. Distance (in grid coordinate units) out of the lonLim and LatLim ranges that is allowed for data retrieving.

Value

a list with the following elements:

  • Variable. Name of the variable

  • Data. A 2-D matrix containing the data. Dates are ordered by rows and Stations by columns, following the order indicated in the Metadata.

  • xyCoords. A 2-D matrix with longitude and latitudes of the stations

  • Dates. A list with the verification time interval of each record in the time series. This is represented by a list with two elements: start and end, representing the lower and upper bounds of the verification period

  • Metadata. A list of variable length depending on the available metadata associated to each observation. If no metadata are provided, at least the station codes (compulsory) are displayed.

Geolocation parameters

Regarding the selection of the spatial domain, it is possible to select the whole spatial domain of the dataset by defining the arguments lonLim=NULL and latLim=NULL. More often, rectangular domains are defined by the minimum and maximum coordinates in longitude and latitude (for instance lonLim=c(-10,10) and latLim=c(35,45) indicates a rectangular window centered in the Iberian Peninsula), and single grid-cell values (for instance lonLim=-3.21 and latLim=41.087 for retrieving the data in the closest grid point to the point coordinate -3.21E, 41.087N. In the last two cases, the function operates by finding the nearest (euclidean distance) grid-points to the coordinates introduced.

In the case of station data (loadStationData), the logic is the same, taking into account that in the case of rectangular domains, all stations falling inside that window will be loaded. For single-point selections, the closest station will be chosen, and a note on-screen will inform about the distance from the selected point to the chosen station.

In case of irregular grids (e.g. the typical RCM rotated pole projections), the regular coordinates are included in the x and y elements of the xyCoords list, while the corresponding geographical coordinates are insode two matrices inside the lon and lat elements.

Note

Unlike gridded datasets, station data do not use a dictionary for variable homogenization. Thus, users must take care of variable units and eventual conversions when necessary.

Author(s)

J. Bedia

References

https://github.com/SantanderMetGroup/loadeR/wiki/Standard-(ASCII)-format-for-station-data

See Also

Other loading: loadCircularGridData(), loadGridData(), makeAggregatedDataset()

Examples

## Not run: 
## This example is further illustrated in the loadeR's wiki at:
## <https://github.com/SantanderMetGroup/loadeR/wiki/Accessing-and-loading-station-data>

# Download the VALUE-ECA-86 dataset (https://rmets.onlinelibrary.wiley.com/doi/10.1002/joc.5462) as a temp file

value <- tempfile(fileext = ".zip")
download.file("www.value-cost.eu/sites/default/files/VALUE_ECA_86_v2.zip", destfile = value)
stationInfo(value)
example <- loadStationData(dataset = value, 
                           var = "tmax", 
                           stationID = c("000234", "003946"), 
                           season = 6:8,
                           years = 1981:2000)

## End(Not run)

SantanderMetGroup/loadeR documentation built on July 4, 2023, 4:29 a.m.