Skip to content

Commit 5d65459

Browse files
committed
update with geoapps-utils rotations
1 parent 5cbdb21 commit 5d65459

2 files changed

Lines changed: 10 additions & 19 deletions

File tree

simpeg_drivers/utils/regularization.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
import numpy as np
1212
import scipy.sparse as ssp
1313
from discretize import TreeMesh
14-
from geoapps_utils.utils.transformations import normal_to_direction_and_dip
14+
from geoapps_utils.utils.transformations import (
15+
cartesian_normal_to_direction_and_dip,
16+
x_rotation_matrix,
17+
z_rotation_matrix,
18+
)
1519
from geoh5py.groups import PropertyGroup
1620
from geoh5py.groups.property_group_type import GroupTypeEnum
1721
from simpeg.regularization import SparseSmoothness
@@ -194,18 +198,11 @@ def rotate_yz_3d(mesh: TreeMesh, theta: np.ndarray) -> ssp.csr_matrix:
194198
:param theta: Angle in radians for clockwise rotation about the
195199
x-axis (yz plane).
196200
"""
197-
198-
n_cells = len(theta)
199201
hy = mesh.h_gridded[:, 1]
200202
hz = mesh.h_gridded[:, 2]
201203
theta = -np.arctan2((np.sin(theta) / hz), (np.cos(theta) / hy))
202204

203-
rxa = mkvc(np.c_[np.ones(n_cells), np.cos(theta), np.cos(theta)].T)
204-
rxb = mkvc(np.c_[np.zeros(n_cells), np.sin(theta), np.zeros(n_cells)].T)
205-
rxc = mkvc(np.c_[np.zeros(n_cells), -np.sin(theta), np.zeros(n_cells)].T)
206-
Rx = ssp.diags([rxb[:-1], rxa, rxc[:-1]], [-1, 0, 1])
207-
208-
return Rx
205+
return x_rotation_matrix(theta)
209206

210207

211208
def rotate_xy_3d(mesh: TreeMesh, phi: np.ndarray) -> ssp.csr_matrix:
@@ -217,17 +214,11 @@ def rotate_xy_3d(mesh: TreeMesh, phi: np.ndarray) -> ssp.csr_matrix:
217214
:param phi: Angle in radians for clockwise rotation about the
218215
z-axis (xy plane).
219216
"""
220-
n_cells = len(phi)
221217
hx = mesh.h_gridded[:, 0]
222218
hy = mesh.h_gridded[:, 1]
223219
phi = -np.arctan2((np.sin(phi) / hy), (np.cos(phi) / hx))
224220

225-
rza = mkvc(np.c_[np.cos(phi), np.cos(phi), np.ones(n_cells)].T)
226-
rzb = mkvc(np.c_[np.sin(phi), np.zeros(n_cells), np.zeros(n_cells)].T)
227-
rzc = mkvc(np.c_[-np.sin(phi), np.zeros(n_cells), np.zeros(n_cells)].T)
228-
Rz = ssp.diags([rzb[:-1], rza, rzc[:-1]], [-1, 0, 1])
229-
230-
return Rz
221+
return z_rotation_matrix(phi)
231222

232223

233224
def get_cell_normals(n_cells: int, axis: str, outward: bool) -> np.ndarray:
@@ -408,7 +399,7 @@ def ensure_dip_direction_convention(
408399
"""
409400

410401
if group_type == GroupTypeEnum.VECTOR:
411-
orientations = np.rad2deg(normal_to_direction_and_dip(orientations))
402+
orientations = np.rad2deg(cartesian_normal_to_direction_and_dip(orientations))
412403

413404
if group_type in [GroupTypeEnum.STRIKEDIP]:
414405
orientations[:, 0] = 90.0 + orientations[:, 0]

tests/utils_regularization_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,5 @@ def test_ensure_dip_direction_convention():
132132
]
133133
)
134134
dir_dip = ensure_dip_direction_convention(orientations, group_type="3D vector")
135-
assert np.allclose(dir_dip[:, 0], [90, 0, 90, 180] * 2 + [74])
136-
assert np.allclose(dir_dip[:, 1], [45] * 4 + [30] * 4 + [-37])
135+
assert np.allclose(dir_dip[:, 0], [90, 0, 270, 180] * 2 + [254])
136+
assert np.allclose(dir_dip[:, 1], [45] * 4 + [30] * 4 + [37])

0 commit comments

Comments
 (0)