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

xarray open kwargs #48

Open
wants to merge 2 commits into
base: maintenance-1.5.x
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
37 changes: 21 additions & 16 deletions python/cdo.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ def __init__(self,
logFile=StringIO(),
cmd=[],
options=[],
silent=True):
silent=True,
xarray_open_kwargs=None):

if 'CDO' in os.environ and os.path.isfile(os.environ['CDO']):
self.CDO = which(os.environ['CDO'])
Expand All @@ -187,20 +188,23 @@ def __init__(self,
self._cmd = cmd
self._options = options

self.operators = self.__getOperators()
self.noOutputOperators = [op for op in self.operators.keys() if 0 == self.operators[op]]
self.returnNoneOnError = returnNoneOnError
self.tempStore = CdoTempfileStore(dir = tempdir)
self.forceOutput = forceOutput
self.env = env
self.debug = True if 'DEBUG' in os.environ else debug
self.silent = silent
self.operators = self.__getOperators()
self.noOutputOperators = [op for op in self.operators.keys() if 0 == self.operators[op]]
self.returnNoneOnError = returnNoneOnError
self.tempStore = CdoTempfileStore(dir = tempdir)
self.forceOutput = forceOutput
self.env = env
self.debug = True if 'DEBUG' in os.environ else debug
self.silent = silent
self.xarray_open_kwargs = xarray_open_kwargs
if self.xarray_open_kwargs is None:
self.xarray_open_kwargs = {}

# optional IO libraries for additional return types {{{
self.hasNetcdf = False
self.hasXarray = False
self.cdf = None
self.xa_open = None
self.hasNetcdf = False
self.hasXarray = False
self.cdf = None
self.xa_open = None
self.__loadOptionalLibs()

self.logging = logging # internal logging {{{
Expand Down Expand Up @@ -256,7 +260,8 @@ def __get__(self, instance, owner):
instance.logFile,
instance._cmd + ['-' + name],
instance._options,
instance.silent)
instance.silent,
instance.xarray_open_kwargs)

# from 1.9.6 onwards CDO returns 1 of diff* finds a difference
def __exit_success(self,operatorName):
Expand Down Expand Up @@ -768,7 +773,7 @@ def readXArray(self, ifile=None, varname=None):
print("Could not load XArray")
six.raise_from(ImportError,None)

dataSet = self.xa_open(ifile)
dataSet = self.xa_open(ifile, **self.xarray_open_kwargs)
try:
return dataSet[varname]
except:
Expand All @@ -782,7 +787,7 @@ def readXDataset(self, ifile=None):
print("Could not load XArray")
six.raise_from(ImportError,None)

return self.xa_open(ifile)
return self.xa_open(ifile, **self.xarray_open_kwargs)

# internal helper methods:
# return internal cdo.py version
Expand Down