Skip to content

Creating multi grids

Sixto Herrera García edited this page Feb 19, 2016 · 5 revisions

Creating a multigrid from existing grids

An object formed by two or more variables sharing a common spatial grid and time span is termed a multigrid. The constructor makeMultiField allows creating a multigrid from a collection of grids. The spatial and temporal consistency of the different grids must be checked by the user, which can resort to the interpData and getGrid methods to this aim. Otherwise, the function will stop raising an error.

# Path to the E-OBS dataset
dir.eobs <- "mydirectory/eobs.ncml"
# Definition of a common domain
lon = c(-12, 5)
lat = c(35,45)
# Definition of common time domain
seas = c(12,1,2)
yrs = 1990:1999
# Precipitation
pr <- loadGridData(dataset = dir.eobs, 
                   var = "pr", 
                   lonLim = lon, 
                   latLim = lat, 
                   season = seas, 
                   years = yrs)

## [2016-01-23 20:04:21] Defining homogeneization parameters for variable "pr"
## [2016-01-23 20:04:23] Defining geo-location parameters
## [2016-01-23 20:04:23] Defining time selection parameters
## [2016-01-23 20:04:24] Retrieving data subset ...
## [2016-01-23 20:04:35] Done

# Surface temperature
psl <- loadGridData(dataset = dir.eobs, 
                    var = "slp", 
                    lonLim = lon, 
                    latLim = lat, 
                    season = seas, 
                    years = yrs)

## [2016-01-23 20:04:35] Defining homogeneization parameters for variable "slp"
## [2016-01-23 20:04:37] Defining geo-location parameters
## [2016-01-23 20:04:37] Defining time selection parameters
## [2016-01-23 20:04:38] Retrieving data subset ...
## [2016-01-23 20:04:48] Done

example.mf <- makeMultiField(psl, pr)

Note the behaviour of plotMeanField when a multigrid is given as input:

plotMeanField(example.mf)

The data structure of a multigrid incorporates a new dimension in the Data array, labelled var, along which the different variables composing the multigrid are stacked:

str(example.mf$Data)

##  num [1:2, 1:902, 1:41, 1:69] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...
##  - attr(*, "dimensions")= chr [1:4] "var" "time" "lat" "lon"

<-- 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] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] loadeR_0.0-1      loadeR.java_1.0-0 rJava_0.9-8      
## 
## loaded via a namespace (and not attached):
##  [1] digest_0.6.8    bitops_1.0-6    grid_3.2.3      formatR_1.2    
##  [5] magrittr_1.5    spam_1.3-0      evaluate_0.7    stringi_0.4-1  
##  [9] rmarkdown_0.6.1 tools_3.2.3     stringr_1.0.0   RCurl_1.95-4.7 
## [13] maps_3.0.2      fields_8.3-6    yaml_2.1.13     abind_1.4-3    
## [17] htmltools_0.2.6 knitr_1.10.5