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 #344

Merged
merged 6 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,34 +36,26 @@ jobs:
matrix:
os: [ubuntu, ] # macos, windows] # Only Linux currently.
case:
- python-version: "3.9"
name: minimal
os: ubuntu
conda: "'scipy=1.9' 'numba=0.53' 'numpy<2.0' 'empymod>=2.3'"
- python-version: "3.10"
name: full
os: ubuntu
conda: "numba scipy xarray h5py discretize matplotlib 'numpy<2.0' 'empymod>=2.3'" # tqdm
- python-version: "3.10"
name: plain
name: minimal
os: ubuntu
conda: "numba scipy 'numpy<2.0' 'empymod>=2.3'"
conda: "'scipy=1.10' numba 'empymod>=2.3.2'"
- python-version: "3.11"
name: plain
os: ubuntu
conda: "numba scipy 'numpy<2.0' 'empymod>=2.3'"
conda: "scipy numba 'empymod>=2.3.2'"
- python-version: "3.11"
name: full
os: ubuntu
conda: "numba scipy xarray tqdm h5py discretize matplotlib 'numpy<2.0' 'empymod>=2.3'"
conda: "scipy numba 'empymod>=2.3.2' xarray tqdm h5py discretize matplotlib"
- python-version: "3.12"
name: plain
os: ubuntu
conda: "numba scipy 'numpy<2.0' 'empymod>=2.3'"
conda: "scipy numba 'empymod>=2.3.2'"
- python-version: "3.12"
name: full
os: ubuntu
conda: "numba scipy xarray tqdm h5py discretize matplotlib 'numpy<2.0' 'empymod>=2.3'"
conda: "scipy numba 'empymod>=2.3.2' xarray tqdm h5py discretize matplotlib"

env:
# Used for coveralls flag
Expand Down Expand Up @@ -95,8 +87,6 @@ jobs:
auto-update-conda: true
python-version: ${{ matrix.case.python-version }}
miniforge-version: "latest"
miniforge-variant: Mambaforge
use-mamba: true

- name: Install dependencies
shell: bash -l {0}
Expand All @@ -118,7 +108,8 @@ jobs:
- name: Test with pytest
shell: bash -l {0}
run: |
python -m pip install --no-build-isolation --no-deps .
python -m pip install --upgrade pip
make install
pytest --cov=emg3d

- name: Coveralls
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/macos_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ jobs:
auto-update-conda: true
python-version: ${{ matrix.python }}
miniforge-version: "latest"
miniforge-variant: Mambaforge
use-mamba: true

- name: Install dependencies
shell: bash -l {0}
Expand All @@ -72,7 +70,7 @@ jobs:
conda config --show-sources
conda config --show
conda info -a
conda install numba scipy pytest pytest-console-scripts scooby setuptools-scm
conda install scipy numba empymod pytest pytest-console-scripts setuptools-scm

- name: Conda list
shell: bash -l {0}
Expand All @@ -81,5 +79,5 @@ jobs:
- name: Test with pytest
shell: bash -l {0}
run: |
python -m pip install .
make install
pytest
20 changes: 17 additions & 3 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,27 @@ Changelog
""""""""""


latest
------
v1.8.4 : NumPy v2
-----------------

**2024-10-09**

The code is now compatible with NumPy v2.


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

Maintenance
- Bumped the minimum requirements to:

- Python 3.10
- SciPy 1.10
- empymod 2.3.2
- Numba (without minimum version)

- Maintenance

- Testing: dropped Python 3.9 (Python 3.13 not added yet).
- Update for NumPy v2: mainly ``np.infty -> np.inf``.
- Add notes for ``ipympl`` (interactive plots in modern Jupyter).
- Reduce code by making use of new SciPy new features (complex-valued
map_coordinate; lazy loading).
Expand Down
27 changes: 16 additions & 11 deletions CREDITS.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
Credits
#######

This project was started by **Dieter Werthmüller** at
`Delft University of Technology <https://www.tudelft.nl>`_ as part of the
*Gitaro.JIM* project (till 05/2021, emg3d v1.0.0), funded through
`MarTERA <https://www.martera.eu>`_ as part of Horizon 2020, a funding scheme
of the European Research Area. Dieter would like to thank his current employers
who allow him to maintain and further develop the code after the initial
funding ended, namely:

- 2021-today: `Delft University of Technology <https://www.tudelft.nl>`_,
funded through the `Delphi Consortium <https://www.delphi-consortium.com>`_
- 2021-today: `TERRASYS Geophysics GmbH & Co. KG <https://www.terrasysgeo.com>`_
This project was started by **Dieter Werthmüller** at TUD as part of the
*Gitaro.JIM* project (see below).
Dieter would like to thank his past and current employers who allowed and allow
him to maintain and further develop the code after the initial funding ended,
namely:

- 2018-2021: `Delft University of Technology <https://www.tudelft.nl>`_;
through the *Gitaro.JIM* project (till 05/2021, emg3d v1.0.0), funded by
`MarTERA <https://www.martera.eu>`_ as part of Horizon 2020, a funding scheme
of the European Research Area.
- 2021-2024: `Delft University of Technology <https://www.tudelft.nl>`_ through
the `Delphi Consortium <https://www.delphi-consortium.com>`_.
- 2021-2022: `TERRASYS Geophysics GmbH & Co. KG
<https://www.terrasysgeo.com>`_.
- 2024-today: `ETH Zurich <https://ethz.ch>`_ through the group `Geothermal
Energy and Geofluids <https://geg.ethz.ch>`_.

For a list of code contributors see
https://github.com/emsig/emg3d/graphs/contributors.
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,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 .

pytest:
rm -rf .coverage htmlcov/ .pytest_cache/ && pytest --cov=emg3d && coverage html
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/emg3d.svg
:target: https://anaconda.org/conda-forge/emg3d/
: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
2 changes: 1 addition & 1 deletion docs/dev/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ 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/emg3d/issues>`_;
- `Roadmap-project <https://github.com/emsig/emg3d/projects/1>`_;
- `Roadmap <https://github.com/emsig/emg3d/issues/343>`_;
- `PR's <https://github.com/emsig/emg3d/pulls>`_.

There are various different ways to get in touch, see
Expand Down
2 changes: 1 addition & 1 deletion docs/manual/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ remove the comment signs to use them.
[noise_opts]
# add_noise = True # Set to False to switch noise off.
# min_offset = 0.0 # off < min_off set to NaN.
# max_offset = np.infty # off > max_off set to NaN.
# max_offset = np.inf # off > max_off set to NaN.
# mean_noise = 0.0 # Mean of the noise.
# ntype = white_noise # Type of the noise.

Expand Down
10 changes: 5 additions & 5 deletions emg3d/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,9 +696,9 @@ def point_source(xx, yy, zz, coo, s):
nx, ny, nz = s.shape

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

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

rix = min_max_ind(nodes_x, 0)
riy = min_max_ind(nodes_y, 1)
Expand Down
2 changes: 1 addition & 1 deletion emg3d/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def extract_1d(self, method, p0, p1=None, ellipse=None, merge=False,
# Find corresponding indices, limit to grid.
def index(nodes, coo):
"""Return index for interval btw nodes in which coo resides."""
x = np.asarray(coo < np.r_[nodes, np.infty]).nonzero()[0][0]-1
x = np.asarray(coo < np.r_[nodes, np.inf]).nonzero()[0][0]-1
return np.clip(x, 0, nodes.size-2)

# Start and end indices.
Expand Down
6 changes: 3 additions & 3 deletions emg3d/surveys.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def add_noise(self, min_offset=0.0, min_amplitude='half_nf',
dataset it will create a dataset of zeroes. You can use that to
obtain the pure noise.

max_offset : float, default: np.infty
max_offset : float, default: np.inf
Data points in ``data.observed`` where the offset > max_offset are
set to NaN.

Expand All @@ -639,8 +639,8 @@ def add_noise(self, min_offset=0.0, min_amplitude='half_nf',
self.data[add_to].data[cut_amp] = np.nan + 1j*np.nan

# Set offsets below min_offset and above max_offset to NaN.
max_offset = kwargs.pop('max_offset', np.infty)
if min_offset > 0.0 or max_offset < np.infty:
max_offset = kwargs.pop('max_offset', np.inf)
if min_offset > 0.0 or max_offset < np.inf:
for ks, s in self.sources.items():
for kr, r in self.receivers.items():
off = np.linalg.norm(r.center_abs(s) - s.center)
Expand Down
4 changes: 4 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# GLOBAL REQUIREMENTS.
-r requirements.txt

# Fix numpy<2 until discretize is ready for 2.0
numpy<2

# SOFT DEPENDENCIES
tqdm
h5py
Expand All @@ -22,6 +25,7 @@ sphinx_numfig
pydata_sphinx_theme
sphinx_automodapi
ipykernel
pickleshare

# FOR TESTING
asv
Expand Down
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
"emg3d=emg3d.cli.main:main",
],
},
python_requires=">=3.9",
python_requires=">=3.10",
install_requires=[
"scipy>=1.9",
"numpy<2.0",
"numba>=0.53",
"empymod>=2.3.0",
"scipy>=1.10",
"numba",
"empymod>=2.3.2",
],
extras_require={
"full": [
Expand Down
8 changes: 4 additions & 4 deletions tests/alternatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def alt_volume_average(edges_x, edges_y, edges_z, values,
"""

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

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

def get_index_and_strength(ic, nc, csrc, cc):
"""Return index and field strength in c-direction."""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_dtype(self):
with pytest.raises(ValueError, match="must be f>0"):
_ = fields.Field(self.grid, frequency=0.0)

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

Expand Down
10 changes: 5 additions & 5 deletions tests/test_meshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,14 @@ def test_domain_vector(self):

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

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

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

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

def test_seasurface(self):
inp = {'frequency': 1/np.pi, 'properties': 9*mu_0, 'domain': [-1, 2],
Expand Down
1 change: 1 addition & 0 deletions tests/test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def dummy(inp):
return inp


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

# Parallel
Expand Down
2 changes: 2 additions & 0 deletions tests/test_simulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
rng = np.random.default_rng()


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


@pytest.mark.filterwarnings("ignore:.*lead to deadlocks*:DeprecationWarning")
@pytest.mark.skipif(xarray is None, reason="xarray not installed.")
def test_misfit():
data = 1
Expand Down
Loading