Skip to content

Commit

Permalink
calculate symmetry using Mira et al
Browse files Browse the repository at this point in the history
  • Loading branch information
J.R. Angevaare committed Aug 7, 2023
1 parent cf6d957 commit 911fdac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
21 changes: 15 additions & 6 deletions optim_esm_tools/analyze/time_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,26 @@ def calculate_skewtest(ds, field=None):
return scipy.stats.skewtest(values, nan_policy='omit').pvalue


def calculate_historical_std(ds, field='std detrended', **kw):
def calculate_symmetry_test(ds, field=None):
import rpy_symmetry as rsym

values = get_values_from_data_set(ds, field)
return rsym.p_symmetry(values)


def calculate_historical_std(
ds, field='std detrended', field_pi_control='max jump', **kw
):
ds_hist = get_historical_ds(ds, **kw)
if ds_hist is None:
return None
mask = get_mask_from_global_mask(ds)
ds_hist_masked = oet.analyze.xarray_tools.mask_xr_ds(ds_hist, mask, drop=True)
assert (
ds[field].shape == ds_hist_masked[field].shape
), f'{ds[field].shape} != {ds_hist_masked[field].shape}'
cur = ds[field].values
his = ds_hist_masked[field].values
da = ds[field]
da_hist = ds_hist_masked[field_pi_control]
assert da.shape == da_hist.shape, f'{da.shape} != {da_hist.shape}'
cur = da.values
his = da_hist.values
isnnan = np.isnan(cur) | np.isnan(his)
cur = cur[~isnnan]
his = his[~isnnan]
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ pandas
tqdm
treelib
xarray
# Optional, required for some submodules:
# rpy_symmetry
1 change: 1 addition & 0 deletions requirements_tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ hypothesis-numpy
intake-esm
numba
pytest
rpy_symmetry
scikit-learn
scipy

0 comments on commit 911fdac

Please sign in to comment.