Skip to content

Commit

Permalink
Merge 360262b into 3411014
Browse files Browse the repository at this point in the history
  • Loading branch information
JoranAngevaare committed Jun 21, 2023
2 parents 3411014 + 360262b commit 1c2a264
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
4 changes: 2 additions & 2 deletions optim_esm_tools/analyze/cmip_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ def _name_cache_file(
path = os.path.join(
base,
f'{variable_of_interest}'
f'_s{min_time if min_time else ""}'
f'_e{max_time if max_time else ""}'
f'_s{tuple(min_time) if min_time else ""}'
f'_e{tuple(max_time) if max_time else ""}'
f'_ma{_ma_window}'
f'_optimesm_v{version}.nc',
)
Expand Down
41 changes: 19 additions & 22 deletions optim_esm_tools/analyze/region_finding.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,9 @@ def get_masks(self, percentiles=99, read_ds_kw=None) -> dict:
return masks, clusters

@apply_options
def find_historical(self, match_to='piControl', look_back_extra=1):
def find_historical(
self, match_to='piControl', look_back_extra=1, query_updates=None
):
from optim_esm_tools.config import config

base = os.path.join(
Expand All @@ -436,26 +438,21 @@ def find_historical(self, match_to='piControl', look_back_extra=1):
raise NotImplementedError()
search['experiment_id'] = match_to

first_try = oet.cmip_files.find_matches.find_matches(base, **search)
if first_try:
return first_try
self.log.warning('No results at first try, retying with any variant_label')
search.update(
dict(
variant_label='*',
)
)
if query_updates is None:
query_updates = [
dict(),
dict(variant_label='*'),
dict(grid='*'),
dict(version='*'),
]

second_try = oet.cmip_files.find_matches.find_matches(base, **search)
if second_try:
return second_try
self.log.warning('No results at second try, retying with any version')
search.update(
dict(
version='*',
)
)
third_try = oet.cmip_files.find_matches.find_matches(base, **search)
if third_try:
return third_try
for try_n, update_query in enumerate(query_updates):
if try_n:
self.log.warning(
f'No results after {try_n} try, retying with {update_query}'
)
search.update(update_query)
this_try = oet.cmip_files.find_matches.find_matches(base, **search)
if this_try:
return this_try
raise RuntimeError(f'Looked for {search}, in {base} found nothing')

0 comments on commit 1c2a264

Please sign in to comment.