Skip to content

Commit 7a36da5

Browse files
committed
fix tests
1 parent 843a029 commit 7a36da5

15 files changed

Lines changed: 151 additions & 87 deletions

simpeg_drivers/plate_simulation/driver.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,13 @@ def plates(self) -> list[Plate]:
141141
depth_offset=-1 * offset,
142142
)
143143
plate = Plate(
144-
self.params.model.plate,
145-
center,
144+
self.params.model.plate.model_copy(
145+
update={
146+
"easting": center[0],
147+
"northing": center[1],
148+
"elevation": center[2],
149+
}
150+
),
146151
)
147152
self._plates = self.replicate(
148153
plate,
@@ -272,10 +277,24 @@ def replicate(
272277

273278
plates = []
274279
for i in range(number):
275-
center = np.r_[plate.center] + azimuth_to_unit_vector(azimuth) * offsets[i]
276-
new = Plate(plate.params.model_copy(), center)
277-
new.params.name = f"{plate.params.name} offset {i + 1}"
278-
plates.append(new)
280+
center = (
281+
np.r_[plate.params.geometry.origin]
282+
+ azimuth_to_unit_vector(azimuth) * offsets[i]
283+
)
284+
new_geometry = plate.params.geometry.model_copy(
285+
update={
286+
"easting": center[0],
287+
"northing": center[1],
288+
"elevation": center[2],
289+
}
290+
)
291+
new_plate = Plate(
292+
plate.params.model_copy(update={"geometry": new_geometry})
293+
)
294+
295+
new_plate.params.name = f"{plate.params.name} offset {i + 1}"
296+
plates.append(new_plate)
297+
279298
return plates
280299

281300

simpeg_drivers/plate_simulation/models/parametric.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,9 @@ class Plate(Parametric):
6868
def __init__(
6969
self,
7070
params: PlateOptions,
71-
center: tuple[float, float, float] = (
72-
0.0,
73-
0.0,
74-
0.0,
75-
),
7671
workspace: Workspace | None = None,
7772
):
7873
self.params = params
79-
self.center = center
8074
self._workspace = workspace
8175
super().__init__(self._create_surface())
8276

@@ -128,12 +122,16 @@ def triangles(self) -> np.ndarray:
128122
def vertices(self) -> np.ndarray:
129123
"""Vertices for triangulation of a rectangular prism in 3D space."""
130124

131-
u_1 = self.center[0] - (self.params.geometry.strike_length / 2.0)
132-
u_2 = self.center[0] + (self.params.geometry.strike_length / 2.0)
133-
v_1 = self.center[1] - (self.params.geometry.dip_length / 2.0)
134-
v_2 = self.center[1] + (self.params.geometry.dip_length / 2.0)
135-
w_1 = self.center[2] - (self.params.geometry.width / 2.0)
136-
w_2 = self.center[2] + (self.params.geometry.width / 2.0)
125+
u_1 = self.params.geometry.origin[0] - (
126+
self.params.geometry.strike_length / 2.0
127+
)
128+
u_2 = self.params.geometry.origin[0] + (
129+
self.params.geometry.strike_length / 2.0
130+
)
131+
v_1 = self.params.geometry.origin[1] - (self.params.geometry.dip_length / 2.0)
132+
v_2 = self.params.geometry.origin[1] + (self.params.geometry.dip_length / 2.0)
133+
w_1 = self.params.geometry.origin[2] - (self.params.geometry.width / 2.0)
134+
w_2 = self.params.geometry.origin[2] + (self.params.geometry.width / 2.0)
137135

138136
vertices = np.array(
139137
[
@@ -161,7 +159,7 @@ def _rotate(self, vertices: np.ndarray) -> np.ndarray:
161159
"""Rotate vertices and adjust for reference point."""
162160
theta = -1 * self.params.geometry.direction
163161
phi = -1 * self.params.geometry.dip
164-
rotated_vertices = rotate_xyz(vertices, self.center, theta, phi)
162+
rotated_vertices = rotate_xyz(vertices, self.params.geometry.origin, theta, phi)
165163

166164
return rotated_vertices
167165

simpeg_drivers/utils/synthetics/meshes.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,20 @@ def get_octree_mesh(
122122
)
123123

124124
if plate is not None:
125-
# TODO Consolidate PlateOptions and PlateModel into a single class to avoid this redundancy
126125
plate_options = PlateOptions(
127-
plate=1.0, # thickness
128-
width=plate.width,
129-
strike_length=plate.strike_length,
130-
dip_length=plate.dip_length,
131-
dip=plate.dip,
132-
dip_direction=plate.direction,
133-
elevation=0,
126+
plate_property=1.0, # thickness
127+
geometry=PlateModel(
128+
strike_length=plate.strike_length,
129+
dip_length=plate.dip_length,
130+
width=plate.width,
131+
direction=plate.direction,
132+
dip=plate.dip,
133+
easting=plate.origin[0],
134+
northing=plate.origin[1],
135+
elevation=0.0,
136+
),
134137
)
135-
center = list(plate.origin)
136-
137-
plate = Plate(plate_options, center=center, workspace=survey.workspace)
138+
plate = Plate(plate_options, workspace=survey.workspace)
138139
mesh = OctreeDriver.refine_tree_from_triangulation(
139140
mesh, plate.surface, levels=(4,), finalize=False
140141
)

tests/plate_simulation/models/events_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def test_anomaly(tmp_path):
9090
name="my plate",
9191
plate_property=10.0,
9292
geometry=PlateModel(
93-
easting=0.0,
94-
northing=0.0,
93+
easting=5.0,
94+
northing=5.0,
9595
elevation=-1.5,
9696
width=10.0,
9797
strike_length=10.0,
@@ -100,7 +100,7 @@ def test_anomaly(tmp_path):
100100
dip=90,
101101
),
102102
)
103-
plate = Plate(params, center=(5.0, 5.0, -1.5))
103+
plate = Plate(params)
104104

105105
anomaly = Anomaly(body=plate, value=10.0)
106106
event_map = {1: ("Background", 1.0)}

tests/plate_simulation/models/params_test.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1010

1111
import numpy as np
12+
from geoapps_utils.modelling.plates import PlateModel
1213
from geoh5py import Workspace
1314
from geoh5py.objects import Points, Surface
1415

@@ -19,19 +20,21 @@ def test_plate_params(tmp_path):
1920
workspace = Workspace(tmp_path / "test.geoh5")
2021
params = PlateOptions(
2122
name="my plate",
22-
plate=1.0,
23-
width=20.0,
24-
strike_length=1500.0,
25-
dip_length=400.0,
26-
dip=90.0,
27-
dip_direction=0.0,
23+
plate_property=1.0,
24+
geometry=PlateModel(
25+
strike_length=1500.0,
26+
dip_length=400.0,
27+
width=20.0,
28+
easting=10.0,
29+
northing=10.0,
30+
elevation=-100.0,
31+
direction=0.0,
32+
dip=90.0,
33+
),
2834
reference="center",
2935
number=1,
3036
spacing=10.0,
3137
relative_locations=True,
32-
easting=10.0,
33-
northing=10.0,
34-
elevation=-100.0,
3538
reference_surface="topography",
3639
reference_type="mean",
3740
)
@@ -60,19 +63,21 @@ def test_plate_params(tmp_path):
6063
def test_plate_params_empty_reference():
6164
params = PlateOptions(
6265
name="my plate",
63-
plate=1.0,
64-
width=20.0,
65-
strike_length=1500.0,
66-
dip_length=400.0,
67-
dip=90.0,
68-
dip_direction=0.0,
66+
plate_property=1.0,
67+
geometry=PlateModel(
68+
strike_length=1500.0,
69+
dip_length=400.0,
70+
width=20.0,
71+
easting=10.0,
72+
northing=10.0,
73+
elevation=-100.0,
74+
direction=0.0,
75+
dip=90.0,
76+
),
6977
reference="center",
7078
number=1,
7179
spacing=10.0,
7280
relative_locations=True,
73-
easting=10.0,
74-
northing=10.0,
75-
elevation=-100.0,
7681
reference_surface=None,
7782
reference_type=None,
7883
)

tests/plate_simulation/models/plates_test.py

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1010

1111
import numpy as np
12+
from geoapps_utils.modelling.plates import PlateModel
1213
from geoapps_utils.utils.transformations import rotate_xyz
1314
from geoh5py import Workspace
1415

@@ -28,13 +29,17 @@ def are_collocated(pts1, pts2):
2829
def vertical_east_striking_plate():
2930
params = PlateOptions(
3031
name="my plate",
31-
plate=1.0,
32-
elevation=0.0,
33-
width=10.0,
34-
strike_length=1000.0,
35-
dip_length=500.0,
36-
dip=90.0,
37-
dip_direction=0.0,
32+
plate_property=1.0,
33+
geometry=PlateModel(
34+
strike_length=1000.0,
35+
dip_length=500.0,
36+
width=10.0,
37+
direction=0.0,
38+
dip=90.0,
39+
easting=0.0,
40+
northing=0.0,
41+
elevation=0.0,
42+
),
3843
)
3944
plate = Plate(params)
4045

@@ -75,13 +80,17 @@ def test_dipping_plates_all_quadrants():
7580
for dip in [20.0, 70.0]:
7681
params = PlateOptions(
7782
name=f"plate dipping {dip} at {dip_direction}",
78-
plate=1.0,
79-
elevation=0.0,
80-
width=10.0,
81-
strike_length=1000.0,
82-
dip_length=500.0,
83-
dip=dip,
84-
dip_direction=dip_direction,
83+
plate_property=1.0,
84+
geometry=PlateModel(
85+
strike_length=1000.0,
86+
dip_length=500.0,
87+
width=10.0,
88+
direction=dip_direction,
89+
dip=dip,
90+
easting=0.0,
91+
northing=0.0,
92+
elevation=0.0,
93+
),
8594
reference="center",
8695
)
8796

@@ -96,13 +105,19 @@ def test_replicate_even(tmp_path):
96105
workspace = Workspace.create(tmp_path / f"{__name__}.geoh5")
97106
options = PlateOptions(
98107
name="test",
99-
plate=1.0,
100-
width=1.0,
101-
strike_length=1.0,
102-
dip_length=1.0,
103-
elevation=1.0,
108+
plate_property=1.0,
109+
geometry=PlateModel(
110+
strike_length=1.0,
111+
dip_length=1.0,
112+
width=1.0,
113+
direction=0.0,
114+
dip=0.0,
115+
easting=0.0,
116+
northing=0.0,
117+
elevation=0.0,
118+
),
104119
)
105-
plate = Plate(options, (0, 0, 0), workspace=workspace)
120+
plate = Plate(options, workspace=workspace)
106121
plates = PlateSimulationDriver.replicate(plate, 2, 10.0, 90.0)
107122
assert plates[0].surface.vertices is not None
108123
assert plates[1].surface.vertices is not None
@@ -120,13 +135,19 @@ def test_replicate_odd(tmp_path):
120135
workspace = Workspace.create(tmp_path / f"{__name__}.geoh5")
121136
options = PlateOptions(
122137
name="test",
123-
plate=1.0,
124-
width=1.0,
125-
strike_length=1.0,
126-
dip_length=1.0,
127-
elevation=1.0,
138+
plate_property=1.0,
139+
geometry=PlateModel(
140+
strike_length=1.0,
141+
dip_length=1.0,
142+
width=1.0,
143+
direction=0.0,
144+
dip=0.0,
145+
easting=0.0,
146+
northing=0.0,
147+
elevation=0.0,
148+
),
128149
)
129-
plate = Plate(options, (0, 0, 0), workspace=workspace)
150+
plate = Plate(options, workspace=workspace)
130151
plates = PlateSimulationDriver.replicate(plate, 3, 5.0, 0.0)
131152
assert plates[0].surface.vertices is not None
132153
assert plates[1].surface.vertices is not None

tests/run_tests/driver_airborne_fem_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ def test_fem_fwr_run(
9191
strike_length=40.0,
9292
dip_length=40.0,
9393
width=40.0,
94-
origin=(0.0, 0.0, -50.0),
94+
easting=0.0,
95+
northing=0.0,
96+
elevation=-50.0,
9597
),
9698
),
9799
)

tests/run_tests/driver_app_con_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ def test_app_con_fwr_run(
6666
dip_length=60.0,
6767
width=60.0,
6868
dip=90,
69-
origin=(0.0, 0.0, -90.0),
69+
easting=0.0,
70+
northing=0.0,
71+
elevation=-90.0,
7072
),
7173
),
7274
)

tests/run_tests/driver_dc_2d_rotated_gradients_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ def test_dc_rotated_2d_fwr_run(tmp_path: Path, n_electrodes=10, n_lines=3):
6363
strike_length=1000.0,
6464
dip_length=50.0,
6565
width=20.0,
66-
origin=(0.0, 0.0, 0.0),
66+
easting=0.0,
67+
northing=0.0,
68+
elevation=0.0,
6769
direction=90,
6870
dip=45,
6971
),

tests/run_tests/driver_dc_2d_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ def test_dc_2d_fwr_run(
6868
strike_length=1000.0,
6969
dip_length=20.0,
7070
width=20.0,
71-
origin=(0.0, 0.0, 0.0),
71+
easting=0.0,
72+
northing=0.0,
73+
elevation=0.0,
7274
direction=90,
7375
dip=90,
7476
),

0 commit comments

Comments
 (0)