Skip to content

Commit 639fabd

Browse files
authored
NumPy v2 (#344)
- Update for NumPy v2 (replace np.infty by np.inf) - Fix warnings - Bump minimum Python to 3.10 - Bump minimum SciPy to 1.10 - No more restriction on Numba version - Docs need new pickleshare
1 parent e64358b commit 639fabd

18 files changed

+78
-64
lines changed

.github/workflows/linux.yml

+8-17
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,26 @@ jobs:
3636
matrix:
3737
os: [ubuntu, ] # macos, windows] # Only Linux currently.
3838
case:
39-
- python-version: "3.9"
40-
name: minimal
41-
os: ubuntu
42-
conda: "'scipy=1.9' 'numba=0.53' 'numpy<2.0' 'empymod>=2.3'"
43-
- python-version: "3.10"
44-
name: full
45-
os: ubuntu
46-
conda: "numba scipy xarray h5py discretize matplotlib 'numpy<2.0' 'empymod>=2.3'" # tqdm
4739
- python-version: "3.10"
48-
name: plain
40+
name: minimal
4941
os: ubuntu
50-
conda: "numba scipy 'numpy<2.0' 'empymod>=2.3'"
42+
conda: "'scipy=1.10' numba 'empymod>=2.3.2'"
5143
- python-version: "3.11"
5244
name: plain
5345
os: ubuntu
54-
conda: "numba scipy 'numpy<2.0' 'empymod>=2.3'"
46+
conda: "scipy numba 'empymod>=2.3.2'"
5547
- python-version: "3.11"
5648
name: full
5749
os: ubuntu
58-
conda: "numba scipy xarray tqdm h5py discretize matplotlib 'numpy<2.0' 'empymod>=2.3'"
50+
conda: "scipy numba 'empymod>=2.3.2' xarray tqdm h5py discretize matplotlib"
5951
- python-version: "3.12"
6052
name: plain
6153
os: ubuntu
62-
conda: "numba scipy 'numpy<2.0' 'empymod>=2.3'"
54+
conda: "scipy numba 'empymod>=2.3.2'"
6355
- python-version: "3.12"
6456
name: full
6557
os: ubuntu
66-
conda: "numba scipy xarray tqdm h5py discretize matplotlib 'numpy<2.0' 'empymod>=2.3'"
58+
conda: "scipy numba 'empymod>=2.3.2' xarray tqdm h5py discretize matplotlib"
6759

6860
env:
6961
# Used for coveralls flag
@@ -95,8 +87,6 @@ jobs:
9587
auto-update-conda: true
9688
python-version: ${{ matrix.case.python-version }}
9789
miniforge-version: "latest"
98-
miniforge-variant: Mambaforge
99-
use-mamba: true
10090

10191
- name: Install dependencies
10292
shell: bash -l {0}
@@ -118,7 +108,8 @@ jobs:
118108
- name: Test with pytest
119109
shell: bash -l {0}
120110
run: |
121-
python -m pip install --no-build-isolation --no-deps .
111+
python -m pip install --upgrade pip
112+
make install
122113
pytest --cov=emg3d
123114
124115
- name: Coveralls

.github/workflows/macos_windows.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ jobs:
6262
auto-update-conda: true
6363
python-version: ${{ matrix.python }}
6464
miniforge-version: "latest"
65-
miniforge-variant: Mambaforge
66-
use-mamba: true
6765

6866
- name: Install dependencies
6967
shell: bash -l {0}
@@ -72,7 +70,7 @@ jobs:
7270
conda config --show-sources
7371
conda config --show
7472
conda info -a
75-
conda install numba scipy pytest pytest-console-scripts scooby setuptools-scm
73+
conda install scipy numba empymod pytest pytest-console-scripts setuptools-scm
7674
7775
- name: Conda list
7876
shell: bash -l {0}
@@ -81,5 +79,5 @@ jobs:
8179
- name: Test with pytest
8280
shell: bash -l {0}
8381
run: |
84-
python -m pip install .
82+
make install
8583
pytest

CHANGELOG.rst

+17-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,27 @@ Changelog
66
""""""""""
77

88

9-
latest
10-
------
9+
v1.8.4 : NumPy v2
10+
-----------------
11+
12+
**2024-10-09**
13+
14+
The code is now compatible with NumPy v2.
15+
1116

1217
- Created foundation for new module ``inversion``.
1318

14-
Maintenance
19+
- Bumped the minimum requirements to:
20+
21+
- Python 3.10
22+
- SciPy 1.10
23+
- empymod 2.3.2
24+
- Numba (without minimum version)
25+
26+
- Maintenance
1527

28+
- Testing: dropped Python 3.9 (Python 3.13 not added yet).
29+
- Update for NumPy v2: mainly ``np.infty -> np.inf``.
1630
- Add notes for ``ipympl`` (interactive plots in modern Jupyter).
1731
- Reduce code by making use of new SciPy new features (complex-valued
1832
map_coordinate; lazy loading).

CREDITS.rst

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
Credits
22
#######
33

4-
This project was started by **Dieter Werthmüller** at
5-
`Delft University of Technology <https://www.tudelft.nl>`_ as part of the
6-
*Gitaro.JIM* project (till 05/2021, emg3d v1.0.0), funded through
7-
`MarTERA <https://www.martera.eu>`_ as part of Horizon 2020, a funding scheme
8-
of the European Research Area. Dieter would like to thank his current employers
9-
who allow him to maintain and further develop the code after the initial
10-
funding ended, namely:
11-
12-
- 2021-today: `Delft University of Technology <https://www.tudelft.nl>`_,
13-
funded through the `Delphi Consortium <https://www.delphi-consortium.com>`_
14-
- 2021-today: `TERRASYS Geophysics GmbH & Co. KG <https://www.terrasysgeo.com>`_
4+
This project was started by **Dieter Werthmüller** at TUD as part of the
5+
*Gitaro.JIM* project (see below).
6+
Dieter would like to thank his past and current employers who allowed and allow
7+
him to maintain and further develop the code after the initial funding ended,
8+
namely:
9+
10+
- 2018-2021: `Delft University of Technology <https://www.tudelft.nl>`_;
11+
through the *Gitaro.JIM* project (till 05/2021, emg3d v1.0.0), funded by
12+
`MarTERA <https://www.martera.eu>`_ as part of Horizon 2020, a funding scheme
13+
of the European Research Area.
14+
- 2021-2024: `Delft University of Technology <https://www.tudelft.nl>`_ through
15+
the `Delphi Consortium <https://www.delphi-consortium.com>`_.
16+
- 2021-2022: `TERRASYS Geophysics GmbH & Co. KG
17+
<https://www.terrasysgeo.com>`_.
18+
- 2024-today: `ETH Zurich <https://ethz.ch>`_ through the group `Geothermal
19+
Energy and Geofluids <https://geg.ethz.ch>`_.
1520

1621
For a list of code contributors see
1722
https://github.com/emsig/emg3d/graphs/contributors.

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ help:
1313
@echo ""
1414

1515
install:
16-
python -m pip install --no-build-isolation --no-deps -e .
16+
python -m pip install --no-build-isolation --use-pep517 --no-deps -e .
1717

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

2121
pytest:
2222
rm -rf .coverage htmlcov/ .pytest_cache/ && pytest --cov=emg3d && coverage html

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
.. image:: https://img.shields.io/conda/v/conda-forge/emg3d.svg
1111
:target: https://anaconda.org/conda-forge/emg3d/
1212
:alt: conda-forge
13-
.. image:: https://img.shields.io/badge/python-3.8+-blue.svg
13+
.. image:: https://img.shields.io/badge/python-3.10+-blue.svg
1414
:target: https://www.python.org/downloads/
1515
:alt: Supported Python Versions
1616
.. image:: https://img.shields.io/badge/platform-linux,win,osx-blue.svg

docs/dev/contributing.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Good places to get started is to browse the existing issues, check out the
1111
roadmap, or have a look at any open PR:
1212

1313
- `Issues <https://github.com/emsig/emg3d/issues>`_;
14-
- `Roadmap-project <https://github.com/emsig/emg3d/projects/1>`_;
14+
- `Roadmap <https://github.com/emsig/emg3d/issues/343>`_;
1515
- `PR's <https://github.com/emsig/emg3d/pulls>`_.
1616

1717
There are various different ways to get in touch, see

docs/manual/cli.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ remove the comment signs to use them.
124124
[noise_opts]
125125
# add_noise = True # Set to False to switch noise off.
126126
# min_offset = 0.0 # off < min_off set to NaN.
127-
# max_offset = np.infty # off > max_off set to NaN.
127+
# max_offset = np.inf # off > max_off set to NaN.
128128
# mean_noise = 0.0 # Mean of the noise.
129129
# ntype = white_noise # Type of the noise.
130130

emg3d/fields.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -696,9 +696,9 @@ def point_source(xx, yy, zz, coo, s):
696696
nx, ny, nz = s.shape
697697

698698
# Get indices of cells in which source resides.
699-
ix = max(0, np.where(coo[0] < np.r_[xx, np.infty])[0][0]-1)
700-
iy = max(0, np.where(coo[1] < np.r_[yy, np.infty])[0][0]-1)
701-
iz = max(0, np.where(coo[2] < np.r_[zz, np.infty])[0][0]-1)
699+
ix = max(0, np.where(coo[0] < np.r_[xx, np.inf])[0][0]-1)
700+
iy = max(0, np.where(coo[1] < np.r_[yy, np.inf])[0][0]-1)
701+
iz = max(0, np.where(coo[2] < np.r_[zz, np.inf])[0][0]-1)
702702

703703
def get_index_and_strength(ic, nc, csrc, cc):
704704
"""Return index and field strength in c-direction."""
@@ -864,8 +864,8 @@ def min_max_ind(vector, i):
864864
"""Return [min, max]-index of cells in which points resides."""
865865
vmin = min(points[:, i])
866866
vmax = max(points[:, i])
867-
return [max(0, np.where(vmin < np.r_[vector, np.infty])[0][0]-1),
868-
max(0, np.where(vmax < np.r_[vector, np.infty])[0][0]-1)]
867+
return [max(0, np.where(vmin < np.r_[vector, np.inf])[0][0]-1),
868+
max(0, np.where(vmax < np.r_[vector, np.inf])[0][0]-1)]
869869

870870
rix = min_max_ind(nodes_x, 0)
871871
riy = min_max_ind(nodes_y, 1)

emg3d/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def extract_1d(self, method, p0, p1=None, ellipse=None, merge=False,
468468
# Find corresponding indices, limit to grid.
469469
def index(nodes, coo):
470470
"""Return index for interval btw nodes in which coo resides."""
471-
x = np.asarray(coo < np.r_[nodes, np.infty]).nonzero()[0][0]-1
471+
x = np.asarray(coo < np.r_[nodes, np.inf]).nonzero()[0][0]-1
472472
return np.clip(x, 0, nodes.size-2)
473473

474474
# Start and end indices.

emg3d/surveys.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ def add_noise(self, min_offset=0.0, min_amplitude='half_nf',
619619
dataset it will create a dataset of zeroes. You can use that to
620620
obtain the pure noise.
621621
622-
max_offset : float, default: np.infty
622+
max_offset : float, default: np.inf
623623
Data points in ``data.observed`` where the offset > max_offset are
624624
set to NaN.
625625
@@ -639,8 +639,8 @@ def add_noise(self, min_offset=0.0, min_amplitude='half_nf',
639639
self.data[add_to].data[cut_amp] = np.nan + 1j*np.nan
640640

641641
# Set offsets below min_offset and above max_offset to NaN.
642-
max_offset = kwargs.pop('max_offset', np.infty)
643-
if min_offset > 0.0 or max_offset < np.infty:
642+
max_offset = kwargs.pop('max_offset', np.inf)
643+
if min_offset > 0.0 or max_offset < np.inf:
644644
for ks, s in self.sources.items():
645645
for kr, r in self.receivers.items():
646646
off = np.linalg.norm(r.center_abs(s) - s.center)

requirements-dev.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# GLOBAL REQUIREMENTS.
22
-r requirements.txt
33

4+
# Fix numpy<2 until discretize is ready for 2.0
5+
numpy<2
6+
47
# SOFT DEPENDENCIES
58
tqdm
69
h5py
@@ -22,6 +25,7 @@ sphinx_numfig
2225
pydata_sphinx_theme
2326
sphinx_automodapi
2427
ipykernel
28+
pickleshare
2529

2630
# FOR TESTING
2731
asv

setup.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@
2626
"emg3d=emg3d.cli.main:main",
2727
],
2828
},
29-
python_requires=">=3.9",
29+
python_requires=">=3.10",
3030
install_requires=[
31-
"scipy>=1.9",
32-
"numpy<2.0",
33-
"numba>=0.53",
34-
"empymod>=2.3.0",
31+
"scipy>=1.10",
32+
"numba",
33+
"empymod>=2.3.2",
3534
],
3635
extras_require={
3736
"full": [

tests/alternatives.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def alt_volume_average(edges_x, edges_y, edges_z, values,
241241
"""
242242

243243
# Get cell indices.
244-
# First and last edges ignored => first and last cells extend to +/- infty.
244+
# First and last edges ignored => first and last cells extend to +/- inf.
245245
ix_l = np.searchsorted(edges_x[1:-1], new_edges_x, 'left')
246246
ix_r = np.searchsorted(edges_x[1:-1], new_edges_x, 'right')
247247
iy_l = np.searchsorted(edges_y[1:-1], new_edges_y, 'left')
@@ -353,9 +353,9 @@ def point_source(xx, yy, zz, src, s):
353353
nx, ny, nz = s.shape
354354

355355
# Get indices of cells in which source resides.
356-
ix = max(0, np.where(src[0] < np.r_[xx, np.infty])[0][0]-1)
357-
iy = max(0, np.where(src[1] < np.r_[yy, np.infty])[0][0]-1)
358-
iz = max(0, np.where(src[2] < np.r_[zz, np.infty])[0][0]-1)
356+
ix = max(0, np.where(src[0] < np.r_[xx, np.inf])[0][0]-1)
357+
iy = max(0, np.where(src[1] < np.r_[yy, np.inf])[0][0]-1)
358+
iz = max(0, np.where(src[2] < np.r_[zz, np.inf])[0][0]-1)
359359

360360
def get_index_and_strength(ic, nc, csrc, cc):
361361
"""Return index and field strength in c-direction."""

tests/test_fields.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def test_dtype(self):
7878
with pytest.raises(ValueError, match="must be f>0"):
7979
_ = fields.Field(self.grid, frequency=0.0)
8080

81-
with pytest.warns(np.ComplexWarning, match="Casting complex values"):
81+
with pytest.warns(np.exceptions.ComplexWarning, match="Casting compl"):
8282
lp = fields.Field(self.grid, self.field, frequency=-1)
8383
assert lp.field.dtype == np.float64
8484

tests/test_meshes.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,14 @@ def test_domain_vector(self):
346346

347347
vector2 = np.array([-1, 0, 1])
348348
x02, hx2 = meshes.origin_and_widths(vector=vector2, **inp)
349-
assert np.in1d(vector2, x02 + np.cumsum(hx2)).all()
349+
assert np.isin(vector2, x02 + np.cumsum(hx2)).all()
350350

351351
vector3 = np.array([-2, -1, 0, 1, 2])
352352
x03, hx3 = meshes.origin_and_widths( # vector will be cut
353353
domain=[-1, 1], vector=vector3, **inp)
354-
assert np.in1d(vector3[1:-1], x03 + np.cumsum(hx3)).all()
355-
assert not np.in1d(vector3[0], x03 + np.cumsum(hx3))
356-
assert not np.in1d(vector3[-1], x03 + np.cumsum(hx3))
354+
assert np.isin(vector3[1:-1], x03 + np.cumsum(hx3)).all()
355+
assert not np.isin(vector3[0], x03 + np.cumsum(hx3))
356+
assert not np.isin(vector3[-1], x03 + np.cumsum(hx3))
357357

358358
x04, hx4 = meshes.origin_and_widths( # vector will be cut
359359
distance=[1.0, 1.0], vector=vector3, **inp)
@@ -362,7 +362,7 @@ def test_domain_vector(self):
362362

363363
x05, hx5 = meshes.origin_and_widths( # vector will be expanded
364364
distance=[2.0, 2.0], vector=vector2, **inp)
365-
assert np.in1d(np.array([-2, -1, 0, 1, 2]), x05 + np.cumsum(hx5)).all()
365+
assert np.isin(np.array([-2, -1, 0, 1, 2]), x05 + np.cumsum(hx5)).all()
366366

367367
def test_seasurface(self):
368368
inp = {'frequency': 1/np.pi, 'properties': 9*mu_0, 'domain': [-1, 2],

tests/test_multiprocessing.py

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def dummy(inp):
2727
return inp
2828

2929

30+
@pytest.mark.filterwarnings("ignore:.*lead to deadlocks*:DeprecationWarning")
3031
def test_process_map():
3132

3233
# Parallel

tests/test_simulations.py

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
rng = np.random.default_rng()
2929

3030

31+
@pytest.mark.filterwarnings("ignore:.*lead to deadlocks*:DeprecationWarning")
3132
@pytest.mark.skipif(xarray is None, reason="xarray not installed.")
3233
class TestSimulation():
3334
if xarray is not None:
@@ -695,6 +696,7 @@ def test_compute_1d(self):
695696
assert grad.shape == self.model.shape
696697

697698

699+
@pytest.mark.filterwarnings("ignore:.*lead to deadlocks*:DeprecationWarning")
698700
@pytest.mark.skipif(xarray is None, reason="xarray not installed.")
699701
def test_misfit():
700702
data = 1

0 commit comments

Comments
 (0)