gridFromPCA: Reconstruct a Grid from EOFs and principal components

View source: R/gridFromPCA.R

gridFromPCAR Documentation

Reconstruct a Grid from EOFs and principal components

Description

Reconstructs a grid of a climatic variable from the outputs of a principal components analysis

Usage

gridFromPCA(prinCompObj, var)

Arguments

prinCompObj

A EOF analysis object as returned by prinComp

var

Character string indicating the variable to be re-constructed. In case of PCA analyses performed on a single variable (either multimember or not), this can be omitted.

Value

A grid

Author(s)

J. Bedia

See Also

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

Examples


require(climate4R.datasets)
data(NCEP_Iberia_hus850)
data(NCEP_Iberia_ta850)
data(NCEP_Iberia_psl)
# Multigrid constructor:
multigrid <- makeMultiGrid(NCEP_Iberia_hus850, NCEP_Iberia_ta850, NCEP_Iberia_psl)
# In this example, we retain the first 10 PCs
pca <- prinComp(multigrid, n.eofs = 10)
# We recover the sea-level pressure grid from the its PCs:
names(pca)
psl2 <- gridFromPCA(pca, "psl")
str(psl2)
# The attributes of psl2 indicate that this is a reconstructed grid from 10 PCs, 
# explaining 99\% of the variance:
attributes(psl2)
multigrid$Variable$varName
# psl is the 3rd one
require(visualizeR)
# An example of multimember reconstruction from a multimember PC analysis:
spatialPlot(climatology(NCEP_Iberia_psl), backdrop.theme = "coastline",
                main = "DJF Mean Sea-level Pressure (1983-2002)")
pca2 <- prinComp(NCEP_Iberia_psl, n.eofs = 1)
psl_recovered <- gridFromPCA(pca2)
spatialPlot(climatology(psl_recovered), backdrop.theme = "coastline", 
                main = "DJF Mean Sea-level Pressure (1983-2002)\n-Reconstructed from first EOF-")
# The mean field is similar, but there are (small) differences in temporal variability:
plot(NCEP_Iberia_psl$Data[,3,3], ty = 'l', ylab = "psl")
lines(psl_recovered$Data[,3,3], col = "red")
title("Time series for a selected grid-point")
legend("top", c("original", "reconstructed"), lty = 1, col = c(1,2), bty = "n")
# The 1st EOF captures 85% of total MSLP field variance:
attributes(psl_recovered)$'explained_variance'


SantanderMetGroup/transformeR documentation built on Nov. 25, 2024, 1:25 p.m.