Skip to content

Commit

Permalink
add missing test
Browse files Browse the repository at this point in the history
  • Loading branch information
ntessore committed Nov 25, 2023
1 parent e5c47e4 commit d4aa0fa
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/angst/test/test_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,49 @@ def test_displace_abs(rng):
cos_a = np.cos(th) * np.cos(th_) + np.cos(delt) * np.sin(th) * np.sin(th_)

npt.assert_allclose(cos_a, np.cos(abs_alpha))


def test_displacement(rng):
from textwrap import dedent
import angst

# unit changes for displacements
deg5 = np.radians(5.0)
north = np.exp(1j * 0.0)
east = np.exp(1j * (np.pi / 2))
south = np.exp(1j * np.pi)
west = np.exp(1j * (3 * np.pi / 2))

# test data: coordinates and expected displacement
data = [
# equator
(0.0, 0.0, 0.0, 5.0, deg5 * north),
(0.0, 0.0, -5.0, 0.0, deg5 * east),
(0.0, 0.0, 0.0, -5.0, deg5 * south),
(0.0, 0.0, 5.0, 0.0, deg5 * west),
# pole
(0.0, 90.0, 180.0, 85.0, deg5 * north),
(0.0, 90.0, -90.0, 85.0, deg5 * east),
(0.0, 90.0, 0.0, 85.0, deg5 * south),
(0.0, 90.0, 90.0, 85.0, deg5 * west),
]

# test each displacement individually
for from_lon, from_lat, to_lon, to_lat, alpha in data:
alpha_ = angst.displacement(from_lon, from_lat, to_lon, to_lat)
assert np.allclose(alpha_, alpha), dedent(
f"""
displacement from ({from_lon}, {from_lat}) to ({to_lon}, {to_lat})
distance: expected {np.abs(alpha)}, got {np.abs(alpha_)}
direction: expected {np.angle(alpha)}, got {np.angle(alpha_)}
"""
)

# test on an array
alpha = angst.displacement(
rng.uniform(-180.0, 180.0, size=(20, 1)),
rng.uniform(-90.0, 90.0, size=(20, 1)),
rng.uniform(-180.0, 180.0, size=5),
rng.uniform(-90.0, 90.0, size=5),
)
assert alpha.shape == (20, 5)

0 comments on commit d4aa0fa

Please sign in to comment.