From b7496e0b3d67b5c3c7054d6499c3fc6201507b8d Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Wed, 6 Oct 2021 09:37:15 -0300 Subject: [PATCH] PYTHON: Make sure dataset() accepts maxlev > 9. Signed-off-by: Grzegorz Kowal --- python/amunpy/src/amunpy/amun.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/python/amunpy/src/amunpy/amun.py b/python/amunpy/src/amunpy/amun.py index 477df98..6bf7aa9 100644 --- a/python/amunpy/src/amunpy/amun.py +++ b/python/amunpy/src/amunpy/amun.py @@ -899,7 +899,7 @@ class Amun: return dset - def dataset(self, dataset_name, extent=None, maxlev=-1, shrink=1, \ + def dataset(self, dataset_name, extent=None, maxlev=None, shrink=1, \ interpolation='rebin', order=3, progress=False): """ Function returns dataset of the requested variable resampled to @@ -933,13 +933,14 @@ class Amun: if any(slo > dup) or any(sup < dlo) or any (slo >= sup): raise Exception("Wrong order of the dimensions in the argument 'extent'!") - if isinstance(maxlev,int): - if 1 <= maxlev <= self.attributes['maxlev']: - shrink = 2**(self.attributes['maxlev']-maxlev) - elif maxlev > self.attributes['maxlev']: - raise Exception("Argument 'maxlev' should be between 1 and {}.\n".format(self.attributes['maxlev'])) - else: - raise Exception("Argument 'maxlev' must be an integer between 1 and {}.\n".format(self.attributes['maxlev'])) + if maxlev != None: + if isinstance(maxlev, (int, np.int32)): + if 1 <= maxlev <= self.attributes['maxlev']: + shrink = 2**(self.attributes['maxlev']-maxlev) + elif maxlev > self.attributes['maxlev']: + raise Exception("Argument 'maxlev' should be between 1 and {}.\n".format(self.attributes['maxlev'])) + else: + raise Exception("Argument 'maxlev' must be an integer between 1 and {}.\n".format(self.attributes['maxlev'])) bm = np.array([ self.attributes['ncells'] ]*self.attributes['ndims'])