def mean(X, ignore_nan=False, X_thr=None):
    """
    Compute the mean value from a forecast ensemble field.

    Parameters
    ----------
    X: array_like
        Array of shape (k, m, n) containing a k-member ensemble of forecast
        fields of shape (m, n).
    ignore_nan: bool
        If True, ignore nan values.
    X_thr: float
        Optional threshold for computing the ensemble mean.
        Values below **X_thr** are ignored.

    Returns
    -------
    out: ndarray
        Array of shape (m, n) containing the ensemble mean.
    """

    X = np.asanyarray(X)
    X_ndim = X.ndim

    if X_ndim > 3 or X_ndim <= 1:
        raise Exception(
            "Number of dimensions of X should be 2 or 3." + "It was: {}".format(X_ndim)
        )
    elif X.ndim == 2:
        X = X[None, ...]

    if ignore_nan or X_thr is not None:
        if X_thr is not None:
            X = X.copy()
            X[X < X_thr] = np.nan

        return np.nanmean(X, axis=0)
    else:
        return np.mean(X, axis=0)
Compute the mean value from a forecast ensemble field.

Parameters
----------
X: array_like
Array of shape (k, m, n) containing a k-member ensemble of forecast
fields of shape (m, n).
ignore_nan: bool
If True, ignore nan values.
X_thr: float
Optional threshold for computing the ensemble mean.
Values below **X_thr** are ignored.

Returns
-------
out: ndarray
Array of shape (m, n) containing the ensemble mean.
pysteps/postprocessing/ensemblestats.py