mtpy.modeling.simpeg.recipes package

Submodules

mtpy.modeling.simpeg.recipes.inversion_1d module

Created on Wed Nov 1 11:58:59 2023

@author: jpeacock

class mtpy.modeling.simpeg.recipes.inversion_1d.Simpeg1D(mt_dataframe: DataFrame | dict[str, Any] | None = None, resistivity_error: float = 10, phase_error: float = 2.5, **kwargs: Any)[source]

Bases: object

Run a 1D SimPEG inversion for MT apparent resistivity and phase.

Parameters:
  • mt_dataframe (pandas.DataFrame or dict or None, optional) – Input tabular data that can be consumed by mtpy.core.MTDataFrame.

  • **kwargs (Any) – Optional overrides for instance attributes such as mode, n_layers, rho_initial, etc.

Notes

For inversion, phase values are internally mapped to the SimPEG recursive 1D convention [-180, -90]. During plotting, phase values are converted to display convention [0, 90].

Examples

>>> inv = Simpeg1D(mt_dataframe=df, mode="tm", n_layers=60)
>>> inv.run_fixed_layer_inversion(maxIter=30)
>>> _ = inv.plot_response()
cull_from_difference(sub_df: DataFrame, max_diff_res: float = 1.0, max_diff_phase: float = 10.0) DataFrame[source]

Cull outliers using nearest-neighbor differences.

Resistivity culling is done in log10-difference space.

Parameters:
  • sub_df (pandas.DataFrame) – Input data table.

  • max_diff_res (float, default=1.0) – Maximum allowed neighboring difference in log10 resistivity.

  • max_diff_phase (float, default=10.0) – Maximum allowed neighboring difference in phase (degrees).

Returns:

Filtered table after removing rows flagged as outliers.

Return type:

pandas.DataFrame

cull_from_interpolated(sub_df: DataFrame, tolerance: float = 0.1, s_factor: float = 2) None[source]

Prototype spline-based data culling method.

Parameters:
  • sub_df (pandas.DataFrame) – Input data table.

  • tolerance (float, default=0.1) – Allowed absolute residual from spline prediction.

  • s_factor (float, default=2) – Smoothing multiplier applied to the spline fit.

Notes

This method is currently incomplete and does not return filtered data.

cull_from_model(iteration: int) None[source]

Placeholder for model-based culling logic.

Parameters:

iteration (int) – Inversion iteration number.

property data: ndarray

Flattened inversion data vector.

Returns:

Data vector ordered by [rho, phase] for each frequency.

Return type:

numpy.ndarray

property data_error: ndarray

Flattened data standard deviation vector.

Returns:

Error vector ordered by [rho_error, phase_error].

Return type:

numpy.ndarray

property frequencies: Series

Frequency series used by inversion.

Returns:

Frequencies in Hz sorted high-to-low.

Return type:

pandas.Series

property mesh: TensorMesh

Regularization mesh.

Returns:

1D tensor mesh used by SimPEG regularization.

Return type:

discretize.TensorMesh

property mode: str

Inversion mode.

Returns:

One of "te", "tm", or "det".

Return type:

str

property periods: Series

Period series used by inversion and plotting.

Returns:

Periods in seconds.

Return type:

pandas.Series

plot_model_fitting(scale: str = 'log', fig_num: int = 1) Figure[source]

Plot trade-off curve for inversion iterations.

Parameters:
  • scale (str, default="log") – Axis scale. Common choice is "log".

  • fig_num (int, default=1) – Matplotlib figure number.

Returns:

Created matplotlib figure.

Return type:

matplotlib.figure.Figure

Examples

>>> inv.run_fixed_layer_inversion()
>>> fig = inv.plot_model_fitting(scale="log")
plot_response(iteration: int | None = None, fig_num: int = 1, **kwargs: Any) Figure[source]

Plot recovered 1D model and data fit.

Parameters:
  • iteration (int or None, default=None) – Iteration index to plot. If None, uses the final iteration.

  • fig_num (int, default=1) – Matplotlib figure number.

  • **kwargs (Any) – Optional plotting controls such as y_limits and y_scale.

Returns:

Created matplotlib figure.

Return type:

matplotlib.figure.Figure

Examples

>>> inv.run_fixed_layer_inversion()
>>> fig = inv.plot_response(y_scale="log")
run_fixed_layer_inversion(cull_from_difference: bool = False, maxIter: int = 40, maxIterCG: int = 30, alpha_s: float = 1e-10, alpha_z: float = 1, beta0_ratio: float = 1, coolingFactor: float = 2, coolingRate: int = 1, chi_factor: float = 1, use_irls: bool = False, p_s: float = 2, p_z: float = 2, **kwargs: Any) None[source]

Run a fixed-layer 1D inversion.

Parameters:
  • cull_from_difference (bool, default=False) – If True, apply simple nearest-neighbor culling before inversion.

  • maxIter (int, default=40) – Maximum Gauss-Newton iterations.

  • maxIterCG (int, default=30) – Maximum conjugate-gradient iterations per GN step.

  • alpha_s (float, default=1e-10) – Smallness regularization weight.

  • alpha_z (float, default=1) – Vertical smoothness regularization weight.

  • beta0_ratio (float, default=1) – Initial beta estimate scaling.

  • coolingFactor (float, default=2) – Beta reduction factor.

  • coolingRate (int, default=1) – Number of iterations between beta updates.

  • chi_factor (float, default=1) – Target misfit factor.

  • use_irls (bool, default=False) – If True, enable IRLS regularization updates.

  • p_s (float, default=2) – Smallness norm exponent.

  • p_z (float, default=2) – Smoothness norm exponent.

  • **kwargs (Any) – Reserved for future optional controls.

Examples

>>> inv = Simpeg1D(mt_dataframe=df, mode="tm")
>>> inv.run_fixed_layer_inversion(maxIter=25, alpha_z=2.0)
property thicknesses: ndarray

Layer thicknesses used in the recursive 1D simulation.

Returns:

Layer thicknesses in meters ordered from top to bottom.

Return type:

numpy.ndarray

mtpy.modeling.simpeg.recipes.inversion_2d module

Created on Tue Aug 20 17:17:41 2024

@author: jpeacock

A vanilla recipe to invert 2D MT data.

  • For now the default is a quad tree mesh

  • Optimization: Inexact Gauss Newton

class mtpy.modeling.simpeg.recipes.inversion_2d.Simpeg2D(dataframe, data_kwargs={}, mesh_kwargs={}, mesh_type='tensor', **kwargs)[source]

Bases: object

A vanilla recipe to invert 2D MT data.

  • For now the default is a quad tree mesh

  • Optimization: Inexact Gauss Newton

  • Regularization: Sparse

# change mesh to tensor mesh.

property active_map

Active cells mapping

Returns:

DESCRIPTION

Return type:

TYPE

property beta_schedule

how quickly beta is reduced

Returns:

DESCRIPTION

Return type:

TYPE

property conductivity_map

conductivity mapping

Returns:

DESCRIPTION

Return type:

TYPE

property data_misfit

data misfit of all components TE + TM

property directives

list of directives to supply to the inversion

Returns:

DESCRIPTION

Return type:

TYPE

property exponent_map

compute fields on an exponential mapping :return: DESCRIPTION :rtype: TYPE

property inverse_problem

setup the inverse problem

Returns:

DESCRIPTION

Return type:

TYPE

property iterations

return dictionary of model outputs

make_mesh(**kwargs)[source]

make QuadTree Mesh

property optimization

optimization algorithm

default is InexactGaussNewton

plot_iteration(iteration_number, resistivity=True, **kwargs)[source]
plot_responses(iteration_number, **kwargs)[source]

Plot responses all together

Parameters:
  • iteration (TYPE) – DESCRIPTION

  • **kwargs

    DESCRIPTION

Returns:

DESCRIPTION

Return type:

TYPE

plot_tikhonov_curve()[source]

plot L-like curve

Returns:

DESCRIPTION

Return type:

TYPE

property reference_model

reference model

Returns:

DESCRIPTION

Return type:

TYPE

property regularization

Create sparse regularization using paramaters

  • alpha_s = smallness parameter

  • alpha_y = smoothing in y direction

  • alpha_z = smoothing in z direction

Returns:

DESCRIPTION

Return type:

TYPE

run_inversion()[source]

run the inversion using the attributes as input.

property starting_beta

set up the starting beta value

Returns:

DESCRIPTION

Return type:

TYPE

property target_misfit

target misfit

Returns:

DESCRIPTION

Return type:

TYPE

property te_data_misfit

data misfit of TE mode

property te_simulation

Simulation for TE Mode

property tm_data_misfit

data misfit of TM mode

property tm_simulation

Simulation for TE Mode

Module contents

Created on Wed Nov 1 11:58:39 2023

@author: jpeacock

class mtpy.modeling.simpeg.recipes.Simpeg1D(mt_dataframe: DataFrame | dict[str, Any] | None = None, resistivity_error: float = 10, phase_error: float = 2.5, **kwargs: Any)[source]

Bases: object

Run a 1D SimPEG inversion for MT apparent resistivity and phase.

Parameters:
  • mt_dataframe (pandas.DataFrame or dict or None, optional) – Input tabular data that can be consumed by mtpy.core.MTDataFrame.

  • **kwargs (Any) – Optional overrides for instance attributes such as mode, n_layers, rho_initial, etc.

Notes

For inversion, phase values are internally mapped to the SimPEG recursive 1D convention [-180, -90]. During plotting, phase values are converted to display convention [0, 90].

Examples

>>> inv = Simpeg1D(mt_dataframe=df, mode="tm", n_layers=60)
>>> inv.run_fixed_layer_inversion(maxIter=30)
>>> _ = inv.plot_response()
cull_from_difference(sub_df: DataFrame, max_diff_res: float = 1.0, max_diff_phase: float = 10.0) DataFrame[source]

Cull outliers using nearest-neighbor differences.

Resistivity culling is done in log10-difference space.

Parameters:
  • sub_df (pandas.DataFrame) – Input data table.

  • max_diff_res (float, default=1.0) – Maximum allowed neighboring difference in log10 resistivity.

  • max_diff_phase (float, default=10.0) – Maximum allowed neighboring difference in phase (degrees).

Returns:

Filtered table after removing rows flagged as outliers.

Return type:

pandas.DataFrame

cull_from_interpolated(sub_df: DataFrame, tolerance: float = 0.1, s_factor: float = 2) None[source]

Prototype spline-based data culling method.

Parameters:
  • sub_df (pandas.DataFrame) – Input data table.

  • tolerance (float, default=0.1) – Allowed absolute residual from spline prediction.

  • s_factor (float, default=2) – Smoothing multiplier applied to the spline fit.

Notes

This method is currently incomplete and does not return filtered data.

cull_from_model(iteration: int) None[source]

Placeholder for model-based culling logic.

Parameters:

iteration (int) – Inversion iteration number.

property data: ndarray

Flattened inversion data vector.

Returns:

Data vector ordered by [rho, phase] for each frequency.

Return type:

numpy.ndarray

property data_error: ndarray

Flattened data standard deviation vector.

Returns:

Error vector ordered by [rho_error, phase_error].

Return type:

numpy.ndarray

property frequencies: Series

Frequency series used by inversion.

Returns:

Frequencies in Hz sorted high-to-low.

Return type:

pandas.Series

property mesh: TensorMesh

Regularization mesh.

Returns:

1D tensor mesh used by SimPEG regularization.

Return type:

discretize.TensorMesh

property mode: str

Inversion mode.

Returns:

One of "te", "tm", or "det".

Return type:

str

property periods: Series

Period series used by inversion and plotting.

Returns:

Periods in seconds.

Return type:

pandas.Series

plot_model_fitting(scale: str = 'log', fig_num: int = 1) Figure[source]

Plot trade-off curve for inversion iterations.

Parameters:
  • scale (str, default="log") – Axis scale. Common choice is "log".

  • fig_num (int, default=1) – Matplotlib figure number.

Returns:

Created matplotlib figure.

Return type:

matplotlib.figure.Figure

Examples

>>> inv.run_fixed_layer_inversion()
>>> fig = inv.plot_model_fitting(scale="log")
plot_response(iteration: int | None = None, fig_num: int = 1, **kwargs: Any) Figure[source]

Plot recovered 1D model and data fit.

Parameters:
  • iteration (int or None, default=None) – Iteration index to plot. If None, uses the final iteration.

  • fig_num (int, default=1) – Matplotlib figure number.

  • **kwargs (Any) – Optional plotting controls such as y_limits and y_scale.

Returns:

Created matplotlib figure.

Return type:

matplotlib.figure.Figure

Examples

>>> inv.run_fixed_layer_inversion()
>>> fig = inv.plot_response(y_scale="log")
run_fixed_layer_inversion(cull_from_difference: bool = False, maxIter: int = 40, maxIterCG: int = 30, alpha_s: float = 1e-10, alpha_z: float = 1, beta0_ratio: float = 1, coolingFactor: float = 2, coolingRate: int = 1, chi_factor: float = 1, use_irls: bool = False, p_s: float = 2, p_z: float = 2, **kwargs: Any) None[source]

Run a fixed-layer 1D inversion.

Parameters:
  • cull_from_difference (bool, default=False) – If True, apply simple nearest-neighbor culling before inversion.

  • maxIter (int, default=40) – Maximum Gauss-Newton iterations.

  • maxIterCG (int, default=30) – Maximum conjugate-gradient iterations per GN step.

  • alpha_s (float, default=1e-10) – Smallness regularization weight.

  • alpha_z (float, default=1) – Vertical smoothness regularization weight.

  • beta0_ratio (float, default=1) – Initial beta estimate scaling.

  • coolingFactor (float, default=2) – Beta reduction factor.

  • coolingRate (int, default=1) – Number of iterations between beta updates.

  • chi_factor (float, default=1) – Target misfit factor.

  • use_irls (bool, default=False) – If True, enable IRLS regularization updates.

  • p_s (float, default=2) – Smallness norm exponent.

  • p_z (float, default=2) – Smoothness norm exponent.

  • **kwargs (Any) – Reserved for future optional controls.

Examples

>>> inv = Simpeg1D(mt_dataframe=df, mode="tm")
>>> inv.run_fixed_layer_inversion(maxIter=25, alpha_z=2.0)
property thicknesses: ndarray

Layer thicknesses used in the recursive 1D simulation.

Returns:

Layer thicknesses in meters ordered from top to bottom.

Return type:

numpy.ndarray

class mtpy.modeling.simpeg.recipes.Simpeg2D(dataframe, data_kwargs={}, mesh_kwargs={}, mesh_type='tensor', **kwargs)[source]

Bases: object

A vanilla recipe to invert 2D MT data.

  • For now the default is a quad tree mesh

  • Optimization: Inexact Gauss Newton

  • Regularization: Sparse

# change mesh to tensor mesh.

property active_map

Active cells mapping

Returns:

DESCRIPTION

Return type:

TYPE

property beta_schedule

how quickly beta is reduced

Returns:

DESCRIPTION

Return type:

TYPE

property conductivity_map

conductivity mapping

Returns:

DESCRIPTION

Return type:

TYPE

property data_misfit

data misfit of all components TE + TM

property directives

list of directives to supply to the inversion

Returns:

DESCRIPTION

Return type:

TYPE

property exponent_map

compute fields on an exponential mapping :return: DESCRIPTION :rtype: TYPE

property inverse_problem

setup the inverse problem

Returns:

DESCRIPTION

Return type:

TYPE

property iterations

return dictionary of model outputs

make_mesh(**kwargs)[source]

make QuadTree Mesh

property optimization

optimization algorithm

default is InexactGaussNewton

plot_iteration(iteration_number, resistivity=True, **kwargs)[source]
plot_responses(iteration_number, **kwargs)[source]

Plot responses all together

Parameters:
  • iteration (TYPE) – DESCRIPTION

  • **kwargs

    DESCRIPTION

Returns:

DESCRIPTION

Return type:

TYPE

plot_tikhonov_curve()[source]

plot L-like curve

Returns:

DESCRIPTION

Return type:

TYPE

property reference_model

reference model

Returns:

DESCRIPTION

Return type:

TYPE

property regularization

Create sparse regularization using paramaters

  • alpha_s = smallness parameter

  • alpha_y = smoothing in y direction

  • alpha_z = smoothing in z direction

Returns:

DESCRIPTION

Return type:

TYPE

run_inversion()[source]

run the inversion using the attributes as input.

property starting_beta

set up the starting beta value

Returns:

DESCRIPTION

Return type:

TYPE

property target_misfit

target misfit

Returns:

DESCRIPTION

Return type:

TYPE

property te_data_misfit

data misfit of TE mode

property te_simulation

Simulation for TE Mode

property tm_data_misfit

data misfit of TM mode

property tm_simulation

Simulation for TE Mode