Skip to content

Commit 95fad9a

Browse files
committed
Fix auto-meshing. Augment unit test
1 parent 146ef54 commit 95fad9a

4 files changed

Lines changed: 45 additions & 21 deletions

File tree

simpeg_drivers/electricals/base_2d.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ def inversion_mesh(self) -> InversionMesh:
142142
if self.params.mesh is None:
143143
entity = create_mesh_by_line_id(
144144
self.workspace,
145-
self.params.line_ids,
145+
self.params.data_object,
146+
self.params.line_parts,
146147
self.params.drape_model,
147148
parent=self.out_group,
148149
)

simpeg_drivers/utils/surveys.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,17 @@ def compute_dc_projections(locations, cells, simulation):
177177

178178
def create_mesh_by_line_id(
179179
workspace: Workspace,
180-
line_ids: IntegerData,
180+
survey: PotentialElectrode,
181+
line_ids: np.ndarray,
181182
drape_options: DrapeModelOptions,
182183
**object_kwargs,
183184
) -> DrapeModel:
184185
"""
185186
Create a drape mesh for the dc resistivity survey lines.
186187
187188
:param workspace: Workspace to create the drape mesh in.
188-
:param line_ids: IntegerData object containing the line IDs for each vertex.
189+
:param survey: PotentialElectrode survey object.
190+
:param line_ids: Array containing the line IDs for each vertex.
189191
:param drape_options: DrapeModelOptions containing the parameters for the drape mesh
190192
:param object_kwargs: Additional keyword arguments to pass to the DrapeModelMerger.create_object method.
191193
@@ -194,10 +196,10 @@ def create_mesh_by_line_id(
194196
drape_models = []
195197
temp_work = Workspace()
196198

197-
relief = get_max_line_relief(line_ids, drape_options.v_cell_size)
199+
relief = get_max_line_relief(survey, line_ids, drape_options.v_cell_size)
198200

199-
for line_id in np.unique(line_ids.values):
200-
poles = get_poles_by_line_id(line_ids, line_id)
201+
for line_id in np.unique(line_ids):
202+
poles = get_poles_by_line_id(survey, line_ids, line_id)
201203
poles = np.unique(poles, axis=0)
202204
poles = normalize_vertically(poles, relief)
203205

@@ -220,34 +222,47 @@ def create_mesh_by_line_id(
220222
return entity
221223

222224

223-
def get_max_line_relief(line_ids: IntegerData, z_cell_size: float) -> float:
225+
def get_max_line_relief(
226+
survey: PotentialElectrode, line_ids: np.ndarray, z_cell_size: float
227+
) -> float:
224228
"""
225229
Get the maximum relief across all survey lines, rounded to the nearest cell thickness.
226230
227-
:param line_ids: IntegerData object containing the line IDs for each vertex.
231+
:param survey: PotentialElectrode survey object.
232+
:param line_ids: Array containing the line IDs for each vertex.
228233
:param z_cell_size: Cell size in the vertical direction for the drape mesh.
229234
"""
230235
max_relief = 0
231-
for line_id in np.unique(line_ids.values):
232-
poles = get_poles_by_line_id(line_ids, line_id)
236+
for line_id in np.unique(line_ids):
237+
poles = get_poles_by_line_id(survey, line_ids, line_id)
233238
max_relief = np.maximum(poles[:, 2].max() - poles[:, 2].min(), max_relief)
234239

235240
return (max_relief // z_cell_size + 2) * z_cell_size
236241

237242

238-
def get_poles_by_line_id(line_ids: IntegerData, uid: int) -> np.ndarray:
239-
"""Get the vertices associated with a given line ID."""
240-
mn_mask = line_ids.values == uid
243+
def get_poles_by_line_id(
244+
survey: PotentialElectrode, line_ids: np.ndarray, uid: int
245+
) -> np.ndarray:
246+
"""
247+
Get the vertices associated with a given line ID.
248+
249+
:param survey: PotentialElectrode survey object.
250+
:param line_ids: Array containing the line IDs for each vertex.
251+
:param uid: Unique ID for the survey line.
252+
253+
:return: Array containing the receiver and transmitter pole locations associated with a given line ID.
254+
"""
255+
mn_mask = line_ids == uid
241256

242-
unique_tx = np.unique(line_ids.parent.ab_cell_id.values[mn_mask])
257+
unique_tx = np.unique(survey.ab_cell_id.values[mn_mask])
243258

244-
ab_mask = np.isin(line_ids.parent.complement.ab_cell_id.values, unique_tx)
259+
ab_mask = np.isin(survey.complement.ab_cell_id.values, unique_tx)
245260

246261
return np.vstack(
247262
[
248-
line_ids.parent.vertices[line_ids.parent.cells[mn_mask].flatten()],
249-
line_ids.parent.current_electrodes.vertices[
250-
line_ids.parent.current_electrodes.cells[ab_mask].flatten()
263+
survey.vertices[survey.cells[mn_mask].flatten()],
264+
survey.current_electrodes.vertices[
265+
survey.current_electrodes.cells[ab_mask].flatten()
251266
],
252267
]
253268
)

simpeg_drivers/utils/synthetics/meshes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def get_mesh(
3333

3434
return create_mesh_by_line_id(
3535
survey.workspace,
36-
line_data,
36+
survey,
37+
line_data.values,
3738
options,
3839
name="mesh",
3940
)

tests/run_tests/driver_ip_2d_test.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,18 @@ def test_ip_2d_run(
107107
}
108108
}
109109
)
110-
# Run the inverse
110+
# Run the inverse without a mesh
111111
params = IP2DInversionOptions.build(
112112
geoh5=geoh5,
113-
mesh=components.mesh,
114113
topography_object=components.topography,
114+
drape_model=DrapeModelOptions(
115+
u_cell_size=5.0,
116+
v_cell_size=5.0,
117+
depth_core=50.0,
118+
expansion_factor=1.1,
119+
vertical_padding=200.0,
120+
horizontal_padding=200.0,
121+
),
115122
data_object=chargeability.parent,
116123
chargeability_channel=chargeability,
117124
chargeability_uncertainty=uncertainties,

0 commit comments

Comments
 (0)