1313
1414from pathlib import Path
1515
16+ import numpy as np
17+ from geoapps_utils .modelling .plates import PlateModel
1618from geoh5py .workspace import Workspace
1719
1820from simpeg_drivers .electricals .direct_current .two_dimensions .driver import (
4143# To test the full run and validate the inversion.
4244# Move this file out of the test directory and run.
4345
44- target_run = {"data_norm" : 1.101767837151429 , "phi_d" : 2210 , "phi_m" : 21.4 }
46+ target_run = {"data_norm" : 11.14351536256954 , "phi_d" : 6360 , "phi_m" : 245 }
4547
4648
47- def test_dc_p3d_fwr_run (
49+ def test_dc_2d_fwr_run (
4850 tmp_path : Path ,
4951 n_electrodes = 10 ,
5052 n_lines = 3 ,
@@ -58,9 +60,21 @@ def test_dc_p3d_fwr_run(
5860 v_cell_size = 5.0 ,
5961 depth_core = 50.0 ,
6062 expansion_factor = 1.1 ,
61- vertical_padding = 100.0 ,
63+ vertical_padding = 200.0 ,
64+ horizontal_padding = 200.0 ,
65+ ),
66+ model = ModelOptions (
67+ background = 0.001 ,
68+ anomaly = 1.0 ,
69+ plate = PlateModel (
70+ strike_length = 1000.0 ,
71+ dip_length = 20.0 ,
72+ width = 20.0 ,
73+ origin = (0.0 , 0.0 , 0.0 ),
74+ direction = 90 ,
75+ dip = 90 ,
76+ ),
6277 ),
63- model = ModelOptions (background = 0.01 , anomaly = 10.0 ),
6478 )
6579 with get_workspace (tmp_path / "inversion_test.ui.geoh5" ) as geoh5 :
6680 components = SyntheticsComponents (geoh5 = geoh5 , options = opts )
@@ -76,34 +90,40 @@ def test_dc_p3d_fwr_run(
7690 fwr_driver .run ()
7791
7892
79- def test_dc_p3d_run (
93+ def test_dc_2d_run (
8094 tmp_path : Path ,
8195 max_iterations = 1 ,
8296 pytest = True ,
8397):
8498 workpath = tmp_path / "inversion_test.ui.geoh5"
8599 if pytest :
86- workpath = tmp_path .parent / "test_dc_p3d_fwr_run0 " / "inversion_test.ui.geoh5"
100+ workpath = tmp_path .parent / "test_dc_2d_fwr_run0 " / "inversion_test.ui.geoh5"
87101
88102 with Workspace (workpath ) as geoh5 :
89103 components = SyntheticsComponents (geoh5 )
90104 fwr_group = geoh5 .get_entity ("Direct Current 2D Forward" )[0 ]
91105 survey = fwr_group .get_entity ("survey" )[0 ]
92106 potential = survey .get_data ("Iteration_0_potential" )[0 ]
93-
107+ uncertainties = survey .add_data (
108+ {
109+ "Uncertainties" : {
110+ "values" : np .abs (potential .values ) * 0.05 + 1e-4 ,
111+ }
112+ }
113+ )
94114 # Run the inverse
95115 params = DC2DInversionOptions .build (
96116 geoh5 = geoh5 ,
97117 mesh = components .mesh ,
98118 topography_object = components .topography ,
99119 data_object = potential .parent ,
100120 potential_channel = potential ,
101- potential_uncertainty = 1e-3 ,
121+ potential_uncertainty = uncertainties ,
102122 line_selection = LineSelectionOptions (
103123 line_object = potential .parent .get_entity ("Line IDs" )[0 ]
104124 ),
105- starting_model = 1e-2 ,
106- reference_model = 1e-2 ,
125+ starting_model = 1e-3 ,
126+ reference_model = 1e-3 ,
107127 s_norm = 0.0 ,
108128 x_norm = 1.0 ,
109129 z_norm = 1.0 ,
@@ -134,14 +154,20 @@ def test_dc_single_run(
134154):
135155 workpath = tmp_path / "inversion_test.ui.geoh5"
136156 if pytest :
137- workpath = tmp_path .parent / "test_dc_p3d_fwr_run0 " / "inversion_test.ui.geoh5"
157+ workpath = tmp_path .parent / "test_dc_2d_fwr_run0 " / "inversion_test.ui.geoh5"
138158
139159 with Workspace (workpath ) as geoh5 :
140160 components = SyntheticsComponents (geoh5 )
141161 fwr_group = geoh5 .get_entity ("Direct Current 2D Forward" )[0 ]
142162 survey = fwr_group .get_entity ("survey" )[0 ]
143163 potential = survey .get_data ("Iteration_0_potential" )[0 ]
144-
164+ uncertainties = survey .add_data (
165+ {
166+ "Uncertainties" : {
167+ "values" : np .abs (potential .values ) * 0.05 + 1e-4 ,
168+ }
169+ }
170+ )
145171 # Run the inverse
146172 params = DC2DInversionOptions .build (
147173 geoh5 = geoh5 ,
@@ -150,12 +176,12 @@ def test_dc_single_run(
150176 topography_object = components .topography ,
151177 data_object = potential .parent ,
152178 potential_channel = potential ,
153- potential_uncertainty = 1e-3 ,
179+ potential_uncertainty = uncertainties ,
154180 line_selection = LineSelectionOptions (
155181 line_object = potential .parent .get_entity ("Line IDs" )[0 ], line_id = 2
156182 ),
157- starting_model = 1e-2 ,
158- reference_model = 1e-2 ,
183+ starting_model = 1e-3 ,
184+ reference_model = 1e-3 ,
159185 s_norm = 0.0 ,
160186 x_norm = 1.0 ,
161187 z_norm = 1.0 ,
@@ -168,25 +194,27 @@ def test_dc_single_run(
168194 )
169195 params .write_ui_json (path = tmp_path / "Inv_run.ui.json" )
170196
171- driver = DC2DInversionDriver .start (str (tmp_path / "Inv_run.ui.json" ))
197+ DC2DInversionDriver .start (str (tmp_path / "Inv_run.ui.json" ))
172198
173- output = get_inversion_output (
174- driver .params .geoh5 .h5file , driver .params .out_group .uid
175- )
176- if geoh5 .open ():
177- output ["data" ] = potential .values
178- if pytest :
179- check_target (output , target_run )
199+ with Workspace (workpath ) as geoh5 :
200+ inv_group = geoh5 .get_entity ("Direct Current Single 2D Inversion" )[0 ]
201+ mesh = inv_group .get_entity ("mesh" )[0 ]
202+ model = mesh .get_entity ("Iteration_1_model" )[0 ]
203+
204+ # Check that model values for lines 1 and 3 are close to the starting model (1e-3) and that line 2 has been updated.
205+ np .testing .assert_almost_equal (np .nanmin (model .values [:2369 ]), 1e-3 , decimal = 3 )
206+ np .testing .assert_almost_equal (np .nanmin (model .values [- 2368 :]), 1e-3 , decimal = 3 )
207+ assert np .nanmax (model .values [2368 :- 2368 ]) > 1e-3
180208
181209
182210if __name__ == "__main__" :
183211 # Full run
184- test_dc_p3d_fwr_run (
212+ test_dc_2d_fwr_run (
185213 Path ("./" ),
186214 n_electrodes = 20 ,
187215 n_lines = 3 ,
188216 )
189- test_dc_p3d_run (
217+ test_dc_2d_run (
190218 Path ("./" ),
191219 max_iterations = 20 ,
192220 pytest = False ,
0 commit comments