earthkit.meteo.score.xarray.cosine_similarity

earthkit.meteo.score.xarray.cosine_similarity(fcst, obs, over, weights=None)

Calculates the cosine similarity between a forecast and observations.

Warning

Experimental API. This function may change or be removed without notice.

The cosine similarity is defined as:

\[\frac{\overline{f o}}{\sqrt{\overline{f^2}\ \overline{o^2}}}\]

where the averaging operator is defined as:

\[\overline{x} = \frac{\sum_{i=1}^N x_i w_i}{\sum_{i=1}^N w_i}\]

and

  • \(f_i\) is the forecast,

  • \(o_i\) are the observations,

  • \(w_i\) are the weights,

  • \(c\) is the cosine similarity.

Parameters:
  • fcst (xarray object) – The forecast xarray.

  • obs (xarray object) – The observations xarray.

  • over (str or list of str) – The dimension(s) over which to aggregate.

  • weights (xarray object, optional) – Weights to apply during aggregation. Default is None.

Returns:

The cosine similarity between the forecast and observations.

Return type:

xarray object