Learn R Programming

RCMIP5 (version 1.0)

makeZStat: Compute Z-dimension statistic of a variable

Description

Some CMIP5 data are four-dimensional: in addition to longitude, latitude, and time, they include a Z dimension (typically encoded in the netcdf file as 'depth' or 'lev'). This function computes a summary statistic for all Z values. The default statistic is mean, but any summary function that returns a numeric result (including weighted.mean, if you want to apply weights) can be used.

Usage

makeZStat(x, verbose = FALSE, parallel = FALSE, FUN = mean, ...)

Arguments

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

Value

  • A cmip5data object, whose val field is the mean of the variable across Zs A numZs field is also added recording the number of Z values averaged for each year, and x's original Z field is removed.

Details

No status bar is printed when processing in parallel, but progress is logged to a file (call with verbose=T) that can be monitored.

If the user requests parallel processing (via parallel=T) makeZStat (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, makeZStat respects the existing cluster.

See Also

makeAnnualStat makeGlobalStat makeMonthlyStat

Examples

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

Run the code above in your browser using DataLab