From 0467d97a8ce5e09476933bdbb84b40100e4f3168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dieter=20Werthm=C3=BCller?= Date: Sun, 4 Jul 2021 12:16:28 +0200 Subject: [PATCH] np.seterr(all='ignore') (#131) --- .github/workflows/linkcheck.yml | 2 +- .github/workflows/linux.yml | 18 +++++++++--------- .github/workflows/macos_windows.yml | 2 +- CHANGELOG.rst | 19 +++++++++++++++++++ README.rst | 2 +- empymod/kernel.py | 4 ++-- empymod/scripts/fdesign.py | 20 ++++++++++++++++++++ empymod/transform.py | 5 +++-- examples/reproducing/constable2006.py | 3 +++ setup.py | 8 ++++---- tests/test_fdesign.py | 5 +++-- 11 files changed, 66 insertions(+), 22 deletions(-) diff --git a/.github/workflows/linkcheck.yml b/.github/workflows/linkcheck.yml index be248243..7ce2d9f2 100644 --- a/.github/workflows/linkcheck.yml +++ b/.github/workflows/linkcheck.yml @@ -31,7 +31,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v2 with: - python-version: "3.8" + python-version: "3.9" - name: Install dependencies shell: bash -l {0} diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 49a31e9a..c32c4876 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -29,16 +29,10 @@ jobs: matrix: os: [ubuntu, ] # macos, windows] # Only Linux currently. case: - - python-version: 3.6 + - python-version: 3.7 name: minimal os: ubuntu - conda: "'scipy=1.0' 'numba=0.44'" - pip: "" - test: "" - - python-version: 3.6 - name: plain - os: ubuntu - conda: "'scipy<1.5' 'numba<0.50'" + conda: "'numpy=1.17' 'scipy=1.4' 'numba=0.47'" pip: "" test: "" - python-version: 3.7 @@ -65,6 +59,12 @@ jobs: conda: matplotlib pip: pytest-mpl scooby test: "--mpl" + - python-version: 3.9 + name: plain + os: ubuntu + conda: "" + pip: "" + test: "" - python-version: 3.9 name: full os: ubuntu @@ -177,7 +177,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v2 with: - python-version: "3.8" + python-version: "3.9" - name: Install dependencies run: | diff --git a/.github/workflows/macos_windows.yml b/.github/workflows/macos_windows.yml index 0fd53a86..ff76cf84 100644 --- a/.github/workflows/macos_windows.yml +++ b/.github/workflows/macos_windows.yml @@ -28,7 +28,7 @@ jobs: fail-fast: false matrix: os: [macos, windows] - python: [3.8, ] + python: [3.9, ] steps: diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 55f61672..f61d9c10 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -10,6 +10,25 @@ v2.0.x """""" +v2.1.2: Bugfix np.seterr(all='ignore') +-------------------------------------- + +**2021-07-04** + +- Bumped the minimum requirements to: + + - Python 3.7 + - NumPy 1.17 + - SciPy 1.4 + - Numba 0.47 + +- Legacy clean-up: The kernel of empymod used to switch off all NumPy errors + via ``np.seterr(all='ignore')``. That means that any script or library that + used empymod switched off all warnings from NumPy, which is not good. Since + empymod v2 this does make even less sense, as the entire kernel is jitted + with numba. *This setting is therefore removed.* + + v2.1.1: Bugfix azm/dip broadcasting ----------------------------------- diff --git a/README.rst b/README.rst index 7be3bc0f..de1f8abd 100644 --- a/README.rst +++ b/README.rst @@ -10,7 +10,7 @@ .. image:: https://img.shields.io/conda/v/conda-forge/empymod.svg :target: https://anaconda.org/conda-forge/empymod/ :alt: conda-forge -.. image:: https://img.shields.io/badge/python-3.6+-blue.svg +.. image:: https://img.shields.io/badge/python-3.7+-blue.svg :target: https://www.python.org/downloads/ :alt: Supported Python Versions .. image:: https://img.shields.io/badge/platform-linux,win,osx-blue.svg diff --git a/empymod/kernel.py b/empymod/kernel.py index 464a40a5..86cee200 100644 --- a/empymod/kernel.py +++ b/empymod/kernel.py @@ -33,8 +33,6 @@ import numba as nb from scipy import special # Only used for halfspace solution -np.seterr(all='ignore') - __all__ = ['wavenumber', 'angle_factor', 'fullspace', 'greenfct', 'reflections', 'fields', 'halfspace'] @@ -751,6 +749,7 @@ def angle_factor(angle, ab, msrc, mrec): # Analytical solutions +@np.errstate(all='ignore') def fullspace(off, angle, zsrc, zrec, etaH, etaV, zetaH, zetaV, ab, msrc, mrec): r"""Analytical full-space solutions in the frequency domain. @@ -924,6 +923,7 @@ def term(lGam, z_eH, z_eV, R, off, co1, co2): return gin +@np.errstate(all='ignore') def halfspace(off, angle, zsrc, zrec, etaH, etaV, freqtime, ab, signal, solution='dhs'): r"""Return frequency- or time-space domain VTI half-space solution. diff --git a/empymod/scripts/fdesign.py b/empymod/scripts/fdesign.py index 5124218c..6f9c7271 100644 --- a/empymod/scripts/fdesign.py +++ b/empymod/scripts/fdesign.py @@ -257,6 +257,7 @@ def rhs(r): # 1. PRINCIPAL FILTER DESIGNING ROUTINES +@np.errstate(all='ignore') def design(n, spacing, shift, fI, fC=False, r=None, r_def=(1, 1, 2), reim=None, cvar='amp', error=0.01, name=None, full_output=False, finish=False, save=True, path='filters', verb=2, plot=1): @@ -586,6 +587,7 @@ def load_filter(name, full=False, path='filters', filter_coeff=None): # # 2.a Public plotting routines for QC or direct use +@np.errstate(all='ignore') def plot_result(filt, full, prntres=True): r"""QC the inversion result. @@ -876,6 +878,7 @@ def __init__(self, name, lhs, rhs): # # 3.a Hankel J0 transform pairs +@np.errstate(all='ignore') def j0_1(a=1): r"""Hankel transform pair J0_1 ([Ande75]_).""" @@ -888,6 +891,7 @@ def rhs(b): return Ghosh('j0', lhs, rhs) +@np.errstate(all='ignore') def j0_2(a=1): r"""Hankel transform pair J0_2 ([Ande75]_).""" @@ -900,6 +904,7 @@ def rhs(b): return Ghosh('j0', lhs, rhs) +@np.errstate(all='ignore') def j0_3(a=1): r"""Hankel transform pair J0_3 ([GuSi97]_).""" @@ -912,6 +917,7 @@ def rhs(b): return Ghosh('j0', lhs, rhs) +@np.errstate(all='ignore') def j0_4(f=1, rho=0.3, z=50): r"""Hankel transform pair J0_4 ([ChCo82]_). @@ -939,6 +945,7 @@ def rhs(b): return Ghosh('j0', lhs, rhs) +@np.errstate(all='ignore') def j0_5(f=1, rho=0.3, z=50): r"""Hankel transform pair J0_5 ([ChCo82]_). @@ -968,6 +975,7 @@ def rhs(b): # # 3.b Hankel J1 transform pairs +@np.errstate(all='ignore') def j1_1(a=1): r"""Hankel transform pair J1_1 ([Ande75]_).""" @@ -980,6 +988,7 @@ def rhs(b): return Ghosh('j1', lhs, rhs) +@np.errstate(all='ignore') def j1_2(a=1): r"""Hankel transform pair J1_2 ([Ande75]_).""" @@ -992,6 +1001,7 @@ def rhs(b): return Ghosh('j1', lhs, rhs) +@np.errstate(all='ignore') def j1_3(a=1): r"""Hankel transform pair J1_3 ([Ande75]_).""" @@ -1004,6 +1014,7 @@ def rhs(b): return Ghosh('j1', lhs, rhs) +@np.errstate(all='ignore') def j1_4(f=1, rho=0.3, z=50): r"""Hankel transform pair J1_4 ([ChCo82]_). @@ -1031,6 +1042,7 @@ def rhs(b): return Ghosh('j1', lhs, rhs) +@np.errstate(all='ignore') def j1_5(f=1, rho=0.3, z=50): r"""Hankel transform pair J1_5 ([ChCo82]_). @@ -1060,6 +1072,7 @@ def rhs(b): # # 3.c Fourier sine transform pairs +@np.errstate(all='ignore') def sin_1(a=1, inverse=False): r"""Fourier sine transform pair sin_1 ([Ande75]_).""" @@ -1075,6 +1088,7 @@ def rhs(b): return Ghosh('sin', lhs, rhs) +@np.errstate(all='ignore') def sin_2(a=1, inverse=False): r"""Fourier sine transform pair sin_2 ([Ande75]_).""" @@ -1090,6 +1104,7 @@ def rhs(b): return Ghosh('sin', lhs, rhs) +@np.errstate(all='ignore') def sin_3(a=1, inverse=False): r"""Fourier sine transform pair sin_3 ([Ande75]_).""" @@ -1107,6 +1122,7 @@ def rhs(b): # # 3.d Fourier cosine transform pairs +@np.errstate(all='ignore') def cos_1(a=1, inverse=False): r"""Fourier cosine transform pair cos_1 ([Ande75]_).""" @@ -1122,6 +1138,7 @@ def rhs(b): return Ghosh('cos', lhs, rhs) +@np.errstate(all='ignore') def cos_2(a=1, inverse=False): r"""Fourier cosine transform pair cos_2 ([Ande75]_).""" @@ -1137,6 +1154,7 @@ def rhs(b): return Ghosh('cos', lhs, rhs) +@np.errstate(all='ignore') def cos_3(a=1, inverse=False): r"""Fourier cosine transform pair cos_3 ([Ande75]_).""" @@ -1243,6 +1261,7 @@ def lhs(k): # 4. NON-USER-FACING ROUTINES +@np.errstate(all='ignore') def _get_min_val(spaceshift, *params): r"""Calculate minimum resolved amplitude or maximum r.""" @@ -1325,6 +1344,7 @@ def _get_min_val(spaceshift, *params): return np.where(imin == 0, np.inf, min_val) +@np.errstate(all='ignore') def _calculate_filter(n, spacing, shift, fI, r_def, reim, name): r"""Calculate filter for this spacing, shift, n.""" diff --git a/empymod/transform.py b/empymod/transform.py index 62fc8ed4..13ac3bbf 100644 --- a/empymod/transform.py +++ b/empymod/transform.py @@ -1088,8 +1088,9 @@ def getweights(i, inpint): for k in range(i, 0, -1): aux1, aux2 = aux2, S[om, k-1] ddff = S[om, k] - aux2 - S[om, k-1] = np.where(np.abs(ddff) < np.finfo(np.double).tiny, - np.finfo(np.double).max, aux1 + 1/ddff) + with np.errstate(all='ignore'): + S[om, k-1] = np.where(np.abs(ddff) < np.finfo(np.double).tiny, + np.finfo(np.double).max, aux1 + 1/ddff) # The extrapolated result plus the first interval term extrap[om, i-1] = S[om, np.mod(i, 2)] + EM0[om] diff --git a/examples/reproducing/constable2006.py b/examples/reproducing/constable2006.py index 6a9ed89c..fc8568c2 100644 --- a/examples/reproducing/constable2006.py +++ b/examples/reproducing/constable2006.py @@ -61,6 +61,8 @@ plt.figure(figsize=(9, 13)) plt.subplots_adjust(wspace=.3, hspace=.3) +oldsettings = np.geterr() +_ = np.seterr(all='ignore') # Radial amplitude plt.subplot(321) @@ -110,6 +112,7 @@ plt.legend() plt.show() +_ = np.seterr(**oldsettings) ############################################################################### # Original Figure diff --git a/setup.py b/setup.py index b4f6e0fd..2d074d3a 100644 --- a/setup.py +++ b/setup.py @@ -26,15 +26,15 @@ classifiers=[ "Development Status :: 5 - Production/Stable", "License :: OSI Approved :: Apache Software License", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", ], - python_requires=">=3.6", + python_requires=">=3.7", install_requires=[ - "scipy>=1.0.0", - "numba>=0.44", + "numpy>=1.17", + "scipy>=1.4", + "numba>=0.47", ], use_scm_version={ "root": ".", diff --git a/tests/test_fdesign.py b/tests/test_fdesign.py index e38c75ef..0a4c1063 100644 --- a/tests/test_fdesign.py +++ b/tests/test_fdesign.py @@ -47,8 +47,9 @@ def test_design(): # only affects the edge-cases, not the best result we are looking for. # However, we have to limit the following comparison; we check that at # least 50% are within a relative error of 0.1%. - rate = np.sum(np.abs((out1[3] - dat1[2][3])/dat1[2][3]) < 1e-3) - assert rate > out1[3].size/2 + with np.errstate(all='ignore'): + rate = np.sum(np.abs((out1[3] - dat1[2][3])/dat1[2][3]) < 1e-3) + assert rate > out1[3].size/2 # 2. Specific model with only one spacing/shift dat2 = DATA['case2'][()]