Skip to content

Creating multi grids

miturbide edited this page Feb 18, 2016 · 5 revisions

#Creating a multifield from existing fields

An object formed by two or more variables sharing a common grid and time span is termed a multifield. The constructor makeMultiField allows creating a multifield from a collection of fields. The spatial and temporal consistency of the different fields must be checked by the user, which can resort to the interpGridData 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 multifield is given as input:

plotMeanField(example.mf)

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

str(example.mf$Data)

<-- Home page of the Wiki

print(sessionInfo())