bindGrid: Grid binding by the specified dimension

Description Usage Arguments Details Author(s) See Also Examples

View source: R/bindGrid.R

Description

Flexible binding of grids by the specified dimension. The grids must be consistent regarding the dimensions that are no subject of binding. Useful to handle sets of predictors as a single block.

Usage

1
2
bindGrid(..., dimension = c("member", "time", "lat", "lon", "loc"),
  spatial.tolerance = 0.001, dataset.attr = NULL)

Arguments

...

Input grids to bind by their member dimension. These must be compatible in time and space (see details). For flexibility, they can be introduced as a list or directly as consecutive arguments.

dimension

Dimension along which the binding is performed. Choices are "member" (the default), "time", "lat", "lon" or "loc" (for point data) .

spatial.tolerance

Numeric of length one. Coordinate differences smaller than spatial.tolerance will be considered equal coordinates. Default to 0.001 –assuming that degrees are being used it seems a reasonable rounding error after interpolation–. This value is passed to the identical function to check for spatial consistency of the input grids.

dataset.attr

Character string used to update the "dataset" attribute of the output grid. This is used only when binding grids along the "member" dimension, in case multi-model combination is being undertaken, (i.e., different models are being joined as members of a single multimodel dataset) so the new dataset attribute reflects this. Note that the default behaviour is retaining the "dataset" attribute of the first grid given, resulting in a misleading metadata information if this is the case. Default to NULL, and ignored.

Details

Application

One usual application of this function is the construction of multimodel ensembles, by binding different grids from different models along their "member" dimension. The function can be also useful for handling loading large domains and multimembers, that are difficult or impossible to load at once with the loading functions. The task of loading can be efficiently parallelized by splitting the request by ensemble member subsets, and then binded with this function.

Input grids consistency checks

The function makes a number of checks in order to test the spatiotemporal compatibility of the input multi-member grids. The spatial consistency of the input grids is also checked. In order to avoid possible errors from the user, the spatial consistency (i.e., equal XY coordinates) of the input grids must be ensured before attempting the creation of the multigrid, otherwise giving an error. This can be achieved either through the specification of the same 'lonLim' and 'latLim' argument values when loading the grids, or using the interpGrid interpolator in conjuntion with the getGrid method.

Binding along the time dimension

The "time" dimension will be always returned in ascending order, regardless of the ordering of the input grids. The internal helper sortDim.time is applied to this aim.

Author(s)

J Bedia and M Iturbide

See Also

subsetGrid, for the reverse operation. makeMultiGrid is somehow related, although envisaged to bind grids of different variables along a new dimension "var" (variable), mainly for the construction of predictor sets in downscaling applications. intersectGrid, for temporal or spatial intersection of two or more grids.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
## Binding along the member dimension:
data("CFS_Iberia_tas")
# We first diaggregate in various grids with different members
members1_2 <- subsetGrid(CFS_Iberia_tas, members = 1:2)
members3_4 <- subsetGrid(CFS_Iberia_tas, members = 3:4)
member7 <- subsetGrid(CFS_Iberia_tas, members = 7)
member8 <- subsetGrid(CFS_Iberia_tas, members = 8)
# The function is insensitive to the number of members per input grid
bindedGrid <- bindGrid(members1_2, members3_4, member7, member8, dimension = "member")
getShape(bindedGrid, "member")
## Also works for point data
data("VALUE_Iberia_tas")
CFS_points <- interpGrid(CFS_Iberia_tas, getGrid(VALUE_Iberia_tas))
getShape(CFS_points)
mem1 <- subsetGrid(CFS_points, members = 1)
mem5 <- subsetGrid(CFS_points, members = 5)
CFS_points_2mem <- bindGrid(mem1, mem5, dimension = "member")
getShape(CFS_points_2mem)
## Not run: 
require(visualizeR)
spatialPlot(climatology(bindedGrid), backdrop.theme = "coastline", rev.colors = TRUE)

## End(Not run)
## Binding along time:
data("EOBS_Iberia_tas")
eobs.1998 <- subsetGrid(EOBS_Iberia_tas, years = 1998)
eobs.1999_2000 <- subsetGrid(EOBS_Iberia_tas, years = 1999:2000)
eobs1 <- bindGrid(eobs.1998, eobs.1999_2000, dimension = "time")
eobs2 <- bindGrid(eobs.1999_2000, eobs.1998, dimension = "time")
# Note that the output is always adequately ordered along time:
identical(eobs1, eobs2)

# For convenience while programming, it also accepts a list as input:
year.list <- list(1998, 1999:2000)
grid.list <- lapply(year.list, function(x) {
    subsetGrid(EOBS_Iberia_tas, years = x)
    # perform any other tasks with the subsets...
}) 
eobs3 <- do.call("bindGrid", c(grid.list, dimension = "time"))
identical(eobs1, eobs3)

SantanderMetGroup/transformeR documentation built on Nov. 23, 2019, 12:28 p.m.