Skip to content

Commit 3ff5a6a

Browse files
committed
Add unitest for new utils
1 parent cb40625 commit 3ff5a6a

1 file changed

Lines changed: 51 additions & 2 deletions

File tree

tests/utils_surveys_test.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@
1212

1313
import numpy as np
1414
from geoh5py import Workspace
15-
from geoh5py.objects import Points
15+
from geoh5py.objects import CurrentElectrode, Points, PotentialElectrode
1616

17-
from simpeg_drivers.utils.surveys import counter_clockwise_sort, station_spacing
17+
from simpeg_drivers.options import DrapeModelOptions
18+
from simpeg_drivers.utils.surveys import (
19+
counter_clockwise_sort,
20+
create_mesh_by_line_id,
21+
get_parts_from_electrodes,
22+
station_spacing,
23+
)
1824

1925

2026
def create_test_survey(
@@ -83,3 +89,46 @@ def test_counterclockwise_sort():
8389
ccw_sorted = counter_clockwise_sort(segments, vertices)
8490

8591
np.testing.assert_equal(ccw_sorted[0, :], [0, 5])
92+
93+
94+
def get_dc_survey(workspace):
95+
"""
96+
Create a DC survey with 4 current electrodes and 10 potential electrodes.
97+
"""
98+
vertices = np.random.randn(4, 3)
99+
currents = CurrentElectrode.create(workspace, vertices=vertices, parts=[0, 0, 1, 1])
100+
currents.ab_cell_id = np.repeat([1, 2], 2)
101+
102+
rx_vertices = np.random.randn(12, 3)
103+
mn_pairs = np.c_[np.arange(11), np.arange(1, 12)] # Remove connection
104+
mn_pairs = np.delete(mn_pairs, 5, axis=0)
105+
potentials = PotentialElectrode.create(
106+
workspace,
107+
vertices=rx_vertices,
108+
cells=mn_pairs,
109+
)
110+
potentials.ab_cell_id = np.repeat([1, 2], 5)
111+
112+
potentials.current_electrodes = currents
113+
return potentials
114+
115+
116+
def test_parts_from_electrodes():
117+
workspace = Workspace()
118+
survey = get_dc_survey(workspace)
119+
120+
line_ids = get_parts_from_electrodes(survey)
121+
assert len(np.unique(line_ids)) == 2
122+
assert np.all(line_ids[:5] == 0)
123+
assert np.all(line_ids[5:] == 1)
124+
125+
126+
def test_drape_from_line_id(tmp_path):
127+
128+
with Workspace.create(tmp_path / f"{__name__}.geoh5") as ws:
129+
survey = get_dc_survey(ws)
130+
drape = create_mesh_by_line_id(
131+
ws, survey.ab_cell_id, DrapeModelOptions(), name="test_drape"
132+
)
133+
134+
assert drape.name == "test_drape"

0 commit comments

Comments
 (0)