From daef11467da92dfd6dfa1d861ffc3c8aefe94e30 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Thu, 6 Mar 2025 13:29:55 -0800 Subject: [PATCH 1/3] ENH: allow cache clearing from open_mdsdataset --- xmitgcm/mds_store.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xmitgcm/mds_store.py b/xmitgcm/mds_store.py index ea3730f..c21dd0f 100644 --- a/xmitgcm/mds_store.py +++ b/xmitgcm/mds_store.py @@ -32,6 +32,8 @@ from .file_utils import listdir, listdir_startswith, listdir_endswith, \ listdir_startsandendswith, listdir_fnmatch +from .file_utils import clear_cache as futil.clear_cache + # Python2/3 compatibility if (sys.version_info > (3, 0)): stringtypes = [str] @@ -59,7 +61,7 @@ def open_mdsdataset(data_dir, grid_dir=None, ignore_unknown_vars=False, default_dtype=None, nx=None, ny=None, nz=None, llc_method="smallchunks", extra_metadata=None, - extra_variables=None): + extra_variables=None, clear_cache=False): """Open MITgcm-style mds (.data / .meta) file output as xarray datset. Parameters @@ -184,6 +186,9 @@ def open_mdsdataset(data_dir, grid_dir=None, else: pass + if clear_cache: + futil.clear_cache() + # if levels s a slice or a list, a subset of levels is needed if levels is not None and nz is not None: warnings.warn('levels has been set, nz will be ignored.') From 13cb7cb4a8c548b071bcb962052784920d1fef37 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Thu, 6 Mar 2025 13:33:17 -0800 Subject: [PATCH 2/3] ENH: allow cache clearing from open_mdsdataset --- xmitgcm/mds_store.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xmitgcm/mds_store.py b/xmitgcm/mds_store.py index c21dd0f..b69f336 100644 --- a/xmitgcm/mds_store.py +++ b/xmitgcm/mds_store.py @@ -150,6 +150,9 @@ def open_mdsdataset(data_dir, grid_dir=None, standard_name='Sensitivity_to_theta', long_name='Sensitivity of cost function to theta', units='[J]/degC')) ) + clear_cache: bool, optional + Clear the cache of filenames for reading data files. This is useful + when the contents of the data directory are changing (e.g. during a model run). Returns From c6f2557e077f1f29941c7fab8b8ed9eb2fc63e41 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Sat, 15 Mar 2025 14:58:28 -0700 Subject: [PATCH 3/3] FIX: make syntax of import work --- xmitgcm/mds_store.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmitgcm/mds_store.py b/xmitgcm/mds_store.py index b69f336..3efa411 100644 --- a/xmitgcm/mds_store.py +++ b/xmitgcm/mds_store.py @@ -32,7 +32,7 @@ from .file_utils import listdir, listdir_startswith, listdir_endswith, \ listdir_startsandendswith, listdir_fnmatch -from .file_utils import clear_cache as futil.clear_cache +from .file_utils import clear_cache as fu_clear_cache # Python2/3 compatibility if (sys.version_info > (3, 0)): @@ -190,7 +190,7 @@ def open_mdsdataset(data_dir, grid_dir=None, pass if clear_cache: - futil.clear_cache() + fu_clear_cache() # if levels s a slice or a list, a subset of levels is needed if levels is not None and nz is not None: