radarx.retrieve.nowcast_verification.fss#

radarx.retrieve.nowcast_verification.fss(forecast, observed, threshold, scale, *, dim=None, edge='inside', x='x', y='y', n_threads=None, engine='auto')[source]#

Fractions skill score of a forecast for a threshold and a scale.

For every cell the fraction of cells at or above threshold in the square neighbourhood of side scale is computed for the forecast (F) and the observation (O). The score compares the fractions (Roberts and Lean 2008 [1]):

FSS = 1 - sum (F - O)**2 / (sum F**2 + sum O**2)

It is 1 for a perfect forecast, 0 when the forecast and the observed events never overlap in the neighbourhoods, and rises with the scale for a displaced forecast (Ebert 2008 [2]). The sums run over the cells of the grid and over the dimensions in dim: the numerators and denominators are added before the division, so a time series is scored as a whole, not as the mean of daily scores.

Cells where the forecast or the observation is NaN are left out. The side of the neighbourhood is rounded to an odd number of cells. edge decides how the fraction is taken at the border of the grid and next to missing cells: "inside" (default) divides by the number of valid cells of the neighbourhood, "zero" by the whole neighbourhood, so that what lies outside counts as no event. The fractions come from a summed-area table (a compiled kernel with a NumPy equivalent), so the cost does not depend on scale.

Parameters:
  • forecast, observed (xarray.DataArray) – Fields on (y, x), possibly with more dimensions (lead_time, member, …). observed is broadcast against forecast. Their x and y coordinates are evenly spaced, in metres.

  • threshold (float) – Event threshold, in the units of the fields.

  • scale (float or sequence of float) – Side of the neighbourhood in metres. A sequence adds a scale dimension to the result.

  • dim (str or sequence of str, optional) – Dimensions (besides x and y) over which the sums run, e.g. "time". Default: none, one score for each of the other dimensions.

  • edge ({"inside", "zero"}, optional) – Treatment of the border. Default "inside".

  • x, y (str, optional) – Names of the horizontal coordinates. Default "x" and "y".

  • 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, dimensionless, NaN where no cell has an event in either field), on the dimensions of forecast that are not reduced, with a scale dimension for a sequence of scales.

Raises:
  • ValueError – For an unknown edge, a negative scale, a grid that is not regular or fields that do not share their dimensions.

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

Notes

Dask. This function computes the dask array: it needs the whole fields to build the neighbourhoods. The input is loaded into memory and the result is held in memory.

References

Examples

>>> score = radarx.retrieve.fss(ens, truth, 35.0, [5e3, 20e3])