diff --git a/devito/types/basic.py b/devito/types/basic.py index 9f85f1273a..03e6c4f7c0 100644 --- a/devito/types/basic.py +++ b/devito/types/basic.py @@ -985,8 +985,9 @@ def __init_finalize__(self, *args, **kwargs): # Averaging mode for off the grid evaluation self._avg_mode = kwargs.get('avg_mode', 'arithmetic') - assert self._avg_mode in ['arithmetic', 'harmonic'], "Accepted avg_mode " \ - "values are 'arithmetic' or 'harmonic', invalid %s" % self._avg_mode + if self._avg_mode not in ['arithmetic', 'harmonic']: + raise ValueError("Invalid averaging mode_mode %s, accepted values are" + " arithmetic or harmonic" % self._avg_mode) @classmethod def __args_setup__(cls, *args, **kwargs): @@ -1152,10 +1153,13 @@ def _evaluate(self, **kwargs): return self # Base function - retval = 1 / self.function if self._avg_mode == 'harmonic' else self.function + if self._avg_mode == 'harmonic': + retval = 1 / self.function + else: + retval = self.function # Apply interpolation from inner most dim for d, i in self._grid_map.items(): - retval = retval.diff(d, deriv_order=0, fd_order=2, x0={d: i}).evaluate + retval = retval.diff(d, deriv_order=0, fd_order=2, x0={d: i}) if self._avg_mode == 'harmonic': retval = 1 / retval diff --git a/examples/seismic/acoustic/acoustic_example.py b/examples/seismic/acoustic/acoustic_example.py index 7d563d42d9..d45d935b8b 100644 --- a/examples/seismic/acoustic/acoustic_example.py +++ b/examples/seismic/acoustic/acoustic_example.py @@ -1,7 +1,7 @@ import numpy as np try: import pytest -except: +except ImportError: pass from devito.logger import info diff --git a/examples/seismic/elastic/elastic_example.py b/examples/seismic/elastic/elastic_example.py index 66b26540ae..fa1bc546a9 100644 --- a/examples/seismic/elastic/elastic_example.py +++ b/examples/seismic/elastic/elastic_example.py @@ -1,7 +1,7 @@ import numpy as np try: import pytest -except: +except ImportError: pass from devito import norm from devito.logger import info diff --git a/examples/seismic/tti/tti_example.py b/examples/seismic/tti/tti_example.py index de7d61eee9..d65a8ce88b 100644 --- a/examples/seismic/tti/tti_example.py +++ b/examples/seismic/tti/tti_example.py @@ -1,7 +1,7 @@ import numpy as np try: import pytest -except: +except ImportError: pass from devito import Function, smooth, norm, info, Constant diff --git a/examples/seismic/viscoacoustic/viscoacoustic_example.py b/examples/seismic/viscoacoustic/viscoacoustic_example.py index bd64922295..3b065d50f9 100755 --- a/examples/seismic/viscoacoustic/viscoacoustic_example.py +++ b/examples/seismic/viscoacoustic/viscoacoustic_example.py @@ -1,7 +1,7 @@ import numpy as np try: import pytest -except: +except ImportError: pass from devito.logger import info diff --git a/examples/seismic/viscoelastic/viscoelastic_example.py b/examples/seismic/viscoelastic/viscoelastic_example.py index 22de2e11d7..910462953a 100644 --- a/examples/seismic/viscoelastic/viscoelastic_example.py +++ b/examples/seismic/viscoelastic/viscoelastic_example.py @@ -1,7 +1,7 @@ import numpy as np try: import pytest -except: +except ImportError: pass from devito import norm