climatology: Compute a grid climatology

View source: R/climatology.R

climatologyR Documentation

Compute a grid climatology

Description

Calculates the climatology (i.e., complete temporal aggregation, typically the mean) of the input grid.

Usage

climatology(
  grid,
  clim.fun = list(FUN = "mean", na.rm = TRUE),
  by.member = TRUE,
  parallel = FALSE,
  max.ncores = 16,
  ncores = NULL
)

Arguments

grid

Input grid

clim.fun

Function to compute the climatology. This is specified as a list, indicating the name of the aggregation function in first place (as character), and other optional arguments to be passed to the aggregation function. Default to mean (i.e., clim.fun = list(FUN="mean",na.rm = TRUE)).

by.member

Logical. In case of multimember grids, should the climatology be computed sepparately for each member (by.member=TRUE), or a single climatology calculated from the ensemble mean (by.member=FALSE)?. Default to TRUE.

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 ncpus = NULL (the default), or when maxcores exceeds the default ncores value.

Details

Two attributes are appended to the grid:

  • climatology:fun, added to the Data component of the grid, indicating the function used to compute the climatology.

  • season, added to the Dates component (if not yet existing), in order to provide information on the season for which the climatology has been computed.

Value

A grid corresponding to the climatology. See details.

Parallel Processing

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.

Author(s)

J. Bedia

See Also

spatialPlot, for plotting climatologies. persistence, for a special case in which the temporal autocorrelation function is applied.

Examples

 
require(climate4R.datasets)
# Station data:
# Mean surface temperature
data("VALUE_Iberia_tas")
st_mean_clim <- climatology(VALUE_Iberia_tas)
str(st_mean_clim)
require(visualizeR)
spatialPlot(st_mean_clim, backdrop.theme = "coastline")
# Standard deviation of surface temperature
st_sd_clim <- climatology(VALUE_Iberia_tas, clim.fun = list(FUN = sd, na.rm = TRUE))
spatialPlot(st_sd_clim, backdrop.theme = "coastline")

# July surface temp forecast climatology
data("CFS_Iberia_tas")
# Aggregate all members before computing the climatology
t_mean.clim <- climatology(CFS_Iberia_tas,
                           by.member = FALSE)
# Note the new attributes, and that time dimension is preserved as a singleton
str(t_mean.clim$Data)
str(t_mean.clim$Dates)
# Compute a climatology for each member sepparately
t_mean_9mem.clim <- climatology(CFS_Iberia_tas,
                                by.member = TRUE)
str(t_mean_9mem.clim$Data)
# 9 different climatologies, one for each member


SantanderMetGroup/transformeR documentation built on Nov. 25, 2024, 1:25 p.m.