def detrend_dim(da, dim, deg=1):
"""detrend along a single dimension.""" # calculate polynomial coefficients p = da.polyfit(dim=dim, deg=deg, skipna=False) # evaluate trend fit = xr.polyval(da[dim], p.polyfit_coefficients) # remove the trend return da - fit Courtesy: Ryan Abernathy's tweet Example: SSTa_detrended = detrend_dim (SSTa, dim = 'time')
0 Comments
|
AuthorMahdi Hasan Archives
September 2023
Categories |