-
Notifications
You must be signed in to change notification settings - Fork 59
Accessing Station Data
The function https://github.com/SantanderMetGroup/downscaleR/blob/master/R/dataInventory.R is intended for a quick overview of the data contained in the dataset. In the case of stations data, the main argument to be provided is the path to the directory where the dataset (stations.txt, variables.txt and associated data) are stored (see https://github.com/SantanderMetGroup/downscaleR/wiki/Observation-Data-format for details on station data format).
For instance, this is a quick overview of the built-in dataset in the downscaleR package using dataInventory:
> di <- dataInventory("inst//datasets//observations//GSN_Iberia") [2014-06-03 09:36:27] Doing inventory ... [2014-06-03 09:36:27] Done.
The object loaded contains all the necessary information in order to make a call to the loading function loadObservations, including station codes, geolocation and details on the variable names, units ... \:
> str(di) List of 3 $ Stations :List of 4 ..$ station_id : chr [1:6] "SP000008027" "SP000008181" "SP000008202" "SP000008215" ... ..$ LonLatCoords : num [1:6, 1:2] -2.04 2.07 -5.5 -4.01 -1.86 ... .. ..- attr(*, "dimnames")=List of 2 .. .. ..$ : chr [1:6] "SP000008027" "SP000008181" "SP000008202" "SP000008215" ... .. .. ..$ : chr [1:2] "lon" "lat" ..$ times :List of 3 .. ..$ startDate: POSIXlt[1:1], format: "1979-01-01" .. ..$ endDate : POSIXlt[1:1], format: "2012-12-31" .. ..$ timeStep :Class 'difftime' atomic [1:1] 24 .. .. .. ..- attr(*, "units")= chr "hours" ..$ other.metadata:List of 4 .. ..$ altitude : int [1:6] 251 4 790 1894 704 90 .. ..$ location : chr [1:6] "SAN SEBASTIAN - IGUELDO" "BARCELONA/AEROPUERTO" "SALAMANCA AEROPUERTO" "NAVACERRADA" ... .. ..$ WMO_Id : int [1:6] 8027 8181 8202 8215 8280 8410 .. ..$ Koppen.class: chr [1:6] "Cfb" "Csa" "BSk" "Csb" ... $ Variables :'data.frame': 3 obs. of 4 variables: ..$ variable : Factor w/ 3 levels "precip","tmax",..: 1 3 2 ..$ longname : Factor w/ 3 levels "maximum daily temperature",..: 3 2 1 ..$ unit : Factor w/ 2 levels "0.1 degC","0.1 mm": 2 1 1 ..$ missing.code: Factor w/ 1 level "NaN": 1 1 1 $ Summary.stats: NULL
Note that the last element of the inventory, named Summary.stats is NULL. Bt default, the inventory will return the basic information, but setting the argument return.stats to TRUE will return also a table summarizing the characteristics of the data (percentage of missing data, mean, min and max values):
> di2 <- dataInventory("inst//datasets//observations//GSN_Iberia", return.stats= TRUE) [2014-06-03 09:51:18] Doing inventory ... [2014-06-03 09:51:19] Done. > di2$Summary.stats $missing.percent precip tmin tmax SP000008027 0.6 2.3 4.2 SP000008181 0.7 1.7 1.1 SP000008202 0.5 4.5 0.8 SP000008215 0.6 2.7 2.3 SP000008280 0.5 17.8 4.1 SP000008410 0.9 10.1 6.0 $min precip tmin tmax SP000008027 -0.3 -10.0 -3.5 SP000008181 0.0 -7.2 0.0 SP000008202 0.0 -12.0 -1.4 SP000008215 0.0 -17.5 -11.0 SP000008280 0.0 -13.4 -1.8 SP000008410 0.0 -8.2 0.0 $max precip tmin tmax SP000008027 93.0 25.2 38.6 SP000008181 175.1 26.8 37.4 SP000008202 50.3 22.0 41.0 SP000008215 111.8 20.6 31.8 SP000008280 146.6 23.4 42.0 SP000008410 154.3 27.0 46.6 $mean precip tmin tmax SP000008027 1.2266499 10.621573 16.58673 SP000008181 1.5895889 11.803554 20.44687 SP000008202 1.0108198 5.791200 18.73546 SP000008215 1.5650255 3.303088 10.94361 SP000008280 0.9700607 7.756689 20.23754 SP000008410 1.5544916 11.311057 24.63882
The function `loadObservations` is the interface to acces observational datasets. There are several ways in which observations data can be queried. The most common cases are next presented.
Given the station codes provided by the inventory, it is possible to retrieve a time series for a selected station or several time series for several stations directly by the identification codes. This will load summer temperature data (JJA) for the period 1981-2000 for two stations: Albacete - Los Llanos and Cordoba - Aeropuerto:
downscaleR - Santander MetGroup (Univ. Cantabria - CSIC)