Skip to content

Commit 5933801

Browse files
authored
Merge pull request #48 from MTgeophysics/updates
Check for Pardiso import
2 parents b406692 + d503d0a commit 5933801

File tree

7 files changed

+148
-24
lines changed

7 files changed

+148
-24
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 2.0.8
2+
current_version = 2.0.9
33
files = setup.py mtpy/__init__.py README.md docs/source/conf.py
44
commit = True
55
tag = True
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: TestingInConda
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
8+
jobs:
9+
setup-build:
10+
name: Ex1 (${{ matrix.python-version }}, ${{ matrix.os }})
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
os: ["ubuntu-latest"]
16+
python-version: ["3.10"]
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Setup Conda
21+
uses: s-weigand/setup-conda@v1
22+
with:
23+
update-conda: false
24+
conda-channels: conda-forge
25+
python-version: ${{ matrix.python-version }}
26+
27+
- name: Install Packages
28+
shell: bash
29+
run: |
30+
python --version
31+
conda create -n mtpy-v2-test python=--version
32+
source activate mtpy-v2-test
33+
pip install mtpy-v2
34+
conda install pytest
35+
conda install pytest-subtests
36+
conda install pytest-cov
37+
git clone https://github.com/kujaku11/mt_metadata.git
38+
git clone install git+https://github.com/kujaku11/mth5.git
39+
git clone git+https://github.com/simpeg/aurora
40+
git clone https://github.com/MTgeophysics/mtpy_data.git
41+
cd mtpy_data
42+
pip install -e .
43+
cd ..
44+
conda list
45+
46+
- name: Run Tests
47+
shell: bash
48+
run: |
49+
source activate mtpy-v2-test
50+
pytest -rA --cov=./ --cov-report=xml --cov=mtpy
51+
52+
- name: "Upload coverage to Codecov"
53+
uses: codecov/codecov-action@v3
54+
env:
55+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
56+
with:
57+
fail_ci_if_error: false
58+
verbose: true
59+
flags: tests
60+

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
[![Documentation Status](https://readthedocs.org/projects/mtpy-v2/badge/?version=latest)](https://mtpy-v2.readthedocs.io/en/latest/?badge=latest)
88
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/MTgeophysics/mtpy-v2/main)
99

10-
## Version 2.0.8
10+
## Version 2.0.9
1111

1212
# Description
1313

1414
`mtpy` provides tools for working with magnetotelluric (MT) data. MTpy-v2 is an updated version of [mtpy](https://github.com/MTgeophysics/mtpy). Many things have changed under the hood and usage is different from mtpy v1. The main difference is that there is a central data type that can hold transfer functions and then read/write to your modeling program, plot, and analyze your data. No longer will you need a directory of EDI files and then read them in everytime you want to do something. You only need to build a project once and save it to an MTH5 file and you are ready to go. All metadata uses [mt-metadata](https://github.com/kujaku11/mt-metadata).
1515

16+
17+
1618
# Installation
1719

1820
## Using Pip
@@ -22,7 +24,32 @@
2224
## Using conda
2325

2426
`> conda install -c conda-forge mtpy-v2`
25-
27+
28+
### Pardiso Solver
29+
30+
`mtpy-v2` now include some tools to model and invert using `simpeg`. If you want to use the Pardiso solver you will need to install it separately. See the https://github.com/simpeg/pydiso for more information. Below is a snippet from their recommendations.
31+
32+
#### Installing from source
33+
34+
The wrapper is written in cython and links to the mkl libraries dynamically. Therefore,
35+
it needs to find the necessary header files associated with the MKL installation to compile.
36+
The meson build backend uses pkg-config to identify the locations of the mkl header files
37+
and library dynamic libraries. Most development installations of MKL should provide the
38+
necessary pkg-config files for this. For example, conda users can be install the necessary
39+
configuration information with `mkl-devel` package that is available on the default channel,
40+
conda-forge channel, the intel channel, or others, e.g.
41+
42+
`conda install mkl-devel`
43+
44+
If you have installed the configuration files to a non-standard location, you will need to set
45+
`PKG_CONFIG_PATH` to point to that location.
46+
47+
After the necessary MKL files are accessible, you should be able to install by running
48+
49+
`pip install .`
50+
51+
in the installation directory.
52+
2653

2754
# Functionality
2855

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@
6767
#
6868

6969
# The short X.Y version.
70-
version = "2.0.8"
70+
version = "2.0.9"
7171
# The full version, including alpha/beta/rc tags.
72-
release = "2.0.8"
72+
release = "2.0.9"
7373

7474
# The language for content autogenerated by Sphinx. Refer to documentation
7575
# for a list of supported languages.

mtpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from mtpy.imaging.mtcolors import MT_CMAP_DICT, register_cmaps
1919

2020

21-
__version__ = "2.0.8"
21+
__version__ = "2.0.9"
2222
__all__ = ["MT", "MTData", "MTCollection"]
2323

2424
# =============================================================================

mtpy/modeling/simpeg/recipes/inversion_2d.py

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import warnings
1717
import numpy as np
1818

19+
1920
import matplotlib.pyplot as plt
2021
from matplotlib.colors import LogNorm
2122

@@ -29,7 +30,16 @@
2930
data_misfit,
3031
regularization,
3132
)
32-
from pymatsolver import Pardiso
33+
34+
try:
35+
from pymatsolver import Pardiso
36+
37+
pardiso_imported = True
38+
except ImportError:
39+
warnings.warn(
40+
"Pardiso not installed see https://github.com/simpeg/pydiso/blob/main/README.md."
41+
)
42+
pardiso_imported = False
3343

3444
# from dask.distributed import Client, LocalCluster
3545
from mtpy.modeling.simpeg.data_2d import Simpeg2DData
@@ -58,9 +68,13 @@ def __init__(self, dataframe, data_kwargs={}, mesh_kwargs={}, **kwargs):
5868
self.ax = self.make_mesh()
5969
self.air_conductivity = 1e-8
6070
self.initial_conductivity = 1e-2
61-
self.solver = "pardiso"
71+
if pardiso_imported:
72+
self.solver = "pardiso"
73+
self._solvers_dict = {"pardiso": Pardiso}
6274

63-
self._solvers_dict = {"pardiso": Pardiso}
75+
else:
76+
self.solver = None
77+
self._solvers_dict = {}
6478

6579
# regularization parameters
6680
self.alpha_s = 1e-5
@@ -175,31 +189,54 @@ def conductivity_map(self):
175189
"""
176190
return self.exponent_map * self.active_map
177191

192+
def _get_solver(self):
193+
"""
194+
get solver
195+
"""
196+
try:
197+
return self._solvers_dict[self.solver]
198+
except KeyError:
199+
return None
200+
178201
@property
179202
def tm_simulation(self):
180203
"""
181204
Simulation for TE Mode
182205
"""
183-
184-
return nsem.simulation.Simulation2DElectricField(
185-
self.quad_tree.mesh,
186-
survey=self.data.tm_survey,
187-
sigmaMap=self.conductivity_map,
188-
solver=self._solvers_dict[self.solver],
189-
)
206+
solver = self._get_solver()
207+
if solver is not None:
208+
return nsem.simulation.Simulation2DElectricField(
209+
self.quad_tree.mesh,
210+
survey=self.data.tm_survey,
211+
sigmaMap=self.conductivity_map,
212+
solver=solver,
213+
)
214+
else:
215+
return nsem.simulation.Simulation2DElectricField(
216+
self.quad_tree.mesh,
217+
survey=self.data.tm_survey,
218+
sigmaMap=self.conductivity_map,
219+
)
190220

191221
@property
192222
def te_simulation(self):
193223
"""
194224
Simulation for TE Mode
195225
"""
196-
197-
return nsem.simulation.Simulation2DMagneticField(
198-
self.quad_tree.mesh,
199-
survey=self.data.te_survey,
200-
sigmaMap=self.conductivity_map,
201-
solver=self._solvers_dict[self.solver],
202-
)
226+
solver = self._get_solver()
227+
if solver is not None:
228+
return nsem.simulation.Simulation2DMagneticField(
229+
self.quad_tree.mesh,
230+
survey=self.data.te_survey,
231+
sigmaMap=self.conductivity_map,
232+
solver=solver,
233+
)
234+
else:
235+
nsem.simulation.Simulation2DMagneticField(
236+
self.quad_tree.mesh,
237+
survey=self.data.te_survey,
238+
sigmaMap=self.conductivity_map,
239+
)
203240

204241
@property
205242
def te_data_misfit(self):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
test_suite="tests",
6767
tests_require=test_requirements,
6868
url="https://github.com/MTgeophysics/mtpy-v2",
69-
version="2.0.8",
69+
version="2.0.9",
7070
zip_safe=False,
7171
package_data={"": []},
7272
)

0 commit comments

Comments
 (0)