def linear_trend(x, eps=0.001, alpha=0.01): #pf = np.polyfit(np.arange(len(x)), x, 1) pf, slope, int, p, ind = mk.test(np.arange(len(x)),x.squeeze().values, eps=eps, alpha=alpha, Ha='upordown') # we need to return a dataarray or else xarray's groupby won't be happy if ind == 1: issig = slope else: issig = np.nan return issig
def linear_trend(x, eps=0.001, alpha=0.01): #pf = np.polyfit(np.arange(len(x)), x, 1) pf, slope, int, p, ind = mk.test(np.arange(len(x)), x.squeeze().values, eps=eps, alpha=alpha, Ha='upordown') # we need to return a dataarray or else xarray's groupby won't be happy if ind == 1: issig = slope else: issig = np.nan return issig
def linear_trend_mk(x, eps=0.001, alpha=0.01, nb_missing=None): #pf = np.polyfit(np.arange(len(x)), x, 1) pf, slope, int, p, ind = mk.test(np.arange(len(x)),x.squeeze().values, eps=eps, alpha=alpha, Ha='upordown') # we need to return a dataarray or else xarray's groupby won't be happy if nb_missing is not None: if np.nansum(x.values==0)>=nb_missing: p = np.nan slope = np.nan ind = 0 ds = xr.Dataset() ds['slope'] = xr.DataArray(slope,) ds['pval'] = xr.DataArray(p, ) ds['ind'] = xr.DataArray(ind) return ds
def linear_trend_mk(x, eps=0.001, alpha=0.01): #pf = np.polyfit(np.arange(len(x)), x, 1) pf, slope, int, p, ind = mk.test(np.arange(len(x)), x.squeeze().values, eps=eps, alpha=alpha, Ha='upordown') # we need to return a dataarray or else xarray's groupby won't be happy if ind == 1: issig = slope else: issig = np.nan if np.nansum(x.values == 0) >= 10: p = np.nan ds = xr.Dataset() ds['slope'] = xr.DataArray(issig, ) ds['pval'] = xr.DataArray(p, ) return ds