radarx.retrieve.nowcast_verification.crps#

radarx.retrieve.nowcast_verification.crps(forecast, observed, *, member_dim='member', fair=False, dim=None, n_threads=None, engine='auto')[source]#

Continuous ranked probability score of an ensemble forecast.

For the empirical distribution of the members x_i and the observation y the score is the energy form (Gneiting and Raftery 2007 [3], who show it equals the integral of the squared difference of the forecast and the observed distribution functions, the CRPS of Matheson and Winkler 1976 [1] and Hersbach 2000 [2]):

CRPS = mean_i |x_i - y| - 1/(2 m**2) sum_ij |x_i - x_j|

With the members sorted, the sum over all pairs is a weighted sum of the sorted values, so the cost is O(m log m) per point. With fair=True the second term is divided by 2 m (m - 1) instead, the score that does not depend on the size of the ensemble in expectation (Ferro 2014 [4]). A deterministic forecast (no member dimension) has the CRPS |x - y|, the absolute error.

NaN members are left out; a point is NaN where the observation is NaN or no member is valid.

Parameters:
  • forecast (xarray.DataArray) – Ensemble with a dimension member_dim, or a deterministic forecast.

  • observed (xarray.DataArray) – Observation, broadcast against the forecast.

  • member_dim (str, optional) – Name of the member dimension. Default "member".

  • fair (bool, optional) – Use the fair CRPS. Default False.

  • dim (str or sequence of str, optional) – Dimensions to average the score over (NaN left out). Default: none, the score of every point.

  • n_threads (int, optional) – Threads for the compiled kernel. Default: all cores.

  • engine ({"auto", "compiled", "numpy"}, optional) – Implementation to use.

Returns:

xarray.DataArray – The score (float32), in the units of the forecast, on the dimensions of the forecast without member_dim (less dim).

Raises:
  • ValueError – If dim names a dimension the forecast does not have, or fair=True for a forecast without members.

  • ImportError – If engine="compiled" and the kernel is not available.

Notes

Dask. This function computes the dask array: it sorts the members of every point. The input is loaded into memory and the result is held in memory.

See also

fss, brier_score

References

Examples

>>> score = radarx.retrieve.crps(ens, truth, dim=["x", "y"])