Skip to content

Commit

Permalink
tests discovered mistake in calc_beam_angles. aft and fore beams swit…
Browse files Browse the repository at this point in the history
…ched
  • Loading branch information
callumrollo committed Apr 13, 2020
1 parent 446a5ed commit a373940
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/data/beam_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
def calc_beam_angles(pitch_angle, roll_angle):
# Returns angles of each beam from the vertical
z = np.empty(4)
z[0] = np.cos(np.deg2rad(47.5 + pitch_angle)) * np.cos(np.deg2rad(roll_angle))
z[0] = np.cos(np.deg2rad(47.5 - pitch_angle)) * np.cos(np.deg2rad(roll_angle))
z[1] = np.cos(np.deg2rad(25 - roll_angle)) * np.cos(np.deg2rad(pitch_angle))
z[2] = np.cos(np.deg2rad(47.5 - pitch_angle)) * np.cos(np.deg2rad(roll_angle))
z[2] = np.cos(np.deg2rad(47.5 + pitch_angle)) * np.cos(np.deg2rad(roll_angle))
z[3] = np.cos(np.deg2rad(25 + roll_angle)) * np.cos(np.deg2rad(pitch_angle))
angles = np.rad2deg(np.arccos(z))
return angles
Expand Down
26 changes: 21 additions & 5 deletions src/data/test_coord_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,44 @@
library_dir = Path("/media/callum/storage/Documents/adcp-glider/")
sys.path.append(str(library_dir))

from src.data.beam_mapping import rotate_pitch, rotate_roll, rotate_head
from src.data.beam_mapping import (
calc_beam_angles,
rotate_pitch,
rotate_roll,
rotate_head,
)

isclose_vec = np.vectorize(isclose)
vel_xyz = np.array([1.0, -1.0, 2.0])


# first test with no rotation, should be no change
def test_beam_angles():
"""First test with perfect angles"""
assert isclose_vec(calc_beam_angles(0, 0), [47.5, 25, 47.5, 25], abs_tol=1e-5).all()
"""Pitch up"""
assert isclose_vec(
calc_beam_angles(90, 0), [42.5, 90, 137.5, 90], abs_tol=1e-5
).all()
""" Roll to starboard"""
assert isclose_vec(calc_beam_angles(0, 90), [90, 65, 90, 115], abs_tol=1e-5).all()


def test_no_rotations():
"""First test with no rotation, should be no change"""
assert (rotate_pitch(0).dot(vel_xyz) == vel_xyz).all()
assert (rotate_roll(0).dot(vel_xyz) == vel_xyz).all()
assert (rotate_head(90).dot(vel_xyz) == vel_xyz).all()


# test with reversing rotations, should be no change
def test_reverse_rotations():
"""test with reversing rotations, should be no change"""
assert (rotate_pitch(-90).dot(rotate_pitch(90)).dot(vel_xyz) == vel_xyz).all()
assert (rotate_roll(-30).dot(rotate_roll(30)).dot(vel_xyz) == vel_xyz).all()
assert (rotate_head(180).dot(rotate_head(0)).dot(vel_xyz) == vel_xyz).all()


# test with single rotations. Using absolute tolerance of 1e-5
def test_single_rotations():
"""test with single rotations. Using absolute tolerance of 1e-5"""
assert (
isclose_vec(
rotate_pitch(90).dot(vel_xyz), np.array([-2.0, -1.0, 1.0]), abs_tol=1e-5
Expand All @@ -48,8 +64,8 @@ def test_single_rotations():
).all()


# test combined rotations
def test_combi_rotations():
"""test combined rotations"""
assert (
isclose_vec(
rotate_pitch(-90).dot(rotate_roll(90)).dot(vel_xyz),
Expand Down

0 comments on commit a373940

Please sign in to comment.