subsetGrid: Select an arbitrary subset from a grid or multigrid along one...

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/subsetGrid.R

Description

Create a new grid/multigrid that is a subset of the input grid along the selected dimensions

Usage

1
2
3
subsetGrid(grid, var = NULL, cluster = NULL, runtime = NULL,
  members = NULL, years = NULL, season = NULL, lonLim = NULL,
  latLim = NULL, outside = FALSE, station.id = NULL, drop = TRUE)

Arguments

grid

The input grid or station data to be subset. This is either a grid (or station data), as returned e.g. by loadeR::loadGridData (or loadeR::loadStationData), a multigrid, as returned by makeMultiGrid, or other types of multimember grids (possibly multimember grids) as returned e.g. by loadeR.ECOMS::loadECOMS.

var

Character vector indicating the variables(s) to be extracted. (Used for multigrid subsetting). See details.

cluster

An integer vector indicating the clusters to be subset.

runtime

An integer vector indicating the position of the runtimes to be subset.

members

An integer vector indicating the position of the members to be subset.

years

The years to be selected. Note that this can be either a continuous or discontinuous series of years, the latter option often used in a cross-validation framework. See details for year-crossing seasons. Default to NULL (no subsetting is performed on the time dimension).

season

An integer vector indicating the months to be subset.

lonLim

Vector of length = 2, with minimum and maximum longitude coordinates, in decimal degrees, of the bounding box defining the subset. For single-point subsets, a numeric value with the longitude coordinate. If NULL (default), no subsetting is performed on the longitude dimension

latLim

Same as lonLim argument, but for latitude.

outside

if TRUE subset coordinates outside the grid extent are allowed. Default is FALSE.

station.id

Station ID (check $Metadata$station_id).

drop

Logical (default is TRUE). Drop or keep dimensions of length 1.

Details

The attribute subset will be added to the different slots corresponding to the subset dimensions, taking the value of the subroutine called in each case (e.g.: attribute subset will have the value subsetSpatial in the xyCoords slot after spatial subsetting...).

Time slicing by years

In case of year-crossing seasons (e.g. boreal winter (DJF), season = c(12,1,2)), the season is assigned to the years of January and February (i.e., winter of year 2000 corresponds to Dec 1999, Jan 2000 and Feb 2000). Thus, the years argument must be introduced accordingly (See e.g. getYearsAsINDEX function for details).

Spatial slicing

Spatial subset definition is done via the lonLim and latLim arguments, in the same way as for instance the loadGridData function, from package loadeR, with the exception that several checks are undertaken to ensure that the subset is actually within the current extent of the input grid. It is also possible to make single-point selections from a grid, just by specifying a single coordinate instead of a range as the argument value. For instance lonLim = c(-10,10) and latLim = c(35,45) indicate a rectangular window centered in the Iberian Peninsula), and single grid-cell values (for instance lonLim = -3.21 and latLim = 41.087 for retrieving the data in the closest grid point to the point coordinate -3.21E, 41.087N. In the last two cases, the function operates by finding the nearest (euclidean distance) grid-points to the coordinates introduced.

Extracting grids from multigrids

One or several variables from a multigrid object can be extracted. Note that argument var is insensitive to the order of the variables, i.e.: variables will be always returned in the same order they are in the original multigrid.

Value

A new grid object that is a logical subset of the input grid along the specified dimensions.

Author(s)

J. Bedia, M. Iturbide, J. A. Fernandez

See Also

Other subsetting: getTemporalIntersection, intersectGrid.spatial, intersectGrid.time, intersectGrid, limitArea, subsetCluster, subsetDimension, subsetMembers, subsetRuntime, subsetSeason, subsetSpatial, subsetStation, subsetVar, subsetYears

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
## Not run: 
# Example 1 - Spatial / member subset
data("CFS_Iberia_tas")
# Selection of a smaller domain over the Iberian Peninsula and members 3 and 7
sub <- subsetGrid(CFS_Iberia_tas,
                  members = c(3,7),
                  lonLim = c(-10,-5),
                  latLim = c(36,43))
require(visualizeR)                  
spatialPlot(climatology(sub), tol = 0.005, contour = TRUE,
                backdrop.theme = "coastline", rev.colors = TRUE)
                
## Example 2 - Subsetting a multimember multigrid by variables
# Multimember multigrid creation
data("CFS_Iberia_pr", "CFS_Iberia_hus850")
mm.mf <- makeMultiGrid(CFS_Iberia_tas, CFS_Iberia_pr, CFS_Iberia_hus850)
# Extracting just minimum temperature
sub1 <- subsetGrid(mm.mf, var = "tas", members = 1:4)
spatialPlot(climatology(sub1, by.member = TRUE), backdrop.theme = "coastline",
     rev.colors = TRUE)
# Extracting precipitation and maximum temperature
# (Note that the grid variables are NOT re-ordered)
sub2 <- subsetGrid(mm.mf, var = c("pr", "tas"))
getShape(sub2)
getVarNames(sub2)

## Example 3 - Subsetting stations by their codes
data("VALUE_Iberia_pr")
getStationID(VALUE_Iberia_pr)
central_ib <- subsetGrid(VALUE_Iberia_pr, station.id = c("000229", "000231", "000232"))
getStationID(central_iberia)
central_iberia$Metadata
VALUE_Iberia_pr$Metadata

## End(Not run)

SantanderMetGroup/transformeR documentation built on Feb. 14, 2020, 5:55 p.m.