eofs.multivariate.iris
¶
Multivariate EOF analysis for iris
cubes.
-
class
eofs.multivariate.iris.
MultivariateEof
(cubes, weights=None, center=True, ddof=1)[source]¶ Multivariate EOF analysis (meta-data enabled
iris
interface)Create a MultivariateEof instance.
The EOF solution is computed at initialization time. Method calls are used to retrieve computed quantities.
Arguments:
- cubes
A list/tuple containing one or more
Cube
instances, each with two or more dimensions, containing the data to be analysed. Time must be the first dimension of eachCube
. Missing values are allowed provided that they are constant with time in each field (e.g., values of an oceanographic field over land).
Optional arguments:
- weights
Sets the weighting method. One method can be chosen to apply to all cubes in datasets or a sequence of options can be given to specify a different weighting method for each cube in datasets. The following pre-defined weighting methods are available:
‘area’ : Square-root of grid cell area normalized by total grid area. Requires a latitude-longitude grid to be present in the corresponding
Cube
. This is a fairly standard weighting strategy. If you are unsure which method to use and you have gridded data then this should be your first choice.‘coslat’ : Square-root of cosine of latitude. Requires a latitude dimension to be present in the corresponding
Cube
.None : Equal weights for all grid points (‘none’ is also accepted).
Alternatively a sequence of arrays of weights whose shapes are compatible with the corresponding
Cube
instances in datasets may be supplied instead of specifying a weighting method.- center
If True, the mean along the first axis of each cube in datasets (the time-mean) will be removed prior to analysis. If False, the mean along the first axis will not be removed. Defaults to True (mean is removed).
The covariance interpretation relies on the input data being anomalies with a time-mean of 0. Therefore this option should usually be set to True. Setting this option to True has the useful side effect of propagating missing values along the time dimension, ensuring that a solution can be found even if missing values occur in different locations at different times.
- ddof
‘Delta degrees of freedom’. The divisor used to normalize the covariance matrix is N - ddof where N is the number of samples. Defaults to 1.
Returns:
- solver
An
MultivariateEof
instance.
Examples:
EOF analysis of two cubes with area-weighting:
from eofs.multivariate.iris import MultivariateEof solver = MultivariateEof(cube1, cube2, weights='area')
-
neofs
= None¶ Number of EOFs in the solution.
-
pcs
(pcscaling=0, npcs=None)[source]¶ Principal component time series (PCs).
Optional arguments:
- pcscaling
Set the scaling of the retrieved PCs. The following values are accepted:
0 : Un-scaled PCs (default).
1 : PCs are scaled to unit variance (divided by the square-root of their eigenvalue).
2 : PCs are multiplied by the square-root of their eigenvalue.
- npcs
Number of PCs to retrieve. Defaults to all the PCs. If the number of PCs requested is more than the number that are available, then all available PCs will be returned.
Returns:
- pcs
A
Cube
containing the ordered PCs.
Examples:
All un-scaled PCs:
pcs = solver.pcs()
First 3 PCs scaled to unit variance:
pcs = solver.pcs(npcs=3, pcscaling=1)
-
eofs
(eofscaling=0, neofs=None)[source]¶ Empirical orthogonal functions (EOFs).
Optional arguments:
- eofscaling
Sets the scaling of the EOFs. The following values are accepted:
0 : Un-scaled EOFs (default).
1 : EOFs are divided by the square-root of their eigenvalues.
2 : EOFs are multiplied by the square-root of their eigenvalues.
- neofs
Number of EOFs to return. Defaults to all EOFs. If the number of EOFs requested is more than the number that are available, then all available EOFs will be returned.
Returns:
- eofs_list
A list of
Cube
instances containing the ordered EOFs for each variable.
Examples:
All EOFs with no scaling:
eofs_list = solver.eofs()
The leading EOF with scaling applied:
eof1_list = solver.eofs(neofs=1, eofscaling=1)
-
eofsAsCorrelation
(neofs=None)[source]¶ Empirical orthogonal functions (EOFs) expressed as the correlation between the principal component time series (PCs) and the each data set in the
MultivariateEof
input datasets.Note
These are not related to the EOFs computed from the correlation matrix.
Optional argument:
- neofs
Number of EOFs to return. Defaults to all EOFs. If the number of EOFs requested is more than the number that are available, then all available EOFs will be returned.
Returns:
- eofs_list
A list of
Cube
instances containing the ordered EOFs for each variable.
Examples:
All EOFs of each data set:
eofs_list = solver.eofsAsCorrelation()
The leading EOF of each data set:
eof1_list = solver.eofsAsCorrelation(neofs=1)
-
eofsAsCovariance
(neofs=None, pcscaling=1)[source]¶ Empirical orthogonal functions (EOFs) expressed as the covariance between the principal component time series (PCs) and the each data set in the
MultivariateEof
input datasets.Optional argument:
- neofs
Number of EOFs to return. Defaults to all EOFs. If the number of EOFs requested is more than the number that are available, then all available EOFs will be returned.
- pcscaling
Set the scaling of the PCs used to compute covariance. The following values are accepted:
0 : Un-scaled PCs.
1 : PCs are scaled to unit variance (divided by the square-root of their eigenvalue) (default).
2 : PCs are multiplied by the square-root of their eigenvalue.
The default is to divide PCs by the square-root of their eigenvalue so that the PCs are scaled to unit variance (option 1).
Returns:
- eofs_list
A list of
Cube
instances containing the ordered EOFs for each variable.
Examples:
All EOFs of each data set:
eofs_list = solver.eofsAsCovariance()
The leading EOF of each data set:
eof1_list = solver.eofsAsCovariance(neofs=1)
-
eigenvalues
(neigs=None)[source]¶ Eigenvalues (decreasing variances) associated with each EOF mode.
Optional argument:
- neigs
Number of eigenvalues to return. Defaults to all eigenvalues. If the number of eigenvalues requested is more than the number that are available, then all available eigenvalues will be returned.
Returns:
- eigenvalues
A
Cube
containing the eigenvalues arranged largest to smallest.
Examples:
All eigenvalues:
eigenvalues = solver.eigenvalues()
The first eigenvalue:
eigenvalues1 = solver.eigenvalues(neigs=1)
-
varianceFraction
(neigs=None)[source]¶ Fractional EOF mode variances.
Optional argument:
- neigs
Number of eigenvalues to return the fractional variance for. Defaults to all eigenvalues. If the number of eigenvalues requested is more than the number that are available, then fractional variances for all available eigenvalues will be returned.
Returns:
- variance_fractions
A
Cube
containing the fractional variances.
Examples:
The fractional variance represented by each EOF mode:
variance_fractions = solver.varianceFraction()
The fractional variance represented by the first EOF mode:
variance_fraction_mode_1 = solver.VarianceFraction(neigs=1)
-
totalAnomalyVariance
()[source]¶ Total variance associated with the field of anomalies (the sum of the eigenvalues).
Returns:
- total_variance
A scalar value (not a
Cube
).
Example:
Get the total variance:
total_variance = solver.totalAnomalyVariance()
-
northTest
(neigs=None, vfscaled=False)[source]¶ Typical errors for eigenvalues.
The method of North et al. (1982) is used to compute the typical error for each eigenvalue. It is assumed that the number of times in the input data set is the same as the number of independent realizations. If this assumption is not valid then the result may be inappropriate.
Optional arguments:
- neigs
The number of eigenvalues to return typical errors for. Defaults to typical errors for all eigenvalues. If the number of eigenvalues requested is more than the number that are available, then typical errors for all available eigenvalues will be returned.
- vfscaled
If True scale the errors by the sum of the eigenvalues. This yields typical errors with the same scale as the values returned by
MultivariateEof.varianceFraction
. If False then no scaling is done. Defaults to False (no scaling).
References
North G.R., T.L. Bell, R.F. Cahalan, and F.J. Moeng (1982) Sampling errors in the estimation of empirical orthogonal functions. Mon. Weather. Rev., 110, pp 669-706.
Returns:
- errors
A
Cube
containing the typical errors.
Examples:
Typical errors for all eigenvalues:
errs = solver.northTest()
Typical errors for the first 5 eigenvalues scaled by the sum of the eigenvalues:
errs = solver.northTest(neigs=5, vfscaled=True)
-
reconstructedField
(neofs)[source]¶ Reconstructed data sets based on a subset of EOFs.
If weights were passed to the
MultivariateEof
instance the returned reconstructed fields will automatically have this weighting removed. Otherwise each returned field will have the same weighting as the corresponding array in theMultivariateEof
input datasets.Argument:
- neofs
Number of EOFs to use for the reconstruction. If the number of EOFs requested is more than the number that are available, then all available EOFs will be used for the reconstruction. Alternatively this argument can be an iterable of mode numbers (where the first mode is 1) in order to facilitate reconstruction with arbitrary modes.
Returns:
- reconstruction_list
A list of
Cube
with the same dimensions as the variables in theMultivariateEof
input datasets contaning the reconstructions using neofs EOFs.
Example:
Reconstruct the input data sets using 3 EOFs:
reconstruction_list = solver.reconstructedField(neofs=3)
Reconstruct the input field using EOFs 1, 2 and 5:
reconstruction_list = solver.reconstuctedField([1, 2, 5])
-
projectField
(cubes, neofs=None, eofscaling=0, weighted=True)[source]¶ Project a set of fields onto the EOFs.
Given a set of fields, projects them onto the EOFs to generate a corresponding set of pseudo-PCs. Argument:
- fields
A list/tuple containing one or more
Cube
instances, each with two or more dimensions, containing the data to be projected onto the EOFs. Each field must have the same spatial dimensions (including missing values in the same places) as the corresponding data set in theMultivariateEof
input datasets. The fields may have different length time dimensions to theMultivariateEof
inputs datasets or no time dimension at all, but this must be consistent for all fields.
Optional arguments:
- neofs
Number of EOFs to project onto. Defaults to all EOFs. If the number of EOFs requested is more than the number that are available, then the field will be projected onto all available EOFs.
- eofscaling
Set the scaling of the EOFs that are projected onto. The following values are accepted:
0 : Un-scaled EOFs (default).
1 : EOFs are divided by the square-root of their eigenvalue.
2 : EOFs are multiplied by the square-root of their eigenvalue.
- weighted
If True then each field in fields is weighted using the same weights used for the EOF analysis prior to projection. If False then no weighting is applied. Defaults to True (weighting is applied). Generally only the default setting should be used.
Returns:
- pseudo_pcs
A
Cube
containing the ordered pseudo-PCs.
Examples:
Project a data set onto all EOFs:
pseudo_pcs = solver.projectField([field1, field2])
Project a data set onto the four leading EOFs:
pseudo_pcs = solver.projectField([field1, field2], neofs=4)