Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: allow cache clearing from open_mdsdataset #342

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion xmitgcm/mds_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
from .file_utils import listdir, listdir_startswith, listdir_endswith, \
listdir_startsandendswith, listdir_fnmatch

from .file_utils import clear_cache as fu_clear_cache

# Python2/3 compatibility
if (sys.version_info > (3, 0)):
stringtypes = [str]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -148,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
Expand Down Expand Up @@ -184,6 +189,9 @@ def open_mdsdataset(data_dir, grid_dir=None,
else:
pass

if 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:
warnings.warn('levels has been set, nz will be ignored.')
Expand Down