View source: R/aggregateGrid.R
aggregateGrid | R Documentation |
Aggregates a grid along the target dimensions using user-defined functions.
aggregateGrid(
grid,
aggr.mem = list(FUN = NULL),
aggr.d = list(FUN = NULL),
aggr.m = list(FUN = NULL),
aggr.y = list(FUN = NULL),
aggr.s = list(FUN = NULL, season = NULL),
aggr.spatial = list(FUN = NULL),
aggr.lat = list(FUN = NULL),
weight.by.lat = TRUE,
aggr.lon = list(FUN = NULL),
aggr.loc = list(FUN = NULL),
parallel = FALSE,
max.ncores = 16,
ncores = NULL
)
grid |
a grid or multigrid to be aggregated. |
aggr.mem |
Same as |
aggr.d |
Daily aggregation function (for sub-daily data only). A list indicating the name of the
aggregation function in first place, and other optional arguments to be passed to the aggregation function.
To be on the safe side, the function in |
aggr.m |
Same as |
aggr.y |
Same as |
aggr.s |
Same as |
aggr.spatial |
Same as |
aggr.lat |
Same as |
weight.by.lat |
Logical. Should latitudinal averages be weighted by the cosine of latitude?.
Default to |
aggr.lon |
Same as |
aggr.loc |
Same as |
parallel |
Logical. Should parallel execution be used? |
max.ncores |
Integer. Upper bound for user-defined number of cores. |
ncores |
Integer number of cores used in parallel computation. Self-selected number of
cores is used when |
Aggregation function definition
The aggregation functions are specified in the form of a named list of the type FUN = "function", ...
, where
...
are further arguments passes to FUN. This allows for a flexible definition of aggregation functions, that are
internally passes to tapply
. Note that the name of the function is indicated as a character string.
Member aggregation
The function preserves the metadadata associated with member information (i.e. initialization dates and member names) after
aggregation. In addition, an attribute indicating the member aggregation function is added to the Variable
component.
Temporal aggregation
To annually or monthly aggregate data, aggr.d
and/or aggr.m
functions are specified.
Aggregations need to be specified from bottom to top, so for instance, if the data in the grid is sub-daily
and aggr.d
is not specified, an error will be given for monthly or annual aggregation attempts. Similarly,
annual aggregations require a previous specification of daily and monthly aggregation, when applicable. Special
attributes in the Variable
component indicate the aggregation undertaken.
In order to preserve the information of the season in annual aggregations, the attribute season
is
added to the Dates
component.
A grid or multigrid aggregated along the chosen dimension(s).
Parallel processing is enabled using the parallel package.
Parallelization is undertaken by a FORK-type parallel socket cluster formed by ncores
.
If ncores
is not specified (default), ncores
will be one less than the autodetected number of cores.
The maximum number of cores used for parallel processing can be set with the max.ncores
argument,
although this will be reset to the auto-detected number of cores minus 1 if this number is exceeded. Note that not all
code, but just some critical loops within the function are parallelized.
In practice, parallelization does not always result in smaller execution times, due to the parallel overhead. However, parallel computing may potentially provide a significant speedup for the particular case of large multimember datasets or large grids.
Parallel computing is currently not available for Windows machines.
M. Iturbide, M. de Felice, J. Bedia
require(climate4R.datasets)
data("CFS_Iberia_tas")
## Aggregating members
# Ensemble mean
mn <- aggregateGrid(grid = CFS_Iberia_tas, aggr.mem = list(FUN = "mean", na.rm = TRUE))
require(visualizeR)
spatialPlot(climatology(mn, by.member = FALSE),
backdrop.theme = "coastline", main = "Ensemble mean tmax climatology")
# Ensemble 90th percentile
ens90 <- aggregateGrid(grid = CFS_Iberia_tas,
aggr.mem = list(FUN = quantile, probs = 0.9, na.rm = TRUE))
spatialPlot(climatology(ens90, by.member = FALSE),
backdrop.theme = "coastline", main = "Ensemble 90th percentile tmax climatology")
## Monthly aggregation
monthly.mean <- aggregateGrid(CFS_Iberia_tas, aggr.m = list(FUN = mean, na.rm = TRUE))
spatialPlot(climatology(monthly.mean), backdrop.theme = "coastline",
main = "Mean tmax climatology")
## Several dimensions ca be aggregated in one go:
mm.mean <- aggregateGrid(CFS_Iberia_tas,
aggr.mem = list(FUN = "mean", na.rm = TRUE),
aggr.m = list(FUN = "mean", na.rm = TRUE))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.