Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trend calculation in xarray #1

Open
kuchaale opened this issue Jun 12, 2020 · 0 comments
Open

Trend calculation in xarray #1

kuchaale opened this issue Jun 12, 2020 · 0 comments

Comments

@kuchaale
Copy link
Member

There are basically two convenient ways how to calculate trends in xarray:

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},
                      )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant