Skip to content

Commit

Permalink
Merge branch 'master' into coverage_upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
JoranAngevaare committed Aug 9, 2023
2 parents 2df5f4e + 7d5153d commit 052434f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions optim_esm_tools/analyze/region_finding.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from optim_esm_tools.analyze.clustering import build_cluster_mask
from optim_esm_tools.analyze.clustering import build_weighted_cluster
from optim_esm_tools.analyze.xarray_tools import mask_xr_ds, mask_to_reduced_dataset
from optim_esm_tools.analyze.time_statistics import TimeStatistics
from optim_esm_tools.plotting.plot import setup_map, _show

import numpy as np
Expand Down Expand Up @@ -75,6 +76,7 @@ class RegionExtractor:

criteria = (tipping_criteria.StdDetrended, tipping_criteria.MaxJump)
extra_opt = None
save_statistics = True

def __init__(
self,
Expand Down Expand Up @@ -108,6 +110,10 @@ def __init__(
self.save_kw = save_kw
self.variable = variable or self.data_set.attrs.get('variable_id', 'NO_VAR_ID!')

@property
def read_ds_kw(self):
return self.extra_opt.get('read_ds_kw', {})

@property
def log(self):
if self._logger is None:
Expand Down Expand Up @@ -202,6 +208,15 @@ def store_mask(self, mask, m_i, store_masks=True):
store_in_dir = os.path.join(save_in, 'masks')
os.makedirs(store_in_dir, exist_ok=True)
ds_masked = mask_to_reduced_dataset(self.data_set, mask)
kw = {
k: v
for k, v in self.read_ds_kw.items()
if k not in 'max_time min_time'.split()
}
statistics = TimeStatistics(
ds_masked, calculation_kwargs=dict(max_jump=kw)
).calculate_statistics()
ds_masked.attrs.update(statistics)
ds_masked.to_netcdf(
os.path.join(
store_in_dir,
Expand Down

0 comments on commit 052434f

Please sign in to comment.