-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
There are basically two convenient ways how to calculate trends in xarray:
- you vectorize
stats.linregressfunction usingxr.apply_ufunc:
from scipy import stats
x = np.arange(da.time.shape[0])
def new_linregress(y):
# Wrapper around scipy linregress to use in apply_ufunc
slope, intercept, r_value, p_value, std_err = stats.linregress(x, y)
return np.array([slope, intercept, r_value, p_value, std_err]
stats = xr.apply_ufunc(new_linregress, da,
input_core_dims=[['time']],
output_core_dims=[["parameter"]],
vectorize=True,
dask="parallelized",
output_dtypes=['float64'],
output_sizes={"parameter": 5},
)- or wait a while since polyfit should be available in the next release (Implementation of polyfit and polyval pydata/xarray#3733, AttributeError: 'DataArray' object has no attribute 'polyfit' pydata/xarray#3902). However, it will not allow calculating things such as p-values.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels