Skip to content

Commit 4c2e838

Browse files
committed
2 parents 2f31e14 + e068ab3 commit 4c2e838

9 files changed

Lines changed: 20 additions & 80 deletions

simpeg_drivers-assets/uijson/direct_current_2d_inversion.ui.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@
285285
"label": "Gradient rotation",
286286
"optional": true,
287287
"enabled": false,
288+
"visible": false,
288289
"parent": "mesh",
289290
"value": ""
290291
},

simpeg_drivers-assets/uijson/direct_current_batch2d_inversion.ui.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@
267267
"label": "Gradient rotation",
268268
"optional": true,
269269
"enabled": false,
270+
"visible": false,
270271
"parent": "mesh",
271272
"value": ""
272273
},

simpeg_drivers-assets/uijson/induced_polarization_2d_inversion.ui.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@
294294
"label": "Gradient rotation",
295295
"optional": true,
296296
"enabled": false,
297+
"visible": false,
297298
"parent": "mesh",
298299
"value": ""
299300
},

simpeg_drivers-assets/uijson/induced_polarization_batch2d_inversion.ui.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@
278278
"label": "Gradient rotation",
279279
"optional": true,
280280
"enabled": false,
281+
"visible": false,
281282
"parent": "mesh",
282283
"value": ""
283284
},

simpeg_drivers/components/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class InversionModelCollection:
5858
5959
"""
6060

61+
model_types = MODEL_TYPES
62+
6163
def __init__(self, driver: InversionDriver):
6264
"""
6365
:param driver: Parental InversionDriver class.

simpeg_drivers/driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ def get_regularization(self):
473473
components, weight_names, reg_func.objfcts
474474
):
475475
if getattr(self.models, weight_name) is None:
476-
setattr(reg_funcs, weight_name, 0.0)
476+
setattr(reg_func, weight_name, 0.0)
477477
functions.append(fun)
478478
continue
479479

tests/models_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_zero_reference_model(tmp_path: Path):
7272
geoh5 = params.geoh5
7373
with geoh5.open():
7474
driver = MVIInversionDriver(params)
75-
_ = InversionModel(driver, "reference")
75+
_ = InversionModel(driver, "reference", is_vector=True)
7676
incl = np.unique(geoh5.get_entity("reference_inclination")[0].values)
7777
decl = np.unique(geoh5.get_entity("reference_declination")[0].values)
7878
assert len(incl) == 1
@@ -87,7 +87,7 @@ def test_collection(tmp_path: Path):
8787
driver = MVIInversionDriver(params)
8888
models = InversionModelCollection(driver)
8989
models.remove_air(driver.models.active_cells)
90-
starting = InversionModel(driver, "starting")
90+
starting = InversionModel(driver, "starting", is_vector=True)
9191
starting.remove_air(driver.models.active_cells)
9292
np.testing.assert_allclose(models.starting, starting.model, atol=1e-7)
9393

@@ -96,7 +96,7 @@ def test_initialize(tmp_path: Path):
9696
params = get_mvi_params(tmp_path)
9797
with params.geoh5.open():
9898
driver = MVIInversionDriver(params)
99-
starting_model = InversionModel(driver, "starting")
99+
starting_model = InversionModel(driver, "starting", is_vector=True)
100100
assert len(starting_model.model) == 3 * driver.inversion_mesh.n_cells
101101
assert len(np.unique(starting_model.model)) == 3
102102

@@ -117,7 +117,7 @@ def test_model_from_object(tmp_path: Path):
117117
point_object.add_data({"test_data": {"values": vals}})
118118
data_object = geoh5.get_entity("test_data")[0]
119119
params.lower_bound = data_object
120-
lower_bound = InversionModel(driver, "lower_bound")
120+
lower_bound = InversionModel(driver, "lower_bound", is_vector=True)
121121
nc = int(len(lower_bound.model) / 3)
122122
A = driver.inversion_mesh.mesh.cell_centers
123123
b = lower_bound.model[:nc]

tests/run_tests/driver_grav_test.py

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import numpy as np
1717
from geoapps_utils.utils.importing import GeoAppsError
18-
from geoh5py.groups import PropertyGroup
1918
from geoh5py.workspace import Workspace
2019
from pytest import raises
2120

@@ -35,7 +34,7 @@
3534
# To test the full run and validate the inversion.
3635
# Move this file out of the test directory and run.
3736

38-
target_run = {"data_norm": 0.0028055269276044915, "phi_d": 8.32e-05, "phi_m": 0.00333}
37+
target_run = {"data_norm": 0.0028055269276044915, "phi_d": 8.32e-05, "phi_m": 0.0038}
3938

4039

4140
def test_gravity_fwr_run(
@@ -189,75 +188,6 @@ def test_gravity_run(
189188
assert np.all(nan_ind == inactive_ind)
190189

191190

192-
def test_rotated_gradient(
193-
tmp_path: Path,
194-
max_iterations=1,
195-
pytest=True,
196-
):
197-
workpath = tmp_path / "inversion_test.ui.geoh5"
198-
if pytest:
199-
workpath = tmp_path.parent / "test_gravity_fwr_run0" / "inversion_test.ui.geoh5"
200-
201-
with Workspace(workpath) as geoh5:
202-
gz = geoh5.get_entity("Iteration_0_gz")[0]
203-
mesh = geoh5.get_entity("mesh")[0]
204-
205-
inds = (mesh.centroids[:, 0] > -35) & (mesh.centroids[:, 0] < 35)
206-
norms = np.ones(mesh.n_cells) * 2
207-
norms[inds] = 0
208-
gradient_norms = mesh.add_data({"norms": {"values": norms}})
209-
210-
topography = geoh5.get_entity("topography")[0]
211-
212-
# Turn some values to nan
213-
values = gz.values.copy()
214-
values[0] = np.nan
215-
gz.values = values
216-
217-
# Rotate the gradients
218-
219-
direction, dip = mesh.add_data(
220-
{
221-
"gradient_direction": {"values": 90 * np.ones(mesh.n_cells)},
222-
"gradient_dip": {"values": 45 * np.ones(mesh.n_cells)},
223-
}
224-
)
225-
gradient_rotation = PropertyGroup(
226-
parent=mesh,
227-
name="gradient_rotation",
228-
property_group_type="Dip direction & dip",
229-
properties=[direction, dip],
230-
)
231-
232-
# Run the inverse
233-
active_cells = ActiveCellsOptions(topography_object=topography)
234-
params = GravityInversionOptions(
235-
geoh5=geoh5,
236-
mesh=mesh,
237-
active_cells=active_cells,
238-
data_object=gz.parent,
239-
starting_model=1e-4,
240-
reference_model=0.0,
241-
gradient_rotation=gradient_rotation,
242-
s_norm=0.0,
243-
x_norm=gradient_norms,
244-
y_norm=gradient_norms,
245-
z_norm=gradient_norms,
246-
gradient_type="components",
247-
gz_channel=gz,
248-
gz_uncertainty=2e-3,
249-
lower_bound=0.0,
250-
max_global_iterations=max_iterations,
251-
initial_beta_ratio=1e-2,
252-
percentile=100,
253-
store_sensitivities="ram",
254-
save_sensitivities=True,
255-
)
256-
params.write_ui_json(path=tmp_path / "Inv_run.ui.json")
257-
258-
_ = GravityInversionDriver.start(str(tmp_path / "Inv_run.ui.json"))
259-
260-
261191
if __name__ == "__main__":
262192
# Full run
263193
test_gravity_fwr_run(

tests/run_tests/driver_rotated_gradients_test.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
# To test the full run and validate the inversion.
3636
# Move this file out of the test directory and run.
3737

38-
target_run = {"data_norm": 0.0028055269276044915, "phi_d": 8.32e-05, "phi_m": 0.00333}
38+
target_run = {"data_norm": 0.006830937520353864, "phi_d": 0.0276, "phi_m": 0.0288}
3939

4040

41-
def test_gravity_fwr_run(
41+
def test_gravity_rotated_grad_fwr_run(
4242
tmp_path: Path,
4343
n_grid_points=2,
4444
refinement=(2,),
@@ -76,7 +76,11 @@ def test_rotated_grad_run(
7676
):
7777
workpath = tmp_path / "inversion_test.ui.geoh5"
7878
if pytest:
79-
workpath = tmp_path.parent / "test_gravity_fwr_run0" / "inversion_test.ui.geoh5"
79+
workpath = (
80+
tmp_path.parent
81+
/ "test_gravity_rotated_grad_fwr_0"
82+
/ "inversion_test.ui.geoh5"
83+
)
8084

8185
with Workspace(workpath) as geoh5:
8286
gz = geoh5.get_entity("Iteration_0_gz")[0]
@@ -141,7 +145,7 @@ def test_rotated_grad_run(
141145

142146
if __name__ == "__main__":
143147
# Full run
144-
test_gravity_fwr_run(
148+
test_gravity_rotated_grad_fwr_run(
145149
Path("./"),
146150
n_grid_points=10,
147151
refinement=(4, 8),

0 commit comments

Comments
 (0)