Skip to content

API reference

earthcarekit.stats

Statistical utility functions.


nan_diff_of_means

nan_diff_of_means(predictions, targets)

Difference between means of target and prediction (i.e., mean(target) - mean(prediction)).

Source code in earthcarekit/utils/statistics.py
def nan_diff_of_means(predictions: ArrayLike, targets: ArrayLike) -> float:
    """Difference between means of target and prediction (i.e., `mean(target) - mean(prediction)`)."""
    predictions = np.asarray(predictions)
    targets = np.asarray(targets)
    with warnings.catch_warnings():  # ignore warings about all-nan values
        warnings.simplefilter("ignore", category=RuntimeWarning)
        result = np.nanmean(targets) - np.nanmean(predictions)
    return result

nan_mae

nan_mae(predictions, targets)

Mean absolute error (MAE)

Source code in earthcarekit/utils/statistics.py
def nan_mae(predictions: ArrayLike, targets: ArrayLike) -> float:
    """Mean absolute error (MAE)"""
    predictions = np.asarray(predictions)
    targets = np.asarray(targets)
    with warnings.catch_warnings():  # ignore warings about all-nan values
        warnings.simplefilter("ignore", category=RuntimeWarning)
        result = np.nanmean(np.abs(targets - predictions))
    return result

nan_max

nan_max(a, axis=None)

Compute the maximum while ignoring NaNs.

Source code in earthcarekit/utils/statistics.py
def nan_max(a: ArrayLike, axis: int | None = None) -> NDArray | float:
    """Compute the maximum while ignoring NaNs."""
    with warnings.catch_warnings():  # ignore warings about all-nan values
        warnings.simplefilter("ignore", category=RuntimeWarning)
        a = np.asarray(a)
        if len(a) > 0:
            return np.nanmax(a, axis=axis)
        else:
            return np.nan

nan_mean

nan_mean(a, axis=None)

Compute the mean while ignoring NaNs.

Source code in earthcarekit/utils/statistics.py
def nan_mean(a: ArrayLike, axis: int | None = None) -> NDArray | float:
    """Compute the mean while ignoring NaNs."""
    with warnings.catch_warnings():  # ignore warings about all-nan values
        warnings.simplefilter("ignore", category=RuntimeWarning)
        a = np.asarray(a)
        return np.nanmean(a, axis=axis)

nan_mean_diff

nan_mean_diff(predictions, targets)

Mean of element-wise differences (i.e., mean(target - prediction)).

Source code in earthcarekit/utils/statistics.py
def nan_mean_diff(predictions: ArrayLike, targets: ArrayLike) -> float:
    """Mean of element-wise differences (i.e., `mean(target - prediction)`)."""
    predictions = np.asarray(predictions)
    targets = np.asarray(targets)
    with warnings.catch_warnings():  # ignore warings about all-nan values
        warnings.simplefilter("ignore", category=RuntimeWarning)
        result = np.nanmean(targets - predictions)
    return result

nan_min

nan_min(a, axis=None)

Compute the minimum while ignoring NaNs.

Source code in earthcarekit/utils/statistics.py
def nan_min(a: ArrayLike, axis: int | None = None) -> NDArray | float:
    """Compute the minimum while ignoring NaNs."""
    with warnings.catch_warnings():  # ignore warings about all-nan values
        warnings.simplefilter("ignore", category=RuntimeWarning)
        a = np.asarray(a)
        if len(a) > 0:
            return np.nanmin(a, axis=axis)
        else:
            return np.nan

nan_rmse

nan_rmse(predictions, targets)

Root mean squared error (RMSE)

Source code in earthcarekit/utils/statistics.py
def nan_rmse(predictions: ArrayLike, targets: ArrayLike) -> float:
    """Root mean squared error (RMSE)"""
    predictions = np.asarray(predictions)
    targets = np.asarray(targets)
    with warnings.catch_warnings():  # ignore warings about all-nan values
        warnings.simplefilter("ignore", category=RuntimeWarning)
        result = np.sqrt(np.nanmean((targets - predictions) ** 2))
    return result

nan_sem

nan_sem(a, axis=None)

Compute the standard error of the mean while ignoring NaNs.

Source code in earthcarekit/utils/statistics.py
def nan_sem(a: ArrayLike, axis: int | None = None) -> NDArray | float:
    """Compute the standard error of the mean while ignoring NaNs."""
    with warnings.catch_warnings():  # ignore warings about all-nan values
        warnings.simplefilter("ignore", category=RuntimeWarning)
        a = np.asarray(a)
        return np.nanstd(a, axis=axis) / np.sqrt(np.size(a, axis=0))

nan_std

nan_std(a, axis=None)

Compute the standard deviation while ignoring NaNs.

Source code in earthcarekit/utils/statistics.py
def nan_std(a: ArrayLike, axis: int | None = None) -> NDArray | float:
    """Compute the standard deviation while ignoring NaNs."""
    with warnings.catch_warnings():  # ignore warings about all-nan values
        warnings.simplefilter("ignore", category=RuntimeWarning)
        a = np.asarray(a)
        return np.nanstd(a, axis=axis)