# Path: lib/eofs/tools/standard.py
# def covariance_map(pcs, field, ddof=1):
#     """Covariance maps for a set of PCs and a spatial-temporal field.
# 
#     Given an array where the columns are PCs (e.g., as output from
#     `eofs.standard.Eof.pcs`) and an array containing spatial-temporal
#     data where the first dimension represents time, one covariance map
#     per PC is computed.
# 
#     The field must have the same temporal dimension as the PCs. Any
#     number of spatial dimensions (including zero) are allowed in the
#     field and there can be any number of PCs.
# 
#     **Arguments:**
# 
#     *pcs*
#         PCs as the columns of an array.
# 
#     *field*
#         Spatial-temporal field with time as the first dimension.
# 
#     **Optional arguments:**
# 
#     *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:**
# 
#     *covariance_maps*
#         An array with the covariance maps along the first dimension.
# 
#     **Example:**
# 
#     Compute covariance maps for each PC::
# 
#         pcs = solver.pcs(pcscaling=1)
#         covariance_maps = covariance_maps(pcs, field)
# 
#     """
#     # Check PCs and fields for validity, flatten the arrays ready for the
#     # computation and remove the mean along the leading dimension.
#     pcs_cent, field_cent, out_shape = _check_flat_center(pcs, field)
#     # Set the divisor according to the specified delta-degrees of freedom.
#     div = np.float64(pcs_cent.shape[0] - ddof)
#     # Compute the covariance map, making sure it has the appropriate shape.
#     cov = (ma.dot(field_cent.T, pcs_cent).T / div).reshape(out_shape)
#     cov = ma.masked_invalid(cov)
#     return cov
# 
# Path: lib/eofs/tools/standard.py
# def correlation_map(pcs, field):
#     """Correlation maps for a set of PCs and a spatial-temporal field.
# 
#     Given an array where the columns are PCs (e.g., as output from
#     `~eofs.standard.Eof.pcs`) and an array containing spatial-temporal
#     data where the first dimension represents time, one correlation map
#     per PC is computed.
# 
#     The field must have the same temporal dimension as the PCs. Any
#     number of spatial dimensions (including zero) are allowed in the
#     field and there can be any number of PCs.
# 
#     **Arguments:**
# 
#     *pcs*
#         PCs as the columns of an array.
# 
#     *field*
#         Spatial-temporal field with time as the first dimension.
# 
#     **Returns:**
# 
#     *correlation_maps*
#         An array with the correlation maps along the first dimension.
# 
#     **Example:**
# 
#     Compute correlation maps for each PC::
# 
#         pcs = solver.pcs(pcscaling=1)
#         correlation_maps = correlation_maps(pcs, field)
# 
#     """
#     # Check PCs and fields for validity, flatten the arrays ready for the
#     # computation and remove the mean along the leading dimension.
#     pcs_cent, field_cent, out_shape = _check_flat_center(pcs, field)
#     # Compute the standard deviation of the PCs and the fields along the time
#     # dimension (the leading dimension).
#     pcs_std = pcs_cent.std(axis=0)
#     field_std = field_cent.std(axis=0)
#     # Set the divisor.
#     div = np.float64(pcs_cent.shape[0])
#     # Compute the correlation map.
#     cor = ma.dot(field_cent.T, pcs_cent).T / div
#     cor = ma.masked_invalid(cor)
#     cor /= ma.outer(pcs_std, field_std)
#     # Return the correlation with the appropriate shape.
#     return cor.reshape(out_shape)
# 
# Path: lib/eofs/tools/generic.py
# def covcor_dimensions(pc_dims, field_dims):
#     """
#     Extract the appropriate dimensions from a set of PCs and a field for
#     construction of covariance/correlation map dimensions.
# 
#     """
#     spatial_dims = field_dims[1:]
#     try:
#         pc_dim = pc_dims[1]
#     except IndexError:
#         pc_dim = None
#     covcor_dims = [d for d in [pc_dim] + spatial_dims if d is not None]
#     return covcor_dims


import cdms2
import numpy as np
from .standard import covariance_map as standard_covmap
from .standard import correlation_map as standard_cormap
from .generic import covcor_dimensions

    **Arguments:**

    *pcs*
        PCs in a `cdms2` variable.

    *field*
        Spatial-temporal field in a `cdms2` variable.

    **Optional arguments:**

    *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:**

    *covariance_maps*
        A `cdms2` variable containing the covariance maps.

    **Examples:**

    Compute covariance maps for each PC::

        pcs = eofobj.pcs(pcscaling=1)
        covmaps = covariance_map(pcs, field)

    """
    cov = standard_covmap(pcs.asma(), field.asma(), ddof=ddof)

# Path: lib/eofs/tools/standard.py
# def covariance_map(pcs, field, ddof=1):
#     """Covariance maps for a set of PCs and a spatial-temporal field.
# 
#     Given an array where the columns are PCs (e.g., as output from
#     `eofs.standard.Eof.pcs`) and an array containing spatial-temporal
#     data where the first dimension represents time, one covariance map
#     per PC is computed.
# 
#     The field must have the same temporal dimension as the PCs. Any
#     number of spatial dimensions (including zero) are allowed in the
#     field and there can be any number of PCs.
# 
#     **Arguments:**
# 
#     *pcs*
#         PCs as the columns of an array.
# 
#     *field*
#         Spatial-temporal field with time as the first dimension.
# 
#     **Optional arguments:**
# 
#     *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:**
# 
#     *covariance_maps*
#         An array with the covariance maps along the first dimension.
# 
#     **Example:**
# 
#     Compute covariance maps for each PC::
# 
#         pcs = solver.pcs(pcscaling=1)
#         covariance_maps = covariance_maps(pcs, field)
# 
#     """
#     # Check PCs and fields for validity, flatten the arrays ready for the
#     # computation and remove the mean along the leading dimension.
#     pcs_cent, field_cent, out_shape = _check_flat_center(pcs, field)
#     # Set the divisor according to the specified delta-degrees of freedom.
#     div = np.float64(pcs_cent.shape[0] - ddof)
#     # Compute the covariance map, making sure it has the appropriate shape.
#     cov = (ma.dot(field_cent.T, pcs_cent).T / div).reshape(out_shape)
#     cov = ma.masked_invalid(cov)
#     return cov
# 
# Path: lib/eofs/tools/standard.py
# def correlation_map(pcs, field):
#     """Correlation maps for a set of PCs and a spatial-temporal field.
# 
#     Given an array where the columns are PCs (e.g., as output from
#     `~eofs.standard.Eof.pcs`) and an array containing spatial-temporal
#     data where the first dimension represents time, one correlation map
#     per PC is computed.
# 
#     The field must have the same temporal dimension as the PCs. Any
#     number of spatial dimensions (including zero) are allowed in the
#     field and there can be any number of PCs.
# 
#     **Arguments:**
# 
#     *pcs*
#         PCs as the columns of an array.
# 
#     *field*
#         Spatial-temporal field with time as the first dimension.
# 
#     **Returns:**
# 
#     *correlation_maps*
#         An array with the correlation maps along the first dimension.
# 
#     **Example:**
# 
#     Compute correlation maps for each PC::
# 
#         pcs = solver.pcs(pcscaling=1)
#         correlation_maps = correlation_maps(pcs, field)
# 
#     """
#     # Check PCs and fields for validity, flatten the arrays ready for the
#     # computation and remove the mean along the leading dimension.
#     pcs_cent, field_cent, out_shape = _check_flat_center(pcs, field)
#     # Compute the standard deviation of the PCs and the fields along the time
#     # dimension (the leading dimension).
#     pcs_std = pcs_cent.std(axis=0)
#     field_std = field_cent.std(axis=0)
#     # Set the divisor.
#     div = np.float64(pcs_cent.shape[0])
#     # Compute the correlation map.
#     cor = ma.dot(field_cent.T, pcs_cent).T / div
#     cor = ma.masked_invalid(cor)
#     cor /= ma.outer(pcs_std, field_std)
#     # Return the correlation with the appropriate shape.
#     return cor.reshape(out_shape)
# 
# Path: lib/eofs/tools/generic.py
# def covcor_dimensions(pc_dims, field_dims):
#     """
#     Extract the appropriate dimensions from a set of PCs and a field for
#     construction of covariance/correlation map dimensions.
# 
#     """
#     spatial_dims = field_dims[1:]
#     try:
#         pc_dim = pc_dims[1]
#     except IndexError:
#         pc_dim = None
#     covcor_dims = [d for d in [pc_dim] + spatial_dims if d is not None]
#     return covcor_dims


# Path: lib/eofs/tools/cdms.py
import cdms2
import numpy as np
from .standard import covariance_map as standard_covmap
from .standard import correlation_map as standard_cormap
from .generic import covcor_dimensions


    **Arguments:**

    *pcs*
        PCs in a `cdms2` variable.

    *field*
        Spatial-temporal field in a `cdms2` variable.

    **Optional arguments:**

    *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:**

    *covariance_maps*
        A `cdms2` variable containing the covariance maps.

    **Examples:**

    Compute covariance maps for each PC::

        pcs = eofobj.pcs(pcscaling=1)
        covmaps = covariance_map(pcs, field)

    """
    cov = standard_covmap(pcs.asma(), field.asma(), ddof=ddof)

    outdims = covcor_dimensions(pcs.getAxisList(), field.getAxisList())