Skip to content

Commit

Permalink
np.seterr(all='ignore') (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
prisae committed Jul 4, 2021
1 parent f317472 commit 0467d97
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linkcheck.yml
Expand Up @@ -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}
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/linux.yml
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos_windows.yml
Expand Up @@ -28,7 +28,7 @@ jobs:
fail-fast: false
matrix:
os: [macos, windows]
python: [3.8, ]
python: [3.9, ]

steps:

Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -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
-----------------------------------

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions empymod/kernel.py
Expand Up @@ -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']

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions empymod/scripts/fdesign.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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]_)."""

Expand All @@ -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]_)."""

Expand All @@ -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]_)."""

Expand All @@ -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]_).
Expand Down Expand Up @@ -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]_).
Expand Down Expand Up @@ -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]_)."""

Expand All @@ -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]_)."""

Expand All @@ -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]_)."""

Expand All @@ -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]_).
Expand Down Expand Up @@ -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]_).
Expand Down Expand Up @@ -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]_)."""

Expand All @@ -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]_)."""

Expand All @@ -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]_)."""

Expand All @@ -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]_)."""

Expand All @@ -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]_)."""

Expand All @@ -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]_)."""

Expand Down Expand Up @@ -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."""

Expand Down Expand Up @@ -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."""

Expand Down
5 changes: 3 additions & 2 deletions empymod/transform.py
Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions examples/reproducing/constable2006.py
Expand Up @@ -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)
Expand Down Expand Up @@ -110,6 +112,7 @@
plt.legend()

plt.show()
_ = np.seterr(**oldsettings)

###############################################################################
# Original Figure
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Expand Up @@ -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": ".",
Expand Down
5 changes: 3 additions & 2 deletions tests/test_fdesign.py
Expand Up @@ -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'][()]
Expand Down

0 comments on commit 0467d97

Please sign in to comment.