Learn R Programming

RCMIP5 (version 1.0)

makeAnnualStat: Compute annual statistic of a variable

Description

Most CMIP5 data are monthly, and we frequently want to summarize these to annual numbers. This function does that (although annual files also occur, and will be handled as well). The default statistic is mean, but any summary function that returns a numeric result can be used.

Usage

makeAnnualStat(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 months of year
...
Other arguments passed on to FUN

Value

  • A cmip5data object, whose val field is the annual mean of the variable. A numMonths field is also added recording the number of months averaged for each year.

Details

If Z dimension is present, the stat function is calculated for all values 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.

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

See Also

makeZStat makeGlobalStat makeMonthlyStat

Examples

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

Run the code above in your browser using DataLab