1414
1515import numpy as np
1616
17- from simpeg_drivers .components import InversionTopography
17+ from simpeg_drivers .components import InversionData , InversionMesh , InversionTopography
1818from simpeg_drivers .options import ActiveCellsOptions
1919from simpeg_drivers .potential_fields import MVIInversionOptions
2020from simpeg_drivers .utils .testing import Geoh5Tester , setup_inversion_workspace
2121
2222
2323def test_get_locations (tmp_path : Path ):
24- geoh5 , entity , model , survey , topography = setup_inversion_workspace (
24+ geoh5 , mesh , model , survey , topography = setup_inversion_workspace (
2525 tmp_path ,
2626 background = 0.0 ,
2727 anomaly = 0.05 ,
@@ -31,7 +31,6 @@ def test_get_locations(tmp_path: Path):
3131 inversion_type = "magnetic_vector" ,
3232 )
3333 with geoh5 .open ():
34- mesh = model .parent
3534 tmi_channel , gyz_channel = survey .add_data (
3635 {
3736 "tmi" : {"values" : np .random .rand (survey .n_vertices )},
@@ -51,6 +50,7 @@ def test_get_locations(tmp_path: Path):
5150 ),
5251 starting_model = 1.0 ,
5352 )
53+
5454 geoh5 = params .geoh5
5555 with geoh5 .open ():
5656 topo = InversionTopography (geoh5 , params )
@@ -60,6 +60,25 @@ def test_get_locations(tmp_path: Path):
6060 params .active_cells .topography .values ,
6161 )
6262
63+ # Check that boundary cells are handled properly
64+ # Shift one of the survey vertices to the corner
65+ survey .vertices [0 , :] = mesh .centroids [0 , :]
66+ geoh5 .update_attribute (survey , "vertices" )
67+ inversion_mesh = InversionMesh (geoh5 , params )
68+ inversion_data = InversionData (geoh5 , params )
69+ params .inversion_type = "magnetotellurics"
70+ active_cells = topo .active_cells (inversion_mesh , inversion_data )
71+
72+ mesh .add_data (
73+ {
74+ "active_cells" : {
75+ "values" : active_cells ,
76+ }
77+ }
78+ )
79+ assert not active_cells [- 1 ]
80+
81+ # Test flat topo
6382 params .active_cells .topography = 199.0
6483 locs = topo .get_locations (params .active_cells .topography_object )
6584 np .testing .assert_allclose (locs [:, 2 ], np .ones_like (locs [:, 2 ]) * 199.0 )
0 commit comments