deseason.VALUE: Remove seasonal cycle

View source: R/deseason.VALUE.R

deseason.VALUER Documentation

Remove seasonal cycle

Description

Remove seasonal cycle from a VALUE dataset (possibly using a moving average filter for daily datasets)

Usage

deseason.VALUE(valueObj, window.width = 31, max.na.prop = 0.25,
  monthly = FALSE, monthly.clim.fun = "mean", ...)

Arguments

valueObj

Any VALUE object (as returned either by loadValueStations or loadValuePredictions).

window.width

Integer number indicating the width, in days, of the window used for moving average computation of the reference daily climatology. Default to 31 days. See details.

max.na.prop

Maximum allowed proportion of missing data (Default to 0.25). See details

monthly

Logical flag indicating whether the input data is monthly (FALSE) or daily (TRUE, the default)

monthly.clim.fun

Optional. Name of the function used to compute the monthly climatology (default to "mean"). Ignored if monthly = FALSE.

...

Further optional arguments passed to monthly.clim.fun that computes the climatology (only used if monthly = TRUE). A typical optional argument is e.g. na.rm = TRUE passed to the default "mean".

Details

A (circular) moving average daily climatology can be automatically calculated for each data series, considering a user-defined window width centered around lag 0. An additional argument allows to specify the maximum number of missing values allowed, being ommited from the analysis those data series above the threshold.

For daily datasets, the daily climatology (i.e., one value per (julian) day of the year) is subtracted from each daily value in the time series. This daily climatlogical value can be calculated using a moving average window as described above. FOr monthly datatasets, the monthly climatological mean is computed and subtrated to each monthly record. In this case, the moving wndow average is not applied. A global attribute "deseason" is included and assigned a value of TRUE, to indicate that the dataset consist of anomalies. An additional attribute "deseason::window.width" is appended to the output indicating the window width (in days) used, when applicable.

Value

A VALUE object same as input but with seasonal cycles removed.

Note

Although the function is insentitive to the input season, it is recommended to perform seasonal cycle removal on the annual series, rather than in particular seasons. Seasonal slices can be selected afterwards using subsetVALUE.

Author(s)

J. Bedia

Examples

## Not run: 
obs.file <- file.path(find.package("R.VALUE"),"example_datasets","VALUE_ECA_86_v2.zip")
# Load 1 station (Innsbruck) as example:
stationObj <- loadValueStations(obs.file, var = "tmin", stationID = "000013", years = 1991:1993)
# Test different window sizes:
widths <- c(31,45,60)
out <- lapply(widths, function(x) deseason.VALUE(stationObj, window.width = x))
dates <- as.Date(stationObj$Dates$start)
plot(dates, stationObj$Data, ty = 'l', ylab = "tmin (degC)")
for (i in 1:length(widths)) {
      lines(dates,out[[i]]$Data,col = i + 1)
}
legend("bottomright", legend = widths, lty = 1, col = (1:3)+1, title = "window.width")
# Monthly aggregation:
mon <- aggregateVALUE(stationObj, aggr.m = list(FUN = "mean", na.rm = TRUE))
# Compute anomalies w.r.t. the monthly means:
anom <- deseason.VALUE(mon, monthly = TRUE, monthly.clim.fun = "mean", na.rm = TRUE)
plot(mon$Data, ty = 'b')
lines(anom$Data[1,,], col = "red", ty = "b")
legend("topright",
       legend = c("monthly tmin", "monthly tmin anomalies"),
       lty = 1, col = c("black","red"))

## End(Not run)

SantanderMetGroup/R_VALUE documentation built on July 4, 2023, 4:27 a.m.