Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NumPy v2 #221

Merged
merged 13 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,30 @@ jobs:
matrix:
os: [ubuntu, ] # macos, windows] # Only Linux currently.
case:
- python-version: "3.9"
name: minimal
os: ubuntu
conda: "'numba=0.53' 'scipy=1.9' scooby libdlf"
test: ""
- python-version: "3.10"
name: plain
name: minimal
os: ubuntu
conda: "numba scipy scooby libdlf"
conda: "numba 'scipy=1.10' scooby libdlf"
test: ""
- python-version: "3.10"
name: full
os: ubuntu
conda: "numba scipy scooby libdlf matplotlib pytest-mpl"
test: "--mpl"
- python-version: "3.11"
name: plain
os: ubuntu
conda: "numba scipy scooby libdlf"
conda: "numba 'scipy>=1.10' scooby libdlf"
test: ""
- python-version: "3.11"
name: full
os: ubuntu
conda: "numba scipy scooby libdlf matplotlib pytest-mpl"
conda: "numba 'scipy>=1.10' scooby libdlf matplotlib pytest-mpl"
test: "--mpl"
- python-version: "3.12"
name: plain
os: ubuntu
conda: "numba scipy scooby libdlf"
conda: "numba 'scipy>=1.10' scooby libdlf"
test: ""
- python-version: "3.12"
name: full
os: ubuntu
conda: "numba scipy scooby libdlf matplotlib pytest-mpl"
conda: "numba 'scipy>=1.10' scooby libdlf matplotlib pytest-mpl"
test: "--mpl"

env:
Expand Down Expand Up @@ -125,7 +115,8 @@ jobs:
- name: Test with pytest
shell: bash -l {0}
run: |
python -m pip install .
python -m pip install --upgrade pip
make install
cp ./tests/matplotlibrc ./.
pytest --cov=empymod ${{ matrix.case.test }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ jobs:
- name: Test with pytest
shell: bash -l {0}
run: |
python -m pip install .
make install
pytest
25 changes: 22 additions & 3 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,34 @@ v2.3.x
""""""


latest
------
v2.3.2: NumPy v2
----------------

**2024-10-09**

The code is now compatible with NumPy v2.

- Gallery Update Part I:

- Update for Jupyterlab (ipympl/widget)
- Replaced implicit by explicit pyplots
- Use by default a positiv z-upwards coordinate system
- Part I: frequency domain; reproducing; published

- Bumped the minimum requirements to:

- Python 3.9
- SciPy 1.10
- Numba, libdlf, scooby (without minimum version)

- Maintenance:

- Testing: dropped Python 3.9 (Python 3.13 not added yet).
- Update for NumPy v2: mainly ``np.infty -> np.inf``,
``np.float_ -> np.float64``.
- Some fixes to address warnings regarding the deprecated conversion of an
array with ndim > 0 to a scalar.


v2.3.1: Julia wrapper
---------------------
Expand Down Expand Up @@ -58,7 +77,7 @@ dependency.
- Maintenance:

- Bumped the minimum requirements to:

- Python 3.9
- SciPy 1.9
- Numba 0.53
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ help:
@echo ""

install:
python -m pip install --no-build-isolation --no-deps -e .
python -m pip install --no-build-isolation --use-pep517 --no-deps -e .

dev-install:
python -m pip install -r requirements-dev.txt && python -m pip install --no-build-isolation --no-deps -e .
python -m pip install -r requirements-dev.txt && python -m pip install --no-build-isolation --use-pep517 --no-deps -e .

.ONESHELL:
pytest:
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
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.8+-blue.svg
.. image:: https://img.shields.io/badge/python-3.10+-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
8 changes: 6 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@
# is responsible for resolving them.
linkcheck_ignore = [
"https://doi.org/*", # DOIs should be permanent (their entire purpose)
"https://conahcyt.mx", # Check fails; check later again!
"https://software.seg.org", # Page cannot be reached.
# Pages which fail with linkcheck, but can be reached manually
# How do we check these?
"https://conahcyt.mx",
"https://software.seg.org",
"https://wiki.seg.org/wiki", # Requires human-check
"https://www.cambridge.org/9781107058620",
]
4 changes: 3 additions & 1 deletion docs/dev/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ Good places to get started is to browse the existing issues, check out the
roadmap, or have a look at any open PR:

- `Issues <https://github.com/emsig/empymod/issues>`_;
- `Roadmap-project <https://github.com/emsig/empymod/projects/3>`_;
- `PR's <https://github.com/emsig/empymod/pulls>`_.

.. GOT DELETED BY GITHUB
`Roadmap-project <https://github.com/emsig/empymod/projects/3>`_;

There are various different ways to get in touch, see
`emsig.xyz#contributing-contact <https://emsig.xyz/#contributing-contact>`_.

Expand Down
2 changes: 1 addition & 1 deletion docs/manual/references.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ References
power spectrum: Monthly Notices of the Royal Astronomical Society, 312,
pages 257--284; DOI: `10.1046/j.1365-8711.2000.03071.x
<https://doi.org/10.1046/j.1365-8711.2000.03071.x>`_; Website of FFTLog:
`casa.colorado.edu/~ajsh/FFTLog <http://casa.colorado.edu/~ajsh/FFTLog>`_.
`jila.colorado.edu/~ajsh/FFTLog <https://jila.colorado.edu/~ajsh/FFTLog>`_.
.. [HuTS15] Hunziker, J., J. Thorbecke, and E. Slob, 2015, The electromagnetic
response in a layered vertical transverse isotropic medium: A new look at an
old problem: Geophysics, 80(1), F1--F18; DOI: `10.1190/geo2013-0411.1
Expand Down
4 changes: 2 additions & 2 deletions docs/manual/transforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ FFTLog

FFTLog is the logarithmic analogue to the Fast Fourier Transform FFT originally
proposed by [Talm78]_. The code used by ``empymod`` was published in Appendix B
of [Hami00]_ and is publicly available at `casa.colorado.edu/~ajsh/FFTLog
<http://casa.colorado.edu/~ajsh/FFTLog>`_. From the ``FFTLog``-website:
of [Hami00]_ and is publicly available at `jila.colorado.edu/~ajsh/FFTLog
<https://jila.colorado.edu/~ajsh/FFTLog>`_. From the ``FFTLog``-website:

*FFTLog is a set of fortran subroutines that compute the fast Fourier or Hankel
(= Fourier-Bessel) transform of a periodic sequence of logarithmically spaced
Expand Down
8 changes: 4 additions & 4 deletions empymod/scripts/fdesign.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,10 +638,10 @@ def plot_result(filt, full, prntres=True):
else: # (c) if several spacing and several shift values
field = np.ma.masked_where(np.isinf(minfield), field)
plt.pcolormesh(shift, spacing, field, cmap=cmap, shading='nearest')
plt.xlim([shift[0]-np.diff(shift[:2])/2,
shift[-1]+np.diff(shift[-2:])/2])
plt.ylim([spacing[0]-np.diff(spacing[:2])/2,
spacing[-1]+np.diff(spacing[-2:])/2])
plt.xlim([shift[0]-np.diff(shift[:2])[0]/2,
shift[-1]+np.diff(shift[-2:])[0]/2])
plt.ylim([spacing[0]-np.diff(spacing[:2])[0]/2,
spacing[-1]+np.diff(spacing[-2:])[0]/2])
plt.ylabel('Spacing')
plt.xlabel('Shift')
plt.colorbar()
Expand Down
2 changes: 1 addition & 1 deletion empymod/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ def fourier_fftlog(fEM, time, freq, ftarg):

FFTLog is the logarithmic analogue to the Fast Fourier Transform FFT.
FFTLog was presented in Appendix B of [Hami00]_ and published at
https://casa.colorado.edu/~ajsh/FFTLog.
https://jila.colorado.edu/~ajsh/FFTLog.

This function uses a simplified version of `pyfftlog`, which is a
python-version of `FFTLog`. For more details regarding `pyfftlog` see
Expand Down
18 changes: 9 additions & 9 deletions empymod/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ def check_model(depth, res, aniso, epermH, epermV, mpermH, mpermV, xdirect,
Returns
-------
depth : array
Depths of layer interfaces, adds -infty at beginning if not present.
Depths of layer interfaces, adds -inf at beginning if not present.

res : array
As input, checked for size.
Expand Down Expand Up @@ -736,13 +736,13 @@ def check_model(depth, res, aniso, epermH, epermV, mpermH, mpermV, xdirect,
# Add -infinity at the beginning
# => The top-layer (-infinity to first interface) is layer 0.
if depth.size == 0:
depth = np.array([-np.infty, ])
depth = np.array([-np.inf, ])
else:
if depth[0] != -np.infty:
depth = np.r_[-np.infty, depth]
if depth[0] != -np.inf:
depth = np.r_[-np.inf, depth]

# Remove +np.infty (can be used to define 2-layer coordinate system).
if depth[-1] == np.infty:
# Remove +np.inf (can be used to define 2-layer coordinate system).
if depth[-1] == np.inf:
depth = depth[:-1]

# Check if the user provided a model for etaH/etaV/zetaH/zetaV
Expand Down Expand Up @@ -1479,9 +1479,9 @@ def get_layer_nr(inp, depth):
"""
zinp = np.array(inp[2], dtype=np.float64)

# depth = [-infty : last interface]; create additional depth-array
# pdepth = [fist interface : +infty]
pdepth = np.concatenate((depth[1:], np.array([np.infty])))
# depth = [-inf : last interface]; create additional depth-array
# pdepth = [fist interface : +inf]
pdepth = np.concatenate((depth[1:], np.array([np.inf])))

# Broadcast arrays
b_zinp = np.atleast_1d(zinp)[:, None]
Expand Down
6 changes: 3 additions & 3 deletions examples/educational/coordinate_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@

In a two-layer scenario with only one interface ``depth = z`` it always
assumes a **LHS**, as it is not possible to detect the direction from only
one interface. To force a **RHS** you have to add ``-np.infty`` for the
one interface. To force a **RHS** you have to add ``-np.inf`` for the
down-most interface:

- **LHS**: ``depth = z`` (+z down); default, corresponds to ``[z, np.infty]``
- **RHS**: ``depth = [z, -np.infty]`` (+z up)
- **LHS**: ``depth = z`` (+z down); default, corresponds to ``[z, np.inf]``
- **RHS**: ``depth = [z, -np.inf]`` (+z up)


In this example we first create a sketch of the LHS and RHS for visualization,
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pydata_sphinx_theme
sphinx_automodapi
ipykernel
ipympl
pickleshare

# FOR TESTING
asv
Expand Down
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@
"empymod=empymod.__main__:main",
],
},
python_requires=">=3.9",
python_requires=">=3.10",
install_requires=[
"scipy>=1.9",
"numpy<2.0",
"numba>=0.53",
"scipy>=1.10",
"numba",
"libdlf",
"scooby",
],
Expand Down
2 changes: 1 addition & 1 deletion tests/create_data/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
zetaV = np.outer(2j*np.pi*freq, mpermV*mu_0)
filt = filters.Hankel().key_51_2012
lambd = filt.base/np.array([0.001, 1, 100, 10000])[:, None]
depth = np.array([-np.infty, 0, 150, 300, 500, 600])
depth = np.array([-np.inf, 0, 150, 300, 500, 600])
inp1 = {'zsrc': 100.,
'zrec': 650.,
'lsrc': np.array(1),
Expand Down
8 changes: 5 additions & 3 deletions tests/create_data/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,12 @@ def test_time(res, off, t, signal):
sPJ0br = iuSpline(np.log(ilambd), PJ0b.real)
sPJ0bi = iuSpline(np.log(ilambd), PJ0b.imag)
ang_fact = kernel.angle_factor(angle, ab, msrc, mrec)
iinp = {'a': a, 'b': b, 'epsabs': atol, 'epsrel': rtol, 'limit': limit}
iinp = {'a': float(a), 'b': float(b), 'epsabs': float(atol),
'epsrel': float(rtol), 'limit': int(limit)}
quad = {'inp': {'sPJ0r': sPJ0r, 'sPJ0i': sPJ0i, 'sPJ1r': sPJ1r, 'sPJ1i': sPJ1i,
'sPJ0br': sPJ0br, 'sPJ0bi': sPJ0bi, 'ab': ab, 'off': off,
'ang_fact': ang_fact, 'iinp': iinp},
'sPJ0br': sPJ0br, 'sPJ0bi': sPJ0bi, 'ab': ab,
'off': float(off[0]), 'ang_fact': float(ang_fact[0]),
'iinp': iinp},
'res': np.squeeze(freqres)}

# # I -- Store data # #
Expand Down
Binary file modified tests/data/transform.npz
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def test_ComplexNumPyEncoder():

# NumPy types
assert type(test.default(np.int_(1))) is int
assert type(test.default(np.float_(1))) is float
assert type(test.default(np.float64(1))) is float
assert type(test.default(np.bool_(1))) is bool
assert type(test.default(np.array([[1., 1.], [1., 1.]]))) is list

Expand Down
8 changes: 4 additions & 4 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,17 +735,17 @@ def test_coordinate_systems():
orig = dipole(depth=z0, res=[air, hs], **inpLHS, **inp)

# Alternatives LHS: low to high and high to low
LHSl2h = dipole(depth=[z0, np.infty], res=[air, hs], **inpLHS, **inp)
LHSh2l = dipole(depth=[np.infty, z0], res=[hs, air], **inpLHS, **inp)
LHSl2h = dipole(depth=[z0, np.inf], res=[air, hs], **inpLHS, **inp)
LHSh2l = dipole(depth=[np.inf, z0], res=[hs, air], **inpLHS, **inp)

assert_allclose(orig, LHSl2h)
assert_allclose(orig, LHSh2l)

# Alternatives LHS: low to high and high to low
RHSlth = sign*dipole(
depth=[-np.infty, -z0], res=[hs, air], **inpRHS, **inp)
depth=[-np.inf, -z0], res=[hs, air], **inpRHS, **inp)
RHSh2l = sign*dipole(
depth=[-z0, -np.infty], res=[air, hs], **inpRHS, **inp)
depth=[-z0, -np.inf], res=[air, hs], **inpRHS, **inp)

assert_allclose(orig, RHSlth, rtol=5e-6)
assert_allclose(orig, RHSh2l, rtol=5e-6)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tmtemod.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
zeta = np.outer(2j*np.pi*freq, mperm*mu_0)
filt = filters.Hankel().key_201_2012
lambd = filt.base/np.array([0.001, 1, 100, 10000])[:, None]
depth = np.array([-np.infty, 0, 150, 300, 500, 600, 800])
depth = np.array([-np.inf, 0, 150, 300, 500, 600, 800])


def test_dipole():
Expand Down
20 changes: 10 additions & 10 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def test_check_model(capsys):
out, _ = capsys.readouterr()
assert "* WARNING :: Parameter aniso < " in out
assert " direct field : Comp. in frequency domain" in out
assert_allclose(depth, [-np.infty, 0])
assert_allclose(depth, [-np.inf, 0])
assert_allclose(res, [1e20, 20])
assert_allclose(aniso, [1, np.sqrt(1e-20/20)])
assert_allclose(epermH, [0, 1])
Expand All @@ -435,13 +435,13 @@ def test_check_model(capsys):
out, _ = capsys.readouterr()
assert " direct field : Not calculated (secondary field)" in out

# Check -np.infty is added to depth
# Check -np.inf is added to depth
out = utils.check_model([], 2, 1, 1, 1, 1, 1, True, 1)
assert_allclose(out[0], -np.infty)
assert_allclose(out[0], -np.inf)

# Check -np.infty is not added if it is already in depth
out = utils.check_model(-np.infty, 2, 1, 1, 1, 1, 1, True, 1)
assert_allclose(out[0], -np.infty)
# Check -np.inf is not added if it is already in depth
out = utils.check_model(-np.inf, 2, 1, 1, 1, 1, 1, True, 1)
assert_allclose(out[0], -np.inf)

# Check verbosity and fullspace
utils.check_model(0, [1, 1], [2, 2], [10, 10], [1, 1], None, [3, 3], True,
Expand Down Expand Up @@ -932,15 +932,15 @@ def test_get_geo_fact():

def test_get_layer_nr():
bip = np.array([0, 0, 300])
lbip, zbip = utils.get_layer_nr(bip, np.array([-np.infty, 500]))
lbip, zbip = utils.get_layer_nr(bip, np.array([-np.inf, 500]))
assert lbip == 0
assert zbip == 300
lbip, _ = utils.get_layer_nr(bip, np.array([-np.infty, 0, 300, 500]))
lbip, _ = utils.get_layer_nr(bip, np.array([-np.inf, 0, 300, 500]))
assert lbip == 1
lbip, _ = utils.get_layer_nr(bip, np.array([-np.infty, 0, 200]))
lbip, _ = utils.get_layer_nr(bip, np.array([-np.inf, 0, 200]))
assert lbip == 2
bip = np.array([np.zeros(4), np.zeros(4), np.arange(4)*100])
lbip, _ = utils.get_layer_nr(bip, np.array([-np.infty, 0, 200]))
lbip, _ = utils.get_layer_nr(bip, np.array([-np.inf, 0, 200]))
assert_allclose(lbip, [0, 1, 1, 2])


Expand Down
Loading