Skip to content

Commit

Permalink
Consistently use 'degree' singular for units
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcvey3 committed Sep 19, 2024
1 parent 5d7d520 commit 33635f8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions mhkit/dolfyn/io/rdi_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@
[],
"data_vars",
"float32",
"degrees_north",
"degree_north",
"Latitude",
"latitude",
),
"longitude_gps": (
[],
"data_vars",
"float32",
"degrees_east",
"degree_east",
"Longitude",
"longitude",
),
Expand Down
18 changes: 13 additions & 5 deletions mhkit/dolfyn/rotate/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def _beam2inst(dat, reverse=False, force=False):
return dat


def euler2orient(heading, pitch, roll, units="degrees"):
def euler2orient(heading, pitch, roll, units="degree"):
"""
Calculate the orientation matrix from DOLfYN-defined euler angles.
Expand Down Expand Up @@ -210,14 +210,14 @@ def euler2orient(heading, pitch, roll, units="degrees"):
instrument's x-axis
"""

if units.lower() == "degrees":
if "deg" in units.lower():
pitch = np.deg2rad(pitch)
roll = np.deg2rad(roll)
heading = np.deg2rad(heading)
elif units.lower() == "radians":
elif "rad" in units.lower():
pass
else:
raise Exception("Invalid units")
raise ValueError("Invalid units")

# Converts the DOLfYN-defined heading to one that follows the right-hand-rule
# reports heading as rotation of the y-axis positive counterclockwise from North
Expand Down Expand Up @@ -361,7 +361,7 @@ def quaternion2orient(quaternions):
return omat.assign_coords({"earth": earth, "inst": inst, "time": quaternions.time})


def calc_tilt(pitch, roll):
def calc_tilt(pitch, roll, units="degree"):
"""
Calculate "tilt", the vertical inclination, from pitch and roll.
Expand All @@ -378,6 +378,14 @@ def calc_tilt(pitch, roll):
Vertical inclination of the instrument in degrees
"""

if "deg" in units.lower():
pitch = np.deg2rad(pitch)
roll = np.deg2rad(roll)
elif "rad" in units.lower():
pass
else:
raise ValueError("Invalid units")

if "xarray" in type(pitch).__module__:
pitch = pitch.values
if "xarray" in type(roll).__module__:
Expand Down
8 changes: 6 additions & 2 deletions mhkit/dolfyn/rotate/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,22 @@ def _calc_omat(time, hh, pp, rr, orientation_down=None):
return _euler2orient(time, hh, pp, rr)


def _euler2orient(time, heading, pitch, roll, units="degrees"):
def _euler2orient(time, heading, pitch, roll, units="degree"):
# For Nortek data only.
# The heading, pitch, roll used here are from the Nortek binary files.

# Heading input is clockwise from North
# Returns a rotation matrix that rotates earth (ENU) -> inst.
# This is based on the Nortek `Transforms.m` file, available in
# the refs folder.
if units.lower() == "degrees":
if "deg" in units.lower():
pitch = np.deg2rad(pitch)
roll = np.deg2rad(roll)
heading = np.deg2rad(heading)
elif "rad" in units.lower():
pass
else:
raise ValueError("Invalid units")

# The definition of heading below is consistent with the right-hand-rule;
# heading is the angle positive counterclockwise from North of the y-axis.
Expand Down
4 changes: 2 additions & 2 deletions mhkit/dolfyn/velocity.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ def convert_to_CW(angle):
dims=self.U.dims,
coords=self.U.coords,
attrs={
"units": "degrees_CW_from_" + str(rel),
"long_name": "Water Direction",
"units": "degree",
"long_name": "Water Direction, CW from " + str(rel),
"standard_name": "sea_water_to_direction",
},
)
Expand Down

0 comments on commit 33635f8

Please sign in to comment.