Skip to content

Commit

Permalink
Merge pull request #48 from MTgeophysics/updates
Browse files Browse the repository at this point in the history
Check for Pardiso import
  • Loading branch information
kujaku11 authored Aug 30, 2024
2 parents b406692 + d503d0a commit 5933801
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.0.8
current_version = 2.0.9
files = setup.py mtpy/__init__.py README.md docs/source/conf.py
commit = True
tag = True
60 changes: 60 additions & 0 deletions .github/workflows/testing_pip_import.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: TestingInConda

on:
push:
branches:
- 'main'

jobs:
setup-build:
name: Ex1 (${{ matrix.python-version }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
python-version: ["3.10"]

steps:
- uses: actions/checkout@v3
- name: Setup Conda
uses: s-weigand/setup-conda@v1
with:
update-conda: false
conda-channels: conda-forge
python-version: ${{ matrix.python-version }}

- name: Install Packages
shell: bash
run: |
python --version
conda create -n mtpy-v2-test python=--version
source activate mtpy-v2-test
pip install mtpy-v2
conda install pytest
conda install pytest-subtests
conda install pytest-cov
git clone https://github.com/kujaku11/mt_metadata.git
git clone install git+https://github.com/kujaku11/mth5.git
git clone git+https://github.com/simpeg/aurora
git clone https://github.com/MTgeophysics/mtpy_data.git
cd mtpy_data
pip install -e .
cd ..
conda list
- name: Run Tests
shell: bash
run: |
source activate mtpy-v2-test
pytest -rA --cov=./ --cov-report=xml --cov=mtpy
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
fail_ci_if_error: false
verbose: true
flags: tests

31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
[![Documentation Status](https://readthedocs.org/projects/mtpy-v2/badge/?version=latest)](https://mtpy-v2.readthedocs.io/en/latest/?badge=latest)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/MTgeophysics/mtpy-v2/main)

## Version 2.0.8
## Version 2.0.9

# Description

`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).



# Installation

## Using Pip
Expand All @@ -22,7 +24,32 @@
## Using conda

`> conda install -c conda-forge mtpy-v2`


### Pardiso Solver

`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.

#### Installing from source

The wrapper is written in cython and links to the mkl libraries dynamically. Therefore,
it needs to find the necessary header files associated with the MKL installation to compile.
The meson build backend uses pkg-config to identify the locations of the mkl header files
and library dynamic libraries. Most development installations of MKL should provide the
necessary pkg-config files for this. For example, conda users can be install the necessary
configuration information with `mkl-devel` package that is available on the default channel,
conda-forge channel, the intel channel, or others, e.g.

`conda install mkl-devel`

If you have installed the configuration files to a non-standard location, you will need to set
`PKG_CONFIG_PATH` to point to that location.

After the necessary MKL files are accessible, you should be able to install by running

`pip install .`

in the installation directory.


# Functionality

Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
#

# The short X.Y version.
version = "2.0.8"
version = "2.0.9"
# The full version, including alpha/beta/rc tags.
release = "2.0.8"
release = "2.0.9"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion mtpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from mtpy.imaging.mtcolors import MT_CMAP_DICT, register_cmaps


__version__ = "2.0.8"
__version__ = "2.0.9"
__all__ = ["MT", "MTData", "MTCollection"]

# =============================================================================
Expand Down
71 changes: 54 additions & 17 deletions mtpy/modeling/simpeg/recipes/inversion_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import warnings
import numpy as np


import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm

Expand All @@ -29,7 +30,16 @@
data_misfit,
regularization,
)
from pymatsolver import Pardiso

try:
from pymatsolver import Pardiso

pardiso_imported = True
except ImportError:
warnings.warn(
"Pardiso not installed see https://github.com/simpeg/pydiso/blob/main/README.md."
)
pardiso_imported = False

# from dask.distributed import Client, LocalCluster
from mtpy.modeling.simpeg.data_2d import Simpeg2DData
Expand Down Expand Up @@ -58,9 +68,13 @@ def __init__(self, dataframe, data_kwargs={}, mesh_kwargs={}, **kwargs):
self.ax = self.make_mesh()
self.air_conductivity = 1e-8
self.initial_conductivity = 1e-2
self.solver = "pardiso"
if pardiso_imported:
self.solver = "pardiso"
self._solvers_dict = {"pardiso": Pardiso}

self._solvers_dict = {"pardiso": Pardiso}
else:
self.solver = None
self._solvers_dict = {}

# regularization parameters
self.alpha_s = 1e-5
Expand Down Expand Up @@ -175,31 +189,54 @@ def conductivity_map(self):
"""
return self.exponent_map * self.active_map

def _get_solver(self):
"""
get solver
"""
try:
return self._solvers_dict[self.solver]
except KeyError:
return None

@property
def tm_simulation(self):
"""
Simulation for TE Mode
"""

return nsem.simulation.Simulation2DElectricField(
self.quad_tree.mesh,
survey=self.data.tm_survey,
sigmaMap=self.conductivity_map,
solver=self._solvers_dict[self.solver],
)
solver = self._get_solver()
if solver is not None:
return nsem.simulation.Simulation2DElectricField(
self.quad_tree.mesh,
survey=self.data.tm_survey,
sigmaMap=self.conductivity_map,
solver=solver,
)
else:
return nsem.simulation.Simulation2DElectricField(
self.quad_tree.mesh,
survey=self.data.tm_survey,
sigmaMap=self.conductivity_map,
)

@property
def te_simulation(self):
"""
Simulation for TE Mode
"""

return nsem.simulation.Simulation2DMagneticField(
self.quad_tree.mesh,
survey=self.data.te_survey,
sigmaMap=self.conductivity_map,
solver=self._solvers_dict[self.solver],
)
solver = self._get_solver()
if solver is not None:
return nsem.simulation.Simulation2DMagneticField(
self.quad_tree.mesh,
survey=self.data.te_survey,
sigmaMap=self.conductivity_map,
solver=solver,
)
else:
nsem.simulation.Simulation2DMagneticField(
self.quad_tree.mesh,
survey=self.data.te_survey,
sigmaMap=self.conductivity_map,
)

@property
def te_data_misfit(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
test_suite="tests",
tests_require=test_requirements,
url="https://github.com/MTgeophysics/mtpy-v2",
version="2.0.8",
version="2.0.9",
zip_safe=False,
package_data={"": []},
)

0 comments on commit 5933801

Please sign in to comment.