From d197423b3060257a466b8028fa5c0877f643aeee Mon Sep 17 00:00:00 2001 From: benjamink Date: Tue, 8 Apr 2025 09:50:27 -0700 Subject: [PATCH 1/4] gradient_type as a key/value pair in ui.json. To be removed after deprecation period --- .../uijson/direct_current_2d_inversion.ui.json | 12 +----------- .../uijson/direct_current_3d_inversion.ui.json | 12 +----------- .../uijson/direct_current_batch2d_inversion.ui.json | 12 +----------- .../uijson/fdem1d_inversion.ui.json | 12 +----------- simpeg_drivers-assets/uijson/fem_inversion.ui.json | 12 +----------- .../uijson/gravity_inversion.ui.json | 12 +----------- .../uijson/induced_polarization_2d_inversion.ui.json | 12 +----------- .../uijson/induced_polarization_3d_inversion.ui.json | 12 +----------- .../induced_polarization_batch2d_inversion.ui.json | 12 +----------- .../uijson/joint_cross_gradient_inversion.ui.json | 12 +----------- .../uijson/joint_surveys_inversion.ui.json | 12 +----------- .../uijson/magnetic_scalar_inversion.ui.json | 12 +----------- .../uijson/magnetic_vector_inversion.ui.json | 12 +----------- .../uijson/magnetotellurics_inversion.ui.json | 12 +----------- .../uijson/tdem1d_inversion.ui.json | 12 +----------- simpeg_drivers-assets/uijson/tdem_inversion.ui.json | 12 +----------- .../uijson/tipper_inversion.ui.json | 12 +----------- 17 files changed, 17 insertions(+), 187 deletions(-) diff --git a/simpeg_drivers-assets/uijson/direct_current_2d_inversion.ui.json b/simpeg_drivers-assets/uijson/direct_current_2d_inversion.ui.json index 2d6357f4..768303a2 100644 --- a/simpeg_drivers-assets/uijson/direct_current_2d_inversion.ui.json +++ b/simpeg_drivers-assets/uijson/direct_current_2d_inversion.ui.json @@ -340,17 +340,7 @@ "enabled": true, "tooltip": "Lp-norm used in the z-smoothness term of the objective function." }, - "gradient_type": { - "choiceList": [ - "total", - "components" - ], - "group": "Sparse/blocky model", - "label": "Gradient type", - "value": "total", - "verbose": 3, - "tooltip": "Choose whether the IRLS weights for regularization terms are updated using total or partial gradients." - }, + "gradient_type": "total", "max_irls_iterations": { "min": 0, "group": "Sparse/blocky model", diff --git a/simpeg_drivers-assets/uijson/direct_current_3d_inversion.ui.json b/simpeg_drivers-assets/uijson/direct_current_3d_inversion.ui.json index 563028b3..f5421be6 100644 --- a/simpeg_drivers-assets/uijson/direct_current_3d_inversion.ui.json +++ b/simpeg_drivers-assets/uijson/direct_current_3d_inversion.ui.json @@ -309,17 +309,7 @@ "enabled": true, "tooltip": "Lp-norm used in the z-smoothness term of the objective function." }, - "gradient_type": { - "choiceList": [ - "total", - "components" - ], - "group": "Sparse/blocky model", - "label": "Gradient type", - "value": "total", - "verbose": 3, - "tooltip": "Choose whether the IRLS weights for regularization terms are updated using total or partial gradients." - }, + "gradient_type": "total", "max_irls_iterations": { "min": 0, "group": "Sparse/blocky model", diff --git a/simpeg_drivers-assets/uijson/direct_current_batch2d_inversion.ui.json b/simpeg_drivers-assets/uijson/direct_current_batch2d_inversion.ui.json index 6337065a..a7834938 100644 --- a/simpeg_drivers-assets/uijson/direct_current_batch2d_inversion.ui.json +++ b/simpeg_drivers-assets/uijson/direct_current_batch2d_inversion.ui.json @@ -321,17 +321,7 @@ "enabled": true, "tooltip": "Lp-norm used in the z-smoothness term of the objective function." }, - "gradient_type": { - "choiceList": [ - "total", - "components" - ], - "group": "Sparse/blocky model", - "label": "Gradient type", - "value": "total", - "verbose": 3, - "tooltip": "Choose whether the IRLS weights for regularization terms are updated using total or partial gradients." - }, + "gradient_type": "total", "max_irls_iterations": { "min": 0, "group": "Sparse/blocky model", diff --git a/simpeg_drivers-assets/uijson/fdem1d_inversion.ui.json b/simpeg_drivers-assets/uijson/fdem1d_inversion.ui.json index a0d7347b..21ec479a 100644 --- a/simpeg_drivers-assets/uijson/fdem1d_inversion.ui.json +++ b/simpeg_drivers-assets/uijson/fdem1d_inversion.ui.json @@ -335,17 +335,7 @@ "enabled": true, "tooltip": "Lp-norm used in the z-smoothness term of the objective function." }, - "gradient_type": { - "choiceList": [ - "total", - "components" - ], - "group": "Sparse/blocky model", - "label": "Gradient type", - "value": "total", - "verbose": 3, - "tooltip": "Choose whether the IRLS weights for regularization terms are updated using total or partial gradients." - }, + "gradient_type": "total", "max_irls_iterations": { "min": 0, "group": "Sparse/blocky model", diff --git a/simpeg_drivers-assets/uijson/fem_inversion.ui.json b/simpeg_drivers-assets/uijson/fem_inversion.ui.json index fc3c00cc..9bf36a8d 100644 --- a/simpeg_drivers-assets/uijson/fem_inversion.ui.json +++ b/simpeg_drivers-assets/uijson/fem_inversion.ui.json @@ -345,17 +345,7 @@ "enabled": true, "tooltip": "Lp-norm used in the z-smoothness term of the objective function." }, - "gradient_type": { - "choiceList": [ - "total", - "components" - ], - "group": "Sparse/blocky model", - "label": "Gradient type", - "value": "total", - "verbose": 3, - "tooltip": "Choose whether the IRLS weights for regularization terms are updated using total or partial gradients." - }, + "gradient_type": "total", "max_irls_iterations": { "min": 0, "group": "Sparse/blocky model", diff --git a/simpeg_drivers-assets/uijson/gravity_inversion.ui.json b/simpeg_drivers-assets/uijson/gravity_inversion.ui.json index 389ba540..e31ef754 100644 --- a/simpeg_drivers-assets/uijson/gravity_inversion.ui.json +++ b/simpeg_drivers-assets/uijson/gravity_inversion.ui.json @@ -578,17 +578,7 @@ "enabled": true, "tooltip": "Lp-norm used in the z-smoothness term of the objective function." }, - "gradient_type": { - "choiceList": [ - "total", - "components" - ], - "group": "Sparse/blocky model", - "label": "Gradient type", - "value": "total", - "verbose": 3, - "tooltip": "Choose whether the IRLS weights for regularization terms are updated using total or partial gradients." - }, + "gradient_type": "total", "max_irls_iterations": { "min": 0, "group": "Sparse/blocky model", diff --git a/simpeg_drivers-assets/uijson/induced_polarization_2d_inversion.ui.json b/simpeg_drivers-assets/uijson/induced_polarization_2d_inversion.ui.json index 940c72e0..9ad27c0d 100644 --- a/simpeg_drivers-assets/uijson/induced_polarization_2d_inversion.ui.json +++ b/simpeg_drivers-assets/uijson/induced_polarization_2d_inversion.ui.json @@ -348,17 +348,7 @@ "enabled": true, "tooltip": "Lp-norm used in the z-smoothness term of the objective function." }, - "gradient_type": { - "choiceList": [ - "total", - "components" - ], - "group": "Sparse/blocky model", - "label": "Gradient type", - "value": "total", - "verbose": 3, - "tooltip": "Choose whether the IRLS weights for regularization terms are updated using total or partial gradients." - }, + "gradient_type": "total", "max_irls_iterations": { "min": 0, "group": "Sparse/blocky model", diff --git a/simpeg_drivers-assets/uijson/induced_polarization_3d_inversion.ui.json b/simpeg_drivers-assets/uijson/induced_polarization_3d_inversion.ui.json index 829f197e..986f76cf 100644 --- a/simpeg_drivers-assets/uijson/induced_polarization_3d_inversion.ui.json +++ b/simpeg_drivers-assets/uijson/induced_polarization_3d_inversion.ui.json @@ -325,17 +325,7 @@ "enabled": true, "tooltip": "Lp-norm used in the z-smoothness term of the objective function." }, - "gradient_type": { - "choiceList": [ - "total", - "components" - ], - "group": "Sparse/blocky model", - "label": "Gradient type", - "value": "total", - "verbose": 3, - "tooltip": "Choose whether the IRLS weights for regularization terms are updated using total or partial gradients." - }, + "gradient_type": "total", "max_irls_iterations": { "min": 0, "group": "Sparse/blocky model", diff --git a/simpeg_drivers-assets/uijson/induced_polarization_batch2d_inversion.ui.json b/simpeg_drivers-assets/uijson/induced_polarization_batch2d_inversion.ui.json index bec2dade..682a91a6 100644 --- a/simpeg_drivers-assets/uijson/induced_polarization_batch2d_inversion.ui.json +++ b/simpeg_drivers-assets/uijson/induced_polarization_batch2d_inversion.ui.json @@ -332,17 +332,7 @@ "enabled": true, "tooltip": "Lp-norm used in the z-smoothness term of the objective function." }, - "gradient_type": { - "choiceList": [ - "total", - "components" - ], - "group": "Sparse/blocky model", - "label": "Gradient type", - "value": "total", - "verbose": 3, - "tooltip": "Choose whether the IRLS weights for regularization terms are updated using total or partial gradients." - }, + "gradient_type": "total", "max_irls_iterations": { "min": 0, "group": "Sparse/blocky model", diff --git a/simpeg_drivers-assets/uijson/joint_cross_gradient_inversion.ui.json b/simpeg_drivers-assets/uijson/joint_cross_gradient_inversion.ui.json index 03185f01..90416f3c 100644 --- a/simpeg_drivers-assets/uijson/joint_cross_gradient_inversion.ui.json +++ b/simpeg_drivers-assets/uijson/joint_cross_gradient_inversion.ui.json @@ -226,17 +226,7 @@ "lineEdit": false, "enabled": false }, - "gradient_type": { - "choiceList": [ - "total", - "components" - ], - "group": "Regularization", - "label": "Gradient type", - "value": "total", - "verbose": 3, - "enabled": false - }, + "gradient_type": "total", "max_irls_iterations": { "min": 0, "group": "Sparse/blocky model", diff --git a/simpeg_drivers-assets/uijson/joint_surveys_inversion.ui.json b/simpeg_drivers-assets/uijson/joint_surveys_inversion.ui.json index 3cf0c145..ca96cdc4 100644 --- a/simpeg_drivers-assets/uijson/joint_surveys_inversion.ui.json +++ b/simpeg_drivers-assets/uijson/joint_surveys_inversion.ui.json @@ -314,17 +314,7 @@ "enabled": true, "tooltip": "Lp-norm used in the z-smoothness term of the objective function." }, - "gradient_type": { - "choiceList": [ - "total", - "components" - ], - "group": "Sparse/blocky model", - "label": "Gradient type", - "value": "total", - "verbose": 3, - "tooltip": "Choose whether the IRLS weights for regularization terms are updated using total or partial gradients." - }, + "gradient_type": "total", "max_irls_iterations": { "min": 0, "group": "Sparse/blocky model", diff --git a/simpeg_drivers-assets/uijson/magnetic_scalar_inversion.ui.json b/simpeg_drivers-assets/uijson/magnetic_scalar_inversion.ui.json index cd0167ef..2485cf71 100644 --- a/simpeg_drivers-assets/uijson/magnetic_scalar_inversion.ui.json +++ b/simpeg_drivers-assets/uijson/magnetic_scalar_inversion.ui.json @@ -610,17 +610,7 @@ "enabled": true, "tooltip": "Lp-norm used in the z-smoothness term of the objective function." }, - "gradient_type": { - "choiceList": [ - "total", - "components" - ], - "group": "Sparse/blocky model", - "label": "Gradient type", - "value": "total", - "verbose": 3, - "tooltip": "Choose whether the IRLS weights for regularization terms are updated using total or partial gradients." - }, + "gradient_type": "total", "max_irls_iterations": { "min": 0, "group": "Sparse/blocky model", diff --git a/simpeg_drivers-assets/uijson/magnetic_vector_inversion.ui.json b/simpeg_drivers-assets/uijson/magnetic_vector_inversion.ui.json index 8916be7e..767c327e 100644 --- a/simpeg_drivers-assets/uijson/magnetic_vector_inversion.ui.json +++ b/simpeg_drivers-assets/uijson/magnetic_vector_inversion.ui.json @@ -675,17 +675,7 @@ "enabled": true, "tooltip": "Lp-norm used in the z-smoothness term of the objective function." }, - "gradient_type": { - "choiceList": [ - "total", - "components" - ], - "group": "Sparse/blocky model", - "label": "Gradient type", - "value": "total", - "verbose": 3, - "tooltip": "Choose whether the IRLS weights for regularization terms are updated using total or partial gradients." - }, + "gradient_type": "total", "max_irls_iterations": { "min": 0, "group": "Sparse/blocky model", diff --git a/simpeg_drivers-assets/uijson/magnetotellurics_inversion.ui.json b/simpeg_drivers-assets/uijson/magnetotellurics_inversion.ui.json index 0f65c8b4..ec31a3f1 100644 --- a/simpeg_drivers-assets/uijson/magnetotellurics_inversion.ui.json +++ b/simpeg_drivers-assets/uijson/magnetotellurics_inversion.ui.json @@ -530,17 +530,7 @@ "enabled": true, "tooltip": "Lp-norm used in the z-smoothness term of the objective function." }, - "gradient_type": { - "choiceList": [ - "total", - "components" - ], - "group": "Sparse/blocky model", - "label": "Gradient type", - "value": "total", - "verbose": 3, - "tooltip": "Choose whether the IRLS weights for regularization terms are updated using total or partial gradients." - }, + "gradient_type": "total", "max_irls_iterations": { "min": 0, "group": "Sparse/blocky model", diff --git a/simpeg_drivers-assets/uijson/tdem1d_inversion.ui.json b/simpeg_drivers-assets/uijson/tdem1d_inversion.ui.json index d173d1a1..a527abc8 100644 --- a/simpeg_drivers-assets/uijson/tdem1d_inversion.ui.json +++ b/simpeg_drivers-assets/uijson/tdem1d_inversion.ui.json @@ -313,17 +313,7 @@ "enabled": true, "tooltip": "Lp-norm used in the z-smoothness term of the objective function." }, - "gradient_type": { - "choiceList": [ - "total", - "components" - ], - "group": "Sparse/blocky model", - "label": "Gradient type", - "value": "total", - "verbose": 3, - "tooltip": "Choose whether the IRLS weights for regularization terms are updated using total or partial gradients." - }, + "gradient_type": "total", "max_irls_iterations": { "min": 0, "group": "Sparse/blocky model", diff --git a/simpeg_drivers-assets/uijson/tdem_inversion.ui.json b/simpeg_drivers-assets/uijson/tdem_inversion.ui.json index b6e49561..c5c8f095 100644 --- a/simpeg_drivers-assets/uijson/tdem_inversion.ui.json +++ b/simpeg_drivers-assets/uijson/tdem_inversion.ui.json @@ -380,17 +380,7 @@ "enabled": true, "tooltip": "Lp-norm used in the z-smoothness term of the objective function." }, - "gradient_type": { - "choiceList": [ - "total", - "components" - ], - "group": "Sparse/blocky model", - "label": "Gradient type", - "value": "total", - "verbose": 3, - "tooltip": "Choose whether the IRLS weights for regularization terms are updated using total or partial gradients." - }, + "gradient_type": "total", "max_irls_iterations": { "min": 0, "group": "Sparse/blocky model", diff --git a/simpeg_drivers-assets/uijson/tipper_inversion.ui.json b/simpeg_drivers-assets/uijson/tipper_inversion.ui.json index 50d78389..d90d45f1 100644 --- a/simpeg_drivers-assets/uijson/tipper_inversion.ui.json +++ b/simpeg_drivers-assets/uijson/tipper_inversion.ui.json @@ -410,17 +410,7 @@ "enabled": true, "tooltip": "Lp-norm used in the z-smoothness term of the objective function." }, - "gradient_type": { - "choiceList": [ - "total", - "components" - ], - "group": "Sparse/blocky model", - "label": "Gradient type", - "value": "total", - "verbose": 3, - "tooltip": "Choose whether the IRLS weights for regularization terms are updated using total or partial gradients." - }, + "gradient_type": "total", "max_irls_iterations": { "min": 0, "group": "Sparse/blocky model", From d15f501e16fe967184c853fd63cd83584a0fb007 Mon Sep 17 00:00:00 2001 From: benjamink Date: Tue, 8 Apr 2025 12:56:28 -0700 Subject: [PATCH 2/4] deprecate gradient_type --- simpeg_drivers/potential_fields/gravity/uijson.py | 1 + 1 file changed, 1 insertion(+) diff --git a/simpeg_drivers/potential_fields/gravity/uijson.py b/simpeg_drivers/potential_fields/gravity/uijson.py index 0d0196b9..11b60080 100644 --- a/simpeg_drivers/potential_fields/gravity/uijson.py +++ b/simpeg_drivers/potential_fields/gravity/uijson.py @@ -149,6 +149,7 @@ class GravityInversionUIJson(SimPEGDriversUIJson): out_group: GroupForm generate_sweep: BoolForm distributed_workers: str + gradient_type: Deprecated | None = None output_tile_files: Deprecated | None = None inversion_style: Deprecated | None = None max_ram: Deprecated | None = None From bc0689c6d62c2878beb5cad45d1409ee6c644846 Mon Sep 17 00:00:00 2001 From: benjamink Date: Wed, 9 Apr 2025 07:36:38 -0700 Subject: [PATCH 3/4] remove global gradient_type setting --- simpeg_drivers/driver.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/simpeg_drivers/driver.py b/simpeg_drivers/driver.py index 1b1cb2a9..e2bbcab1 100644 --- a/simpeg_drivers/driver.py +++ b/simpeg_drivers/driver.py @@ -540,15 +540,6 @@ def get_regularization(self): reg_func.norms = [fun.norm for fun in functions] reg_funcs.append(reg_func) - # TODO - To be deprcated on GEOPY-2109 - if getattr(self.params, "gradient_type") is not None: - for reg in reg_funcs: - setattr( - reg, - "gradient_type", - getattr(self.params, "gradient_type"), - ) - return objective_function.ComboObjectiveFunction(objfcts=reg_funcs) def get_tiles(self): From 12f251e42ef061b3d8da511d84cf77b47cabd983 Mon Sep 17 00:00:00 2001 From: benjamink Date: Wed, 9 Apr 2025 11:45:18 -0700 Subject: [PATCH 4/4] Set rotations to zero to use a gradient_type of 'components' and reset the targets --- tests/run_tests/driver_mvi_test.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/run_tests/driver_mvi_test.py b/tests/run_tests/driver_mvi_test.py index ba742e87..458afac4 100644 --- a/tests/run_tests/driver_mvi_test.py +++ b/tests/run_tests/driver_mvi_test.py @@ -13,6 +13,7 @@ from pathlib import Path import numpy as np +from geoh5py.groups import PropertyGroup from geoh5py.groups.property_group import GroupTypeEnum from geoh5py.objects import Curve from geoh5py.workspace import Workspace @@ -34,7 +35,7 @@ # To test the full run and validate the inversion. # Move this file out of the test directory and run. -target_mvi_run = {"data_norm": 6.3559205278626525, "phi_d": 0.0143, "phi_m": 0.0009} +target_mvi_run = {"data_norm": 6.3559205278626525, "phi_d": 0.0091, "phi_m": 0.00603} def test_magnetic_vector_fwr_run( @@ -95,6 +96,19 @@ def test_magnetic_vector_run( topography = geoh5.get_entity("topography")[0] inducing_field = (50000.0, 90.0, 0.0) + dip, direction = mesh.add_data( + { + "dip": {"values": np.zeros(mesh.n_cells)}, + "direction": {"values": np.zeros(mesh.n_cells)}, + } + ) + gradient_rotation = PropertyGroup( + name="gradient_rotations", + property_group_type=GroupTypeEnum.DIPDIR, + properties=[dip, direction], + parent=mesh, + ) + # Run the inverse active_cells = ActiveCellsOptions(topography_object=topography) params = MVIInversionOptions( @@ -111,10 +125,10 @@ def test_magnetic_vector_run( x_norm=1.0, y_norm=1.0, z_norm=1.0, - gradient_type="components", tmi_channel=tmi, tmi_uncertainty=4.0, max_global_iterations=max_iterations, + gradient_rotation=gradient_rotation, initial_beta_ratio=1e1, store_sensitivities="ram", save_sensitivities=True,