Skip to content

Accessing and loading grid data

Joaquin Bedia edited this page Mar 14, 2016 · 6 revisions

In the previous sections of the Wiki (2. Model Data), it has been shown how to access and load model data. In the cases where observation data are also gridded, the way to load this data is the same. In this example the E-OBS gridded dataset will be used, we can access the NetCDF files stored in the OPeNDAP catalog http://opendap.knmi.nl/knmi/thredds/catalog.html through the corresponding NcML file. The NcML and dic files can be downloaded as follows:

download.file("http://meteo.unican.es/work/loadeR/data/OPeNDAP_EOBS/Grid_0.25deg_reg_v12/Grid_0.25deg_reg_v12.ncml", 
              destfile = "mydirectory/eobs.ncml")

download.file("http://meteo.unican.es/work/loadeR/data/OPeNDAP_EOBS/Grid_0.25deg_reg_v12/Grid_0.25deg_reg_v12.dic", 
              destfile = "mydirectory/eobs.dic")

Obtaining an overview of the dataset

Before opening and loading the data, it is advisable to get an overview of the variables stored, time and spatial extent, units, etc. This is done by the dataInventory function (see also section 2.2. Loading remote grid data), which receives as argument the path to the file storing the data (this can be either a NetCDF file or a NcML) and returns a list defining the name, temporal and spatial ranges, and the main attributes of each variable.

dir.eobs <- "mydirectory/eobs.ncml"
di <- dataInventory(dir.eobs)

Each field of the list corresponds to a variable.

names(di)

## [1] "pr"     "tas"    "tasmax" "tasmin" "slp"

For each variable in the dataset (e.g., tas), the following information is given:

str(di$tas)

## List of 4
##  $ Description: chr "mean temperature"
##  $ DataType   : chr "float"
##  $ Units      : chr "Celsius"
##  $ Dimensions :List of 3
##   ..$ time:List of 4
##   .. ..$ Type      : chr "Time"
##   .. ..$ TimeStep  : chr "1.0 days"
##   .. ..$ Units     : chr "days since 1950-01-01 00:00:00Z"
##   .. ..$ Date_range: chr "1950-01-01T00:00:00Z - 2014-12-31T00:00:00Z"
##   ..$ lat :List of 3
##   .. ..$ Type  : chr "Lat"
##   .. ..$ Units : chr "degrees_north"
##   .. ..$ Values: num [1:201] 25.4 25.6 25.9 26.1 26.4 ...
##   ..$ lon :List of 3
##   .. ..$ Type  : chr "Lon"
##   .. ..$ Units : chr "degrees_east"
##   .. ..$ Values: num [1:464] -40.4 -40.1 -39.9 -39.6 -39.4 ...

Loading Gridded data

In the following example we will load temperature for a selected rectangular domain centered on the Iberian Peninsula, considering summer (JJA) for the period 1981-2000. A single variable within a defined spatio-temporal domain is what we call a grid.

example1.grid <- loadGridData(dataset = dir.eobs, 
                              var = "tas", 
                              lonLim = c(-12, 5), 
                              latLim=c(35,45), 
                              season=c(6:8), 
                              years = 1981:2000)

## [2016-02-18 11:04:22] Defining geo-location parameters
## [2016-02-18 11:04:22] Defining time selection parameters
## [2016-02-18 11:04:22] Retrieving data subset ...
## [2016-02-18 11:04:52] Done

The function returns the requested data subset and all the necessary information for the identification of the variable and its temporal and spatial definition:

str(example1.grid)

## List of 4
##  $ Variable:List of 2
##   ..$ varName: chr "tas"
##   ..$ level  : NULL
##   ..- attr(*, "use_dictionary")= logi FALSE
##   ..- attr(*, "description")= chr "mean temperature"
##   ..- attr(*, "units")= chr "Celsius"
##   ..- attr(*, "longname")= chr "tas"
##   ..- attr(*, "daily_agg_cellfun")= chr "none"
##   ..- attr(*, "monthly_agg_cellfun")= chr "none"
##   ..- attr(*, "verification_time")= chr "none"
##  $ Data    : num [1:1840, 1:41, 1:69] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...
##   ..- attr(*, "dimensions")= chr [1:3] "time" "lat" "lon"
##  $ xyCoords:List of 2
##   ..$ x: num [1:69] -11.9 -11.6 -11.4 -11.1 -10.9 ...
##   ..$ y: num [1:41] 35.1 35.4 35.6 35.9 36.1 ...
##   ..- attr(*, "projection")= chr "LatLonProjection"
##  $ Dates   :List of 2
##   ..$ start: chr [1:1840] "1981-06-01 00:00:00 GMT" "1981-06-02 00:00:00 GMT" "1981-06-03 00:00:00 GMT" "1981-06-04 00:00:00 GMT" ...
##   ..$ end  : chr [1:1840] "1981-06-01 00:00:00 GMT" "1981-06-02 00:00:00 GMT" "1981-06-03 00:00:00 GMT" "1981-06-04 00:00:00 GMT" ...
##  - attr(*, "dataset")= chr "/oceano/gmeteo/WORK/WWW/loadeR/data/OPeNDAP_EOBS/Grid_0.25deg_reg_v12/Grid_0.25deg_reg_v12.ncml"

The element Data of the list is a N-dimensional array, where N is the number of dimensions depending on the type of request. In this case the returned array is 3-dimensional, with the dimension names stored as an attribute named "dimensions":

str(example1.grid$Data)

##  num [1:1840, 1:41, 1:69] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...
##  - attr(*, "dimensions")= chr [1:3] "time" "lat" "lon"

The dimensions are always arranged in their canonical order, this is time > lat > lon in this case.

As in the case of the model, aggregation and drawing functions could be applied (see section 2.1. Dataset definition and loading local grid data).

Examples of available gridded observations

E-OBS

The E-OBS dataset (Haylock et al., 2008 and van den Besselaar et al., 2011), developed within the EU-funded project ENSEMBLES, is the current reference daily gridded dataset for Europe. It is defined on two resolutions both in rotated (0.22º and 0.44º) and regular (0.25º and 0.50º) grids. In this example the last version (v12) of the high-resolution regular grid has been used.

WFDEI: WATCH-Forcing-Data-ERA-Interim

WFDEI consists in 3-hourly and daily meteorological variables for the global land surface (Weedon et al., 2011). It is a meteorological forcing dataset covering the period 1979 – 2012 produced using the methodology developed in the EU-funded project WATCH applied to ERA-Interim data. Is is available through the ** User Data Gateway (UDG)** (see section 2.3. Loading data from the User Data Gateway).

Spain_02

Spain02 is a series of high-resolution daily precipitation and (maximum and minimum) temperature gridded datasets developed for peninsular Spain and the Balearic islands. The updated version v4, which is available in the UDG, includes three different resolutions (0.11º, 0.22º and 0.44º in rotated coordinates matching Euro-CORDEX grids) for the period 1971-2007.


<-- Home page of the Wiki

print(sessionInfo())

## R version 3.2.3 (2015-12-10)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 14.04.3 LTS
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8          LC_NUMERIC=C                 
##  [3] LC_TIME=es_ES.UTF-8           LC_COLLATE=en_US.UTF-8       
##  [5] LC_MONETARY=es_ES.UTF-8       LC_MESSAGES=en_US.UTF-8      
##  [7] LC_PAPER=es_ES.UTF-8          LC_NAME=es_ES.UTF-8          
##  [9] LC_ADDRESS=es_ES.UTF-8        LC_TELEPHONE=es_ES.UTF-8     
## [11] LC_MEASUREMENT=es_ES.UTF-8    LC_IDENTIFICATION=es_ES.UTF-8
## 
## attached base packages:
## [1] grid      stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
## [1] fields_8.3-6      maps_3.0.2        spam_1.3-0        loadeR_0.2-0     
## [5] loadeR.java_1.1-0 rJava_0.9-8      
## 
## loaded via a namespace (and not attached):
##  [1] lattice_0.20-31 digest_0.6.8    bitops_1.0-6    formatR_1.2    
##  [5] magrittr_1.5    evaluate_0.7    stringi_0.4-1   sp_1.1-0       
##  [9] akima_0.5-12    rmarkdown_0.6.1 tools_3.2.3     stringr_1.0.0  
## [13] RCurl_1.95-4.7  yaml_2.1.13     abind_1.4-3     htmltools_0.2.6
## [17] knitr_1.10.5