PC2grid: Principal Component grid

View source: R/PC2grid.R

PC2gridR Documentation

Principal Component grid

Description

Convert a Principal Component to a 'time-series' grid.

Usage

PC2grid(
  prinCompObj,
  var = names(prinCompObj)[1],
  pc.idx = 1,
  scale = FALSE,
  opp = FALSE
)

Arguments

prinCompObj

A PCA object as returned by prinComp

var

Character string. Name of the variable for which to extract the PC. Defaults to the first variable in prinCompObj

pc.idx

Index position of the PC to be converted to a grid. Default to the first PC (pc.idx = 1).

scale

Logical. Should the time series values be scaled?. Default to FALSE. If TRUE, the default scale method is applied to each time series.

opp

Logical. Default to FALSE and rarely used. The data are multiplied by -1 so the opposite is returned.

Details

The XY coordinates correspond to the centroid of the window used for the PCA analysis. Details on the extent of this window are provided by the attributes domX and domY within the xyCoords component.

Currently, only the start days are returned. The end dates are not returned by the prinComp output.

Value

A 'time series' grid (i.e., a grid with dimensions lon and lat of length 1). It can be a multimember.

Author(s)

J. Bedia

See Also

Other pca: grid2PCs(), gridFromPCA(), prinComp()

Examples


require(climate4R.datasets)
data("CFS_Iberia_psl")
pc <- prinComp(CFS_Iberia_psl, v.exp = .95)
# Convert to grid the PC of the leading EOF (pc.idx = 1):
psl.index <- PC2grid(prinCompObj = pc, pc.idx = 1)
aggr.fun <- list(FUN = "mean", na.rm = TRUE)
psl.index <- aggregateGrid(psl.index, aggr.m = aggr.fun, aggr.y = aggr.fun,
                           aggr.mem = aggr.fun)
plot(as.Date(getRefDates(psl.index)), psl.index$Data, ty = "o",
     xlab = "year", ylab = "SLP index")
abline(h=0, lty = 2)
title(main = "1st PC of multimember mean DJF SLP over Iberia")
# opp can be used to obtain the inverse:
psl.index.inv <- PC2grid(prinCompObj = pc, pc.idx = 1, opp = TRUE)
psl.index.inv <- aggregateGrid(psl.index.inv, aggr.m = aggr.fun, aggr.y = aggr.fun,
                           aggr.mem = aggr.fun)
lines(as.Date(getRefDates(psl.index.inv)), psl.index.inv$Data, ty = "o", col = "red")


SantanderMetGroup/transformeR documentation built on Oct. 28, 2023, 5:26 a.m.