CST_Subset {CSTools} | R Documentation |
Subset an object of class s2dv_cube
Description
This function allows to subset (i.e. slice, take a chunk of) the data inside
an object of class s2dv_cube
and modify the dimensions, coordinates and
attributes accordingly, removing any variables, time steps and spatial
coordinates that are dropped when subsetting. It ensures that the information
inside the s2dv_cube remains coherent with the data it contains.
As in the function Subset
from the ClimProjDiags package, the
dimensions to subset along can be specified via the parameter along
either with integer indices or by their name.
There are additional ways to adjust which dimensions are dropped in the
resulting object: either to drop all, to drop none, to drop only the ones that
have been sliced or to drop only the ones that have not been sliced.
The load_parameters
and when
attributes of the original cube
are preserved. The source_files
attribute is subset along the
var_dim
and dat_dim
dimensions.
Usage
CST_Subset(x, along, indices, drop = FALSE, var_dim = NULL, dat_dim = NULL)
Arguments
x |
An object of class |
along |
A vector with references to the dimensions to take the subset from: either integers or dimension names. |
indices |
A list of indices to take from each dimension specified in 'along'. If a single dimension is specified in 'along', it can be directly provided as an integer or a vector. |
drop |
Whether to drop all the dimensions of length 1 in the resulting array, none, only those that are specified in 'along', or only those that are not specified in 'along'. The possible values are: 'all' or TRUE, 'none' or FALSE, 'selected', and 'non-selected'. The default value is FALSE. |
var_dim |
A chatacter string indicating the name of the variable dimension. The default value is NULL. |
dat_dim |
A character string indicating the name of dataset dimension. The default value is NULL. |
Value
An object of class s2dv_cube
with similar data, coordinates and
attributes as the x
input, but with trimmed or dropped dimensions.
Author(s)
Agudetse Roures Victoria, victoria.agudetse@bsc.es
See Also
Examples
#Example with sample data:
# Check original dimensions and coordinates
lonlat_temp$exp$dims
names(lonlat_temp$exp$coords)
# Subset the s2dv_cube
exp_subset <- CST_Subset(lonlat_temp$exp,
along = c("lat", "lon"),
indices = list(1:10, 1:10),
drop = 'non-selected')
# Check new dimensions and coordinates
exp_subset$dims
names(exp_subset$coords)