|
13 | 13 | import numpy as np |
14 | 14 | from geoh5py.objects import Octree |
15 | 15 | from geoh5py.workspace import Workspace |
16 | | -from simpeg.directives import SavePropertyGroup |
| 16 | +from simpeg.directives import SaveModelGeoH5, SavePropertyGroup |
17 | 17 |
|
18 | 18 | from simpeg_drivers.electricals.direct_current.three_dimensions.driver import ( |
19 | 19 | DC3DInversionDriver, |
|
31 | 31 | GravityInversionOptions, |
32 | 32 | ) |
33 | 33 | from simpeg_drivers.potential_fields.gravity.driver import GravityInversionDriver |
| 34 | +from simpeg_drivers.potential_fields.magnetic_vector.driver import MVIInversionDriver |
| 35 | +from simpeg_drivers.potential_fields.magnetic_vector.options import MVIInversionOptions |
34 | 36 | from simpeg_drivers.utils.synthetics.driver import ( |
35 | 37 | SyntheticsComponents, |
36 | 38 | ) |
@@ -195,6 +197,89 @@ def test_joint_surveys_inv_run( |
195 | 197 | check_target(output, target_run) |
196 | 198 |
|
197 | 199 |
|
| 200 | +def test_joint_surveys_mvi_run(tmp_path, anomaly=0.05): |
| 201 | + drivers = [] |
| 202 | + |
| 203 | + with Workspace.create(tmp_path / f"{__name__}.geoh5") as geoh5: |
| 204 | + for ii in range(1, 3): |
| 205 | + opts = SyntheticsComponentsOptions( |
| 206 | + method="magnetic_vector", |
| 207 | + survey=SurveyOptions( |
| 208 | + n_stations=3**ii, |
| 209 | + n_lines=3**ii, |
| 210 | + drape=5.0, |
| 211 | + name=f"Survey Driver[{ii}]", |
| 212 | + ), |
| 213 | + mesh=MeshOptions(refinement=(2**ii, 2, 2), name=f"Mesh Driver[{ii}]"), |
| 214 | + model=ModelOptions(anomaly=anomaly), |
| 215 | + ) |
| 216 | + components = SyntheticsComponents(geoh5, options=opts) |
| 217 | + survey = components.survey |
| 218 | + obs, uncrt = survey.add_data( |
| 219 | + { |
| 220 | + "TMI": {"values": np.random.randn(survey.n_vertices)}, |
| 221 | + "Uncertainty": {"values": np.ones(survey.n_vertices) * 1e-3}, |
| 222 | + } |
| 223 | + ) |
| 224 | + |
| 225 | + # Add an inclination model on the first driver only to test handling of |
| 226 | + # models from the main driver |
| 227 | + if ii == 1: |
| 228 | + model = components.model.values |
| 229 | + model[model > 0] = 45.0 |
| 230 | + model[model <= 0] = 90.0 |
| 231 | + inc_mod = components.mesh.add_data( |
| 232 | + {"Inclination Model": {"values": model}} |
| 233 | + ) |
| 234 | + else: |
| 235 | + inc_mod = None |
| 236 | + |
| 237 | + params = MVIInversionOptions.build( |
| 238 | + geoh5=geoh5, |
| 239 | + mesh=components.mesh, |
| 240 | + topography_object=components.topography, |
| 241 | + tmi_channel=obs, |
| 242 | + tmi_uncertainty=uncrt, |
| 243 | + inducing_field_strength=45000, |
| 244 | + inducing_field_inclination=90.0, |
| 245 | + inducing_field_declination=0.0, |
| 246 | + data_object=survey, |
| 247 | + starting_model=components.model, |
| 248 | + starting_inclination=inc_mod, |
| 249 | + reference_model=0.0, |
| 250 | + ) |
| 251 | + drivers.append(MVIInversionDriver(params)) |
| 252 | + |
| 253 | + # Run the inverse |
| 254 | + joint_params = JointSurveysOptions.build( |
| 255 | + geoh5=geoh5, |
| 256 | + active_cells=ActiveCellsOptions(topography_object=components.topography), |
| 257 | + group_a=drivers[0].out_group, |
| 258 | + group_b=drivers[1].out_group, |
| 259 | + starting_model=0.01, |
| 260 | + # Default to Conductivity (S/m) |
| 261 | + ) |
| 262 | + |
| 263 | + driver = JointSurveyDriver(joint_params) |
| 264 | + assert np.isclose(driver.models.reference_model[0], 0) # Took it from driver_A |
| 265 | + assert driver.models.starting_model.shape == (driver.models.n_active * 3,) |
| 266 | + assert np.isclose( |
| 267 | + driver.models.starting_model.max(), 0.01 * np.cos(np.deg2rad(45.0)) |
| 268 | + ) |
| 269 | + |
| 270 | + # Test saving the starting models on each mesh (open file to validate) |
| 271 | + assert ( |
| 272 | + len( |
| 273 | + [ |
| 274 | + directive.write(0, driver.models.starting_model) |
| 275 | + for directive in driver.directives.directive_list |
| 276 | + if isinstance(directive, SaveModelGeoH5) |
| 277 | + ] |
| 278 | + ) |
| 279 | + == 3 |
| 280 | + ) |
| 281 | + |
| 282 | + |
198 | 283 | def test_joint_surveys_conductivity_run( |
199 | 284 | tmp_path, |
200 | 285 | ): |
|
0 commit comments