seas.sum {climate.plot}R Documentation

Seasonal sum data object

Description

Create a seasonal sum object used for analysis of precipitation data (among other things, such as recharge rates).

Usage

# minimum usage
seas.sum(dat)

# all options
seas.sum(dat, start, end, width = 11, param, prime, a.cut = 0.3, 
     na.cut = 0.2, unit = "mm", id, name)

Arguments

dat time-varying data.frame with parameters which are summed, such as precipitation
start start year; if omitted minimum year will be used
end end year; if omitted will use same as start, and if start is omitted, will use maximum year
width a number specifying the width of the bin (factor) in days, or "mon" for Months (see mkfact for others)
param a character array of the names from dat that are to be summed, such as c("rain","snow","precip"), if available
prime a single parameter from param which is the prime variable of interest, such as "precip"; this is the parameter used for comparison with a.cut and na.cut in the resulting active and na dimensions
a.cut cut-off value for the day to be considered an active or ‘wet day’ (based on the prime parameter); a trace amount of 0.3 mm is suggested
na.cut cut-off fraction of missing values; can be single value or a vector for c(annual,seasonal); details given below
unit unit for seas.sum object; useful for future plotting
id unique station identifier used to extract a subset of data from dat
name provide a name for the seasonal sum object; otherwise generated from id (if available)

Details

This function is used to discretize and sum time-varying data in a data.frame for analysis in seasonal and annual parts. This is particularly useful for calculating normals of rates, such as precipitation and recharge. This function simply sums up each parameter in each bin for each year, and provides the results in several multi-dimensional arrays.

Sums are not normalized, and represent a sum for the number of days in the bin (seasonal data) or year (for annual data). Seasonal data can be normalized by the number of days (for a rate per day) or by the number of active days where prime > a.cut. Both arrays of these numbers of days are provided for normalizing.

For annual sums, years with many missing values are ignored (receiving a value of NA) since it has insufficient data for a complete sum. The amount of allowable NA values is controlled by na.cut, which is a fraction of NA values for the whole year (default is 0.2).

The seasonal sums are calculated independently from the annual sums. Individual bins from each year with many missing values are ignored, where the amount of allowable NA values is controlled by na.cut (fraction of NAs in each bin of each individual year; default is 0.2).

Value

Returns a seas.sum object, which is a list with the following properties:

ann array of annual data; the dimensions are:
[[1]]
years
[[2]]
annual sums of parameters (param) (if original units were mm/day, they are now mm/year); also the total number of active days (active), existing days (days), and missing days (na) in the year.
seas array of seasonal data; the dimensions are:
[[1]]
years
[[2]]
bins, or seasonal factors generated by mkfact
[[3]]
sums of param, active, days, and na in each bin of each year.
call function call
years years (same as ann[[1]] and seas[[1]])
param parameters which the sums represent (part of ann[[2]] and seas[[3]])
prime prime parameter
unit unit of parameter
width width argument passed to mkfact
bins
names of bins returned by mkfact (same as seas[[2]])
precip.only value used in argument (modified if insufficient data found in dat)
na.cut value used in argument
a.cut value used in argument
id value used in argument; or found in dat$id if present and not given as argument
name either given by name argument or generated from id or from dat object name

Author(s)

M.W. Toews

See Also

image.seas.sum to view the result result, seas.norm to view a “normal”

Examples

loc <- Sys.getlocale()
on.exit(Sys.setlocale(locale=loc))
Sys.setlocale(loc="C")
data(mscstn)
data(mscdata)

dat.ss <- seas.sum(mscdata,id=1108447,width="mon")

# Annual data
dat.ss$ann

# Demonstrate how to slice through a cubic array
dat.ss$seas["1990",,]
dat.ss$seas[,"Feb",] # month names are locale specific
dat.ss$seas[,,"precip"]

# Simple calculation on an array
(monthly.mean <- apply(dat.ss$seas[,,"precip"],2,mean,na.rm=TRUE))
barplot(monthly.mean,ylab="Mean monthly total (mm/month)",
        main="Un-normalized mean precipitation in Vancouver, BC")
text(6.5,150,paste("Un-normalized rates given 'per month' should be",
        "avoided since ~3-9% error is introduced",
        "to the analysis between months",sep="\n"))

# Normalized precip
norm.monthly <- dat.ss$seas[,,"precip"]/dat.ss$seas[,,"days"]
norm.monthly.mean <- apply(norm.monthly,2,mean,na.rm=TRUE)
print(round(norm.monthly,2))
print(round(norm.monthly.mean,2))
barplot(norm.monthly.mean,ylab="Normalized mean monthly total (mm/day)",
        main="Normalized mean precipitation in Vancouver, BC")

# Better graphics of data
dat.ss <- seas.sum(mscdata,id=1108447)
image(dat.ss)

[Package climate.plot version 0.1-2 Index]