Skip to content

Updates to Simpeg inversions#100

Merged
kujaku11 merged 29 commits into
mainfrom
updates
Jun 6, 2026
Merged

Updates to Simpeg inversions#100
kujaku11 merged 29 commits into
mainfrom
updates

Conversation

@kujaku11

@kujaku11 kujaku11 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Description

There were some updates in simpeg 0.25 which need to be updated in mtpy-v2.

There is also a change needed for impedance units. The logic was originally to just set the units to "mt" or "ohm" but that was incorrect because if you input "mt" units but then changed the units to "ohm" you wouldn't get the correct resistivity values. Should change the logic to attributes "input_units" and "output_units" to the impedance tensor. Then internally be sure to set output units for simpeg data to "ohm".

Motivation and Context

We want to plugin to the latest version of simpeg.

How Has This Been Tested?

Adding tests

Screenshots (if appropriate):

Types of changes

  • [x ] Bug fix (non-breaking change which fixes an issue)
  • [x ] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

kujaku11 and others added 22 commits May 28, 2026 14:01
Add default resistivity/phase error parameters to MT.to_simpeg_1d and pass impedance units to Simpeg1D. Heavily refactor Simpeg1D: add type hints, docstrings and defaults, introduce resistivity_error and phase_error attributes, compute model error columns for modes (te/tm/det), and ensure phase values are mapped to the recursive 1D SimPEG branch before inversion. Improve robustness by filling NaN errors, removing zero rows, and adding a plotting-phase conversion for display; return matplotlib Figure from plot methods and fix axis labels/limits. Also include small API/behavior changes (receiver component/orientation update, minor culling prototypes, and other readability/typing improvements).
Add a new test suite for the Simpeg1D inversion recipe and run it in CI (non-Windows runners). The workflow was updated to execute the new tests.

Fixes and improvements in mtpy/modeling/simpeg/recipes/inversion_1d.py:
- Initialize resistivity_error and phase_error on the instance earlier.
- Rework the 'det' branch error handling to compute res_model_error and phase_model_error from the z_object using numpy indexing instead of manipulating the dataframe in-place.
- Commented/clarified phase-model-error override logic.
- Remove an unnecessary stray line and minor print cleanup.
- Adjust plotting: use _plot_z ordering (no reverse) and relax default y-axis lower limit from 0.01 to 0.5.

Tests: add tests/modeling/simpeg/test_simpeg_1d_inversion_recipe.py covering mode-specific sub-dataframe construction, phase bounds, invalid-mode handling, data/error vector lengths, plotting conversion, and a short integration smoke test for TE (skipped on Windows).
Add explicit impedance unit support and dataset-based TF computations. Introduce MT_TO_OHM_FACTOR and IMPEDANCE_UNITS and extend tf_helpers functions to accept z_units ("mt" or "ohm") with appropriate conversions. Normalize units string in Z.units setter, switch Z properties to read values from the dataset.transfer_function* attributes (instead of raw z/z_error) and apply the scale factor consistently (including determinant and its errors). Add tests: verify resistivity/phase remain unchanged when switching units and assert final misfit is below target in the SimPEG 2D recipe test.
Refactor impedance unit handling to allow separate input_units and output_units on Z while keeping internal storage in MT units. Add backward-compatible units alias (units -> output_units) and validate unit choices; incoming arrays are scaled by input_units and returned arrays by output_units. Update MT dataframe import/export to set Z.output_units (and pass units into to_z_object) so dataframes are interpreted and exposed with requested units. Add/adjust tests to cover input/output unit behavior, round-trip conversions, and error handling.
Add explicit impedance unit handling across MT, MTData, and MTDataFrame conversions. MTDataFrame.from_z_object now accepts a units parameter and uses a copy of the Z object (setting its output_units) to avoid mutating the input; MT.to_dataframe and MTData.to_dataframe/from_dataframe call through with impedance_units. Z objects are constructed with input_units/output_units where appropriate and resistivity/phase→Z conversion forces mt input_units. Tests updated to cover round-trip conversions with ohm units and to assert that exporting with units does not mutate the source Z object.
Document that transfer-function rotation operates on the coordinate reference frame (not the physical measurement), with an example for frame-angle sign. Add a unit test (test_rotation_shifts_estimated_strike_with_frame_rotation) that verifies a +10° frame rotation produces a -10° shift in estimated invariant strike and phase-tensor azimuth (handles 180° strike ambiguity and wraps differences appropriately).
@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.01299% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.27%. Comparing base (386a776) to head (03ce0e2).

Files with missing lines Patch % Lines
mtpy/imaging/plot_phase_tensor_maps.py 0.00% 7 Missing ⚠️
mtpy/core/transfer_function/tf_helpers.py 57.14% 6 Missing ⚠️
mtpy/modeling/simpeg/recipes/inversion_1d.py 90.32% 6 Missing ⚠️
mtpy/core/mt.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #100      +/-   ##
==========================================
+ Coverage   40.86%   41.27%   +0.41%     
==========================================
  Files         121      121              
  Lines       24265    24342      +77     
==========================================
+ Hits         9915    10048     +133     
+ Misses      14350    14294      -56     
Flag Coverage Δ
tests 41.27% <87.01%> (+0.41%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kujaku11 kujaku11 self-assigned this Jun 3, 2026
@kujaku11 kujaku11 added release:patch patch release and removed release:patch patch release labels Jun 3, 2026
@kujaku11 kujaku11 merged commit 2e6a744 into main Jun 6, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:patch patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant