diff --git a/optim_esm_tools/analyze/cmip_handler.py b/optim_esm_tools/analyze/cmip_handler.py index 6222de4..a91a884 100644 --- a/optim_esm_tools/analyze/cmip_handler.py +++ b/optim_esm_tools/analyze/cmip_handler.py @@ -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', ) diff --git a/optim_esm_tools/analyze/region_finding.py b/optim_esm_tools/analyze/region_finding.py index bd3476f..dc6d909 100644 --- a/optim_esm_tools/analyze/region_finding.py +++ b/optim_esm_tools/analyze/region_finding.py @@ -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( @@ -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')