From 368b2272a42c6b2dd6ca6731a9a4438da3e51050 Mon Sep 17 00:00:00 2001 From: dominiquef Date: Mon, 7 Apr 2025 14:45:57 -0700 Subject: [PATCH 1/4] Replace with Deprecated annotation --- .../potential_fields/magnetic_vector/params.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/simpeg_drivers/potential_fields/magnetic_vector/params.py b/simpeg_drivers/potential_fields/magnetic_vector/params.py index ef0b9973..7ba547e6 100644 --- a/simpeg_drivers/potential_fields/magnetic_vector/params.py +++ b/simpeg_drivers/potential_fields/magnetic_vector/params.py @@ -13,9 +13,9 @@ from pathlib import Path from typing import ClassVar -from warnings import warn from geoh5py.data import FloatData +from geoh5py.ui_json.annotations import Deprecated from pydantic import model_validator from simpeg_drivers import assets_path @@ -129,19 +129,10 @@ class MVIInversionOptions(BaseInversionOptions): inducing_field_strength: float | FloatData = 50000.0 inducing_field_inclination: float | FloatData = 90.0 inducing_field_declination: float | FloatData = 0.0 + + lower_bound: Deprecated | None = None + starting_inclination: float | FloatData | None = None starting_declination: float | FloatData | None = None reference_inclination: float | FloatData | None = None reference_declination: float | FloatData | None = None - - @model_validator(mode="after") - def validate_lower_bound(self): - if self.lower_bound is not None: - warn( - "Parameter 'lower_bound' for Magnetic Vector Inversion has been deprecated. " - "Defaulting to the negative value of 'upper_bound'.", - DeprecationWarning, - stacklevel=1, - ) - self.lower_bound = None - return self From 16f889afdf7ed56bd01f5a2c7697662535840b68 Mon Sep 17 00:00:00 2001 From: dominiquef Date: Mon, 7 Apr 2025 14:55:47 -0700 Subject: [PATCH 2/4] Fix test --- tests/run_tests/driver_mvi_test.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/run_tests/driver_mvi_test.py b/tests/run_tests/driver_mvi_test.py index ba742e87..61420ef5 100644 --- a/tests/run_tests/driver_mvi_test.py +++ b/tests/run_tests/driver_mvi_test.py @@ -10,6 +10,7 @@ from __future__ import annotations +import logging from pathlib import Path import numpy as np @@ -147,6 +148,7 @@ def test_magnetic_vector_run( def test_magnetic_vector_bounds_run( tmp_path: Path, + caplog, max_iterations=4, pytest=True, ): @@ -167,10 +169,7 @@ def test_magnetic_vector_bounds_run( # Run the inverse active_cells = ActiveCellsOptions(topography_object=topography) - with warns( - DeprecationWarning, - match="Parameter 'lower_bound' for Magnetic Vector Inversion", - ): + with caplog.at_level(logging.WARNING): params = MVIInversionOptions( geoh5=geoh5, mesh=mesh, @@ -198,6 +197,8 @@ def test_magnetic_vector_bounds_run( ) params.write_ui_json(path=tmp_path / "Inv_run.ui.json") + assert "Skipping deprecated field: lower_bound" in caplog.text + driver = MVIInversionDriver(params) assert np.all(driver.models.lower_bound == -upper_bound) From 5cb86fb5f9b02bd4cf9ff6e5cea3a590ce6577b5 Mon Sep 17 00:00:00 2001 From: dominiquef Date: Mon, 7 Apr 2025 14:45:57 -0700 Subject: [PATCH 3/4] Replace with Deprecated annotation --- .../potential_fields/magnetic_vector/options.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/simpeg_drivers/potential_fields/magnetic_vector/options.py b/simpeg_drivers/potential_fields/magnetic_vector/options.py index fa5bf436..562b7262 100644 --- a/simpeg_drivers/potential_fields/magnetic_vector/options.py +++ b/simpeg_drivers/potential_fields/magnetic_vector/options.py @@ -13,9 +13,9 @@ from pathlib import Path from typing import ClassVar -from warnings import warn from geoh5py.data import FloatData +from geoh5py.ui_json.annotations import Deprecated from pydantic import model_validator from simpeg_drivers import assets_path @@ -129,19 +129,10 @@ class MVIInversionOptions(BaseInversionOptions): inducing_field_strength: float | FloatData = 50000.0 inducing_field_inclination: float | FloatData = 90.0 inducing_field_declination: float | FloatData = 0.0 + + lower_bound: Deprecated | None = None + starting_inclination: float | FloatData | None = None starting_declination: float | FloatData | None = None reference_inclination: float | FloatData | None = None reference_declination: float | FloatData | None = None - - @model_validator(mode="after") - def validate_lower_bound(self): - if self.lower_bound is not None: - warn( - "Parameter 'lower_bound' for Magnetic Vector Inversion has been deprecated. " - "Defaulting to the negative value of 'upper_bound'.", - DeprecationWarning, - stacklevel=1, - ) - self.lower_bound = None - return self From 571586444bb17b7e89fc66254d16655ec2870b49 Mon Sep 17 00:00:00 2001 From: dominiquef Date: Mon, 7 Apr 2025 14:55:47 -0700 Subject: [PATCH 4/4] Fix test --- tests/run_tests/driver_mvi_test.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/run_tests/driver_mvi_test.py b/tests/run_tests/driver_mvi_test.py index 33671e73..c90abf65 100644 --- a/tests/run_tests/driver_mvi_test.py +++ b/tests/run_tests/driver_mvi_test.py @@ -10,6 +10,7 @@ from __future__ import annotations +import logging from pathlib import Path import numpy as np @@ -165,6 +166,7 @@ def test_magnetic_vector_run( def test_magnetic_vector_bounds_run( tmp_path: Path, + caplog, max_iterations=4, pytest=True, ): @@ -185,10 +187,7 @@ def test_magnetic_vector_bounds_run( # Run the inverse active_cells = ActiveCellsOptions(topography_object=topography) - with warns( - DeprecationWarning, - match="Parameter 'lower_bound' for Magnetic Vector Inversion", - ): + with caplog.at_level(logging.WARNING): params = MVIInversionOptions( geoh5=geoh5, mesh=mesh, @@ -216,6 +215,8 @@ def test_magnetic_vector_bounds_run( ) params.write_ui_json(path=tmp_path / "Inv_run.ui.json") + assert "Skipping deprecated field: lower_bound" in caplog.text + driver = MVIInversionDriver(params) assert np.all(driver.models.lower_bound == -upper_bound)