filterGrid: Time filtering

View source: R/filterGrid.R

filterGridR Documentation

Time filtering

Description

Apply a filter along the time dimension of a grid

Usage

filterGrid(
  grid,
  window.width,
  method = c("convolution", "recursive"),
  sides = 1,
  parallel = FALSE,
  max.ncores = 16,
  ncores = NULL,
  ...
)

Arguments

grid

Input grid (possibly multimember)

window.width

An integer specifying the moving window width. This is in the same temporal units as the input grid. The function internally converts this value to a vector of filter coefficients of the form rep(1/n,n). See filter for details.

method

Either "convolution" or "recursive". The "convolution" option (Default) performs a moving average, while "recursive" applies an autoregressive model. See filter for details.

sides

Used for "convolution" filters only. If sides = 1 the filter coefficients are for past values only; if sides = 2 they are centred around lag 0. See filter for more details.

parallel

Logical. Should parallel execution be used?

max.ncores

Integer. Upper bound for user-defined number of cores.

ncores

Integer number of cores used in parallel computation. Self-selected number of cores is used when ncpus = NULL (the default), or when maxcores exceeds the default ncores value.

...

Further arguments passed to filter. Worth to mention here the circular argument, used in moving averages. See filter for details.

Details

A wrapper of function filter

Value

A time-filtered grid.

Parallel Processing

Parallel processing is enabled using the parallel package. Parallelization is undertaken by a FORK-type parallel socket cluster formed by ncores. If ncores is not specified (default), ncores will be one less than the autodetected number of cores. The maximum number of cores used for parallel processing can be set with the max.ncores argument, although this will be reset to the auto-detected number of cores minus 1 if this number is exceeded. Note that not all code, but just some critical loops within the function are parallelized.

In practice, parallelization does not always result in smaller execution times, due to the parallel overhead. However, parallel computing may potentially provide a significant speedup for the particular case of large multimember datasets or large grids.

Parallel computing is currently not available for Windows machines.

Author(s)

J Bedia

Examples


require(climate4R.datasets)
data(NCEP_Iberia_ta850)
plot(NCEP_Iberia_ta850[["Data"]][,3,3], ty = 'l')
# Apply a moving average considering 2 different window widths of 30 and 90 days
fgrid30 <- filterGrid(NCEP_Iberia_ta850, method = "convolution", window.width = 30, sides = 1)
lines(fgrid30[["Data"]][,3,3], col = 'red')
fgrid90 <- filterGrid(NCEP_Iberia_ta850, method = "convolution", window.width = 90, sides = 1)
lines(fgrid90[["Data"]][,3,3], col = 'green')
legend("top", c("raw","30-day MA", "90-day MA"), lty = 1, col = c(1,2,3), ncol = 3)


SantanderMetGroup/transformeR documentation built on Aug. 29, 2024, 6:42 a.m.