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_iand the observationythe 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=Truethe second term is divided by2 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 dimensionmember_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 (
stror sequence ofstr, 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 withoutmember_dim(lessdim).- Raises:
ValueError – If
dimnames a dimension the forecast does not have, orfair=Truefor 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
References
Examples
>>> score = radarx.retrieve.crps(ens, truth, dim=["x", "y"])