Learn R Programming

RCMIP5 (version 1.0)

makeGlobalStat: Compute global statistic of a variable

Description

We frequently want a global summary for CMIP5 data, usually weighted by the grid cell areas used by each particular model. This function does that. If no area weighting is supplied, a warning is given. The default statistic is weighted.mean, but any summary function that returns a numeric result can be used.

Usage

makeGlobalStat(x, area = NULL, verbose = FALSE, parallel = FALSE,
  FUN = weighted.mean, ...)

Arguments

x
A cmip5data object
area
An area cmip5data object
verbose
logical. Print info as we go?
parallel
logical. Parallelize if possible?
FUN
function. Function to apply across grid
...
Other arguments passed on to FUN

Value

  • A cmip5data object, in which the val dimensions are the same as the caller for Z (if present) and time, but lon and lat are reduced to 1 (i.e. no dimensionality). A numCells field is also added, recording the number of cells in the spatial grid.

Details

If a Z dimension is present, the stat function is calculated for all combinations of these. No status bar is printed when processing in parallel, but progress is logged to a file (call with verbose=T) that can be monitored.

This function is more complicated than the other makeXxxStat functions, because it provides explicit support for area-weighted functions. We expect that weighted.mean and a weighted sum will be the most frequent calculations needed. The former is built into R, and the latter can generally be calculated as weighted.mean * sum(area). A user-supplied stat function must follow the weighted.mean syntax, in particular accepting parameters 'x' (data) and 'w' (weights) of equal size.

If the user requests parallel processing (via parallel=T) makeGlobalStat (i) attempts to load the doParallel package, and (ii) registers it as a parallel backend unless the user has already done this (e.g. set up a virtual cluster with particular, desired characteristics). In that case, makeGlobalStat respects the existing cluster.

See Also

makeAnnualStat makeZStat makeMonthlyStat

Examples

Run this code
d <- cmip5data(1970:1975)   # sample data
makeGlobalStat(d)
summary(makeGlobalStat(d))
library(doParallel)
registerDoParallel()
summary(makeGlobalStat(d, verbose=TRUE, parallel=TRUE))

Run the code above in your browser using DataLab