Angular data#
Sometimes we are interested in evaluating angular forecasts, such as a wind direction forecast against wind direction observations.
Several metrics in scores
can be used to evaluate angular forecasts expressed in degrees. If the is_angular
argument is available in a metric, then that function can be used with angular data and it will handle the discontinuity that occurs between 360 degrees and 0. Simply set is_angular=True
. It does this by calculating the length of the smaller of the two explementary angles between the two sources of data (e.g., forecast and observed).
If your data is in radians, you can convert it to degrees my multiplying your data by 180/pi (you can use numpy.pi
).
[11]:
from scores.continuous import mae
import numpy as np
import xarray as xr
np.random.seed(0) # set the seed to make notebook reproducible
[2]:
fcst = xr.DataArray(
data=np.random.random_sample((1000, 1000)) * 360,
dims=["space", "time"],
coords=[np.arange(0, 1000), np.arange(0, 1000)]
)
obs = xr.DataArray(
data=np.random.random_sample((1000, 1000)) * 360,
dims=["space", "time"],
coords=[np.arange(0, 1000), np.arange(0, 1000)]
)
Let’s calculate MAE with angular=True
[7]:
mae(fcst, obs, is_angular=True)
[7]:
<xarray.DataArray ()> array(89.9521687)
Since the forecast and observed values are random taken from a uniform distribution on the interval [0, 360), we would expect the MAE to be around 90. Let’s see what happens when we don’t use the is_angular=True
.
[4]:
mae(fcst, obs)
[4]:
<xarray.DataArray ()> array(120.03938622)
The value is far higher, since we didn’t use the smaller length of the two explementary angle.
Other things to try:#
Try out some of the other metrics set up to work with angular data including MSE, RMSE, and the Flip-Flop Index.
Read up on the Circular Flip-Flop Index which handles angular data. Griffiths, D., Loveday, N., Price, B., Foley, M. and McKelvie, A., 2021. Circular Flip-Flop Index: quantifying revision stability of forecasts of direction. Journal of Southern Hemisphere Earth Systems Science, 71(3), pp.266-271.