From ca0a45b13e05ec5c3bc3b55ceb5eb4017ff59ce0 Mon Sep 17 00:00:00 2001 From: domfournier Date: Fri, 8 May 2026 13:01:54 -0700 Subject: [PATCH 1/2] Accept nan of negative if data is ndv --- simpeg_drivers/options.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/simpeg_drivers/options.py b/simpeg_drivers/options.py index 2bbb898a..71f2a577 100644 --- a/simpeg_drivers/options.py +++ b/simpeg_drivers/options.py @@ -632,8 +632,10 @@ def uncertainties(self) -> dict[str, dict[float, np.ndarray | None]]: for k in self.active_components: out[k] = self.component_uncertainty(k) - for data in out[k].values(): - if np.any(np.isnan(data)) or np.any(data < 0): + for data, uncert in zip( + out[k].values(), self.component_data(k).values(), strict=True + ): + if np.any((np.isnan(uncert) | (uncert < 0)) & ~np.isnan(data)): flags.append(f"{k} component") break From f51773e8e7ea976782e8b2543419ea9531cfb4e4 Mon Sep 17 00:00:00 2001 From: domfournier Date: Fri, 8 May 2026 13:12:28 -0700 Subject: [PATCH 2/2] Add unit test --- simpeg_drivers/options.py | 2 +- tests/run_tests/driver_mt_test.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/simpeg_drivers/options.py b/simpeg_drivers/options.py index 71f2a577..77e23c09 100644 --- a/simpeg_drivers/options.py +++ b/simpeg_drivers/options.py @@ -632,7 +632,7 @@ def uncertainties(self) -> dict[str, dict[float, np.ndarray | None]]: for k in self.active_components: out[k] = self.component_uncertainty(k) - for data, uncert in zip( + for uncert, data in zip( out[k].values(), self.component_data(k).values(), strict=True ): if np.any((np.isnan(uncert) | (uncert < 0)) & ~np.isnan(data)): diff --git a/tests/run_tests/driver_mt_test.py b/tests/run_tests/driver_mt_test.py index ac54d509..b0a68eac 100644 --- a/tests/run_tests/driver_mt_test.py +++ b/tests/run_tests/driver_mt_test.py @@ -162,12 +162,23 @@ def test_bad_uncertainties( topography = components.topography data_kwargs = setup_data(geoh5, survey) - for elem in ["uncertainty_zxx_imag_[0]", "uncertainty_zyx_real_[0]"]: + # Add NDV to some uncertainties + for elem in [ + "uncertainty_zxx_imag_[0]", + "uncertainty_zyx_real_[0]", + "uncertainty_zyx_imag_[0]", + ]: data = survey.get_entity(elem)[0] vals = data.values vals[0] = np.nan data.values = vals + # Also NDV the data for one of them + data = survey.get_entity("Iteration_0_zyx_imag_[0]")[0] + vals = data.values + vals[0] = np.nan + data.values = vals + # Run the inverse params = MTInversionOptions.build( geoh5=geoh5, @@ -184,6 +195,7 @@ def test_bad_uncertainties( assert "zxx_imag" in str(error.value) assert "zyx_real" in str(error.value) + assert "zyx_imag" not in str(error.value) def test_magnetotellurics_run(tmp_path: Path, max_iterations=1, pytest=True):