1616import pytest
1717from discretize import TreeMesh
1818from geoh5py import Workspace
19- from geoh5py .objects import Octree
19+ from geoh5py .objects import Grid2D , Octree
2020from grid_apps .utils import treemesh_2_octree
2121
2222from simpeg_drivers .components import InversionMesh
2323from simpeg_drivers .options import ActiveCellsOptions
2424from simpeg_drivers .potential_fields import MVIInversionOptions
25+ from simpeg_drivers .potential_fields .magnetic_vector .driver import MVIInversionDriver
2526from simpeg_drivers .utils .synthetics .driver import SyntheticsComponents
2627from simpeg_drivers .utils .synthetics .options import (
2728 MeshOptions ,
3233from tests .utils .targets import get_workspace
3334
3435
35- def get_mvi_params (tmp_path : Path ) -> MVIInversionOptions :
36+ def get_mvi_params (tmp_path : Path , updates = None ) -> MVIInversionOptions :
3637 opts = SyntheticsComponentsOptions (
3738 method = "magnetic_vector" ,
3839 survey = SurveyOptions (n_stations = 4 , n_lines = 4 ),
@@ -52,20 +53,22 @@ def get_mvi_params(tmp_path: Path) -> MVIInversionOptions:
5253 {"elevation" : {"values" : components .topography .vertices [:, 2 ]}}
5354 )
5455
55- params = MVIInversionOptions .build (
56- geoh5 = geoh5 ,
57- data_object = components .survey ,
58- tmi_channel = tmi_channel ,
59- tmi_uncertainty = 0.01 ,
60- active_cells = ActiveCellsOptions (
61- topography_object = components .topography , topography = elevation
62- ),
63- inducing_field_strength = 50000.0 ,
64- inducing_field_inclination = 60.0 ,
65- inducing_field_declination = 30.0 ,
66- mesh = mesh ,
67- starting_model = components .model ,
68- )
56+ kwargs = {
57+ "geoh5" : geoh5 ,
58+ "data_object" : components .survey ,
59+ "tmi_channel" : tmi_channel ,
60+ "tmi_uncertainty" : 0.01 ,
61+ "topography_object" : components .topography ,
62+ "topography" : elevation ,
63+ "inducing_field_strength" : 50000.0 ,
64+ "inducing_field_inclination" : 60.0 ,
65+ "inducing_field_declination" : 30.0 ,
66+ "mesh" : mesh ,
67+ "starting_model" : components .model ,
68+ }
69+ if updates is not None :
70+ kwargs .update (updates )
71+ params = MVIInversionOptions .build (** kwargs )
6972 return params
7073
7174
@@ -214,3 +217,27 @@ def test_raise_on_rotated_negative_cell_size(tmp_path):
214217 msg = "Cannot convert negative cell sizes for rotated mesh."
215218 with pytest .raises (ValueError , match = msg ):
216219 InversionMesh .ensure_cell_convention (mesh )
220+
221+
222+ def test_handle_grid2d (tmp_path ):
223+ with Workspace (tmp_path / "test.geoh5" ) as ws :
224+ topo = Grid2D .create (
225+ ws ,
226+ name = "topography" ,
227+ u_cell_size = 25.0 ,
228+ v_cell_size = 25.0 ,
229+ u_count = 16 ,
230+ v_count = 16 ,
231+ origin = (- 200.0 , - 200.0 , 0.0 ),
232+ )
233+ elev = topo .add_data (
234+ {
235+ "elevation" : {
236+ "values" : np .zeros (len (topo .centroids )),
237+ }
238+ }
239+ )
240+
241+ updates = {"mesh" : None , "topography_object" : topo , "topography" : elev }
242+ params = get_mvi_params (tmp_path , updates = updates )
243+ MVIInversionDriver (params ) # Doesn't crash
0 commit comments