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

pyGIMLi(emg3d) #328

Closed
wants to merge 6 commits into from
Closed
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
26 changes: 17 additions & 9 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,38 @@ jobs:
- python-version: "3.9"
name: minimal
os: ubuntu
conda: "'scipy=1.9' 'numba=0.53'"
conda: "'scipy=1.9' 'numba=0.53' 'numpy<2.0' 'empymod>=2.3'"
pip: ""
- python-version: "3.10"
name: full
os: ubuntu
conda: "numba scipy xarray h5py discretize matplotlib" # tqdm
conda: "numba scipy xarray h5py discretize matplotlib 'numpy<2.0' 'empymod>=2.3'" # tqdm
pip: ""
- python-version: "3.10"
name: plain
os: ubuntu
conda: "numba scipy"
conda: "numba scipy 'numpy<2.0' 'empymod>=2.3'"
pip: ""
- python-version: "3.11"
name: plain
os: ubuntu
conda: "numba scipy"
conda: "numba scipy 'numpy<2.0' 'empymod>=2.3'"
pip: ""
- python-version: "3.11"
name: full
os: ubuntu
conda: "numba scipy xarray tqdm h5py discretize matplotlib"
conda: "numba scipy xarray tqdm h5py discretize matplotlib 'numpy<2.0' 'empymod>=2.3'"
pip: "pygimli"
- python-version: "3.12"
name: plain
os: ubuntu
conda: "numba scipy"
conda: "numba scipy 'numpy<2.0' 'empymod>=2.3'"
pip: ""
- python-version: "3.12"
name: full
os: ubuntu
conda: "numba scipy xarray tqdm h5py discretize matplotlib"
conda: "numba scipy xarray tqdm h5py discretize matplotlib 'numpy<2.0' 'empymod>=2.3'"
pip: ""

env:
# Used for coveralls flag
Expand Down Expand Up @@ -105,7 +112,8 @@ jobs:
conda config --show-sources
conda config --show
conda info -a
conda install ${{ matrix.case.conda }} pytest pytest-cov pytest-console-scripts coveralls flake8 setuptools-scm
conda install -c conda-forge ${{ matrix.case.conda }} pip pytest pytest-cov pytest-console-scripts coveralls flake8 setuptools-scm
pip install ${{ matrix.case.pip }}

- name: Conda list
shell: bash -l {0}
Expand All @@ -118,7 +126,7 @@ jobs:
- name: Test with pytest
shell: bash -l {0}
run: |
python -m pip install .
python -m pip install --no-build-isolation --no-deps .
pytest --cov=emg3d

- name: Coveralls
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ Changelog
""""""""""


latest
------

- New module ``inversion``:

- pyGIMLi(emg3d)


v1.8.3 : tol_gradient isfinite
------------------------------

Expand Down
1 change: 1 addition & 0 deletions docs/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ API reference
surveys
time
utils
inversion/index


.. grid:: 1
Expand Down
21 changes: 21 additions & 0 deletions docs/api/inversion/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.. _inversionapi:

Inversion
#########

.. automodapi:: emg3d.inversion
:no-inheritance-diagram:
:no-heading:

.. toctree::
:maxdepth: 1
:hidden:

pygimli

.. grid:: 1
:gutter: 2

.. grid-item-card::

pyGIMLi(emg3d): :mod:`emg3d.inversion.pygimli`
6 changes: 6 additions & 0 deletions docs/api/inversion/pygimli.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pyGIMLi(emg3d)
==============

.. automodapi:: emg3d.inversion.pygimli
:no-inheritance-diagram:
:no-heading:
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"empymod": ("https://empymod.emsig.xyz/en/stable", None),
"xarray": ("https://docs.xarray.dev/en/stable", None),
"numba": ("https://numba.readthedocs.io/en/stable", None),
"pygimli": ("https://www.pygimli.org", None),
}

# ==== 2. General Settings ====
Expand Down
3 changes: 3 additions & 0 deletions docs/manual/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ or via ``pip``:

pip install emg3d[full]

The wrappers provided in :mod:`emg3d.inversion` may require additional
packages, please consult the :ref:`inversionapi`-API for more information.

If you are new to Python we recommend using a Python distribution, which will
ensure that all dependencies are met, specifically properly compiled versions
of ``NumPy`` and ``SciPy``; we recommend using `Anaconda
Expand Down
1 change: 1 addition & 0 deletions emg3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
RxElectricPoint, RxMagneticPoint,
)
from emg3d.fields import Field, get_source_field, get_magnetic_field
from emg3d import inversion
from emg3d.io import save, load, convert
from emg3d.meshes import TensorMesh, construct_mesh
from emg3d.models import Model
Expand Down
5 changes: 5 additions & 0 deletions emg3d/_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def process_map(fn, *iterables, max_workers, **kwargs):
execution.
"""
process_map.count += 1

# Parallel
if max_workers > 1 and tqdm is None:
Expand All @@ -64,6 +65,10 @@ def process_map(fn, *iterables, max_workers, **kwargs):
iterable=map(fn, *iterables), total=len(iterables[0]), **kwargs))


# Counter for processing map (used, e.g., for inversions).
process_map.count = 0


def solve(inp):
"""Thin wrapper of `solve` or `solve_source` for a `process_map`.
Expand Down
43 changes: 43 additions & 0 deletions emg3d/inversion/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
The inversion submodule of emg3d provides wrapper functionalities to use emg3d
as a forward modelling kernel within third-party inversion frameworks. These
third-party libraries are not included in emg3d, you have to install them
Separately.

Currently implemented wrappers and their corresponding requirements:

- pyGIMLi(emg3d): Requires the *Geophysical Inversion & Modelling
Library* `pyGIMLi <https://pygimli.org>`_.
"""
# Copyright 2024 The emsig community.
#
# This file is part of emg3d.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy
# of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
import importlib as _importlib


submodules = [
'pygimli',
]

__all__ = submodules


def __dir__():
return __all__


def __getattr__(name):
if name in submodules:
return _importlib.import_module(f"emg3d.inversion.{name}")
Loading