I have a daily netcdf dataset. I want to get each year maximum value, and return the season of the maximum value is in.
I have tried the xarray.DataArray.idxmax, below is the example, it can return the coordinate label of the maximum value along a dimension.
IN:
import xarray as xr
array = xr.DataArray(
[
[2.0, 1.0, 2.0, 0.0, -2.0],
[-4.0, np.NaN, 2.0, np.NaN, -2.0],
[np.NaN, np.NaN, 1.0, np.NaN, np.NaN],
],
dims=["y", "x"],
coords={"y": [-1, 0, 1], "x": np.arange(5.0) ** 2},
)
array.max(dim="x")
OUT:
<xarray.DataArray (y: 3)>
array([2., 2., 1.])
Coordinates:
* y (y) int64 -1 0 1
IN:
array.argmax(dim="x")
OUT:
<xarray.DataArray (y: 3)>
array([0, 2, 2])
Coordinates:
* y (y) int64 -1 0 1
I know xarray.DataArray.idxmax can return the day of the all years. but i can't turn this day to each year's season is. The most difficult thing for me is winter, because winter spans between in two years.
How can I achieve that?