From 79aa763236c68fd94b040a0f2da812a3bdf07356 Mon Sep 17 00:00:00 2001 From: github action <5659125+larsbuntemeyer@users.noreply.github.com> Date: Wed, 21 Dec 2022 20:33:24 +0100 Subject: [PATCH 1/2] added xarray_open_kwargs keyword --- python/cdo.py | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/python/cdo.py b/python/cdo.py index ce7ad0a..b33497c 100644 --- a/python/cdo.py +++ b/python/cdo.py @@ -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']) @@ -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 {{{ @@ -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): @@ -598,7 +603,6 @@ def __call__(self, *args, **kwargs): return outputs def __getattr__(self, method_name): # main method-call handling for Cdo-objects {{{ - if ((method_name in self.__dict__) or (method_name in list(self.operators.keys())) or (method_name in self.AliasOperators)): if self.debug: @@ -768,7 +772,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: @@ -782,7 +786,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 From e4cb2fc4609f8a7f97466c18e9c8365d72add87e Mon Sep 17 00:00:00 2001 From: github action <5659125+larsbuntemeyer@users.noreply.github.com> Date: Wed, 21 Dec 2022 21:05:13 +0100 Subject: [PATCH 2/2] fix line --- python/cdo.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/cdo.py b/python/cdo.py index b33497c..b9cbcf2 100644 --- a/python/cdo.py +++ b/python/cdo.py @@ -603,6 +603,7 @@ def __call__(self, *args, **kwargs): return outputs def __getattr__(self, method_name): # main method-call handling for Cdo-objects {{{ + if ((method_name in self.__dict__) or (method_name in list(self.operators.keys())) or (method_name in self.AliasOperators)): if self.debug: