Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Test conversion of str direction to numeric and back."""
assert direction("N").value() == 0.0
assert direction("NNE").value() == 22.5
assert direction("NE").value() == 45.0
assert direction("ENE").value() == 67.5
assert direction("E").value() == 90.0
assert direction("ESE").value() == 112.5
assert direction("SE").value() == 135.0
assert direction("SSE").value() == 157.5
assert direction("S").value() == 180.0
assert direction("SSW").value() == 202.5
assert direction("SW").value() == 225.0
assert direction("WSW").value() == 247.5
assert direction("W").value() == 270.0
assert direction("WNW").value() == 292.5
assert direction("NW").value() == 315.0
assert direction("NNW").value() == 337.5
assert direction("0").compass() == "N"
assert direction("5").compass() == "N"
assert direction("355").compass() == "N"
assert direction("20").compass() == "NNE"
assert direction("60").compass() == "ENE"
assert direction("247.5").compass() == "WSW"
assert direction("ENE").value() == 67.5
assert direction("E").value() == 90.0
assert direction("ESE").value() == 112.5
assert direction("SE").value() == 135.0
assert direction("SSE").value() == 157.5
assert direction("S").value() == 180.0
assert direction("SSW").value() == 202.5
assert direction("SW").value() == 225.0
assert direction("WSW").value() == 247.5
assert direction("W").value() == 270.0
assert direction("WNW").value() == 292.5
assert direction("NW").value() == 315.0
assert direction("NNW").value() == 337.5
assert direction("0").compass() == "N"
assert direction("5").compass() == "N"
assert direction("355").compass() == "N"
assert direction("20").compass() == "NNE"
assert direction("60").compass() == "ENE"
assert direction("247.5").compass() == "WSW"
assert direction("ESE").value() == 112.5
assert direction("SE").value() == 135.0
assert direction("SSE").value() == 157.5
assert direction("S").value() == 180.0
assert direction("SSW").value() == 202.5
assert direction("SW").value() == 225.0
assert direction("WSW").value() == 247.5
assert direction("W").value() == 270.0
assert direction("WNW").value() == 292.5
assert direction("NW").value() == 315.0
assert direction("NNW").value() == 337.5
assert direction("0").compass() == "N"
assert direction("5").compass() == "N"
assert direction("355").compass() == "N"
assert direction("20").compass() == "NNE"
assert direction("60").compass() == "ENE"
assert direction("247.5").compass() == "WSW"
assert direction("SE").value() == 135.0
assert direction("SSE").value() == 157.5
assert direction("S").value() == 180.0
assert direction("SSW").value() == 202.5
assert direction("SW").value() == 225.0
assert direction("WSW").value() == 247.5
assert direction("W").value() == 270.0
assert direction("WNW").value() == 292.5
assert direction("NW").value() == 315.0
assert direction("NNW").value() == 337.5
assert direction("0").compass() == "N"
assert direction("5").compass() == "N"
assert direction("355").compass() == "N"
assert direction("20").compass() == "NNE"
assert direction("60").compass() == "ENE"
assert direction("247.5").compass() == "WSW"
def test_conversion():
"""Test conversion of str direction to numeric and back."""
assert direction("N").value() == 0.0
assert direction("NNE").value() == 22.5
assert direction("NE").value() == 45.0
assert direction("ENE").value() == 67.5
assert direction("E").value() == 90.0
assert direction("ESE").value() == 112.5
assert direction("SE").value() == 135.0
assert direction("SSE").value() == 157.5
assert direction("S").value() == 180.0
assert direction("SSW").value() == 202.5
assert direction("SW").value() == 225.0
assert direction("WSW").value() == 247.5
assert direction("W").value() == 270.0
assert direction("WNW").value() == 292.5
assert direction("NW").value() == 315.0
assert direction("NNW").value() == 337.5
assert direction("0").compass() == "N"
assert direction("5").compass() == "N"
assert direction("355").compass() == "N"
assert direction("20").compass() == "NNE"
assert direction("60").compass() == "ENE"
assert direction("247.5").compass() == "WSW"
def test_usage():
"""Test basic usage."""
assert direction("90").value() == 90.0
assert direction(90).value() == 90.0
assert direction(90.0).value() == 90.0
assert direction("90").string() == "90 degrees"
assert direction("E").compass() == "E"
def test_usage():
"""Test basic usage."""
assert direction("90").value() == 90.0
assert direction(90).value() == 90.0
assert direction(90.0).value() == 90.0
assert direction("90").string() == "90 degrees"
assert direction("E").compass() == "E"
def _handlePeakWindRemark(self, d):
"""
Parse a peak wind remark group.
"""
peak_dir = int(d["dir"])
peak_speed = int(d["speed"])
self.wind_speed_peak = speed(peak_speed, "KT")
self.wind_dir_peak = direction(peak_dir)
peak_min = int(d["min"])
if d["hour"]:
peak_hour = int(d["hour"])
else:
peak_hour = self._hour
self.peak_wind_time = datetime.datetime(
self._year, self._month, self._day, peak_hour, peak_min
)
if self.peak_wind_time > self.time:
if peak_hour > self._hour:
self.peak_wind_time -= datetime.timedelta(hours=24)
else:
self.peak_wind_time -= datetime.timedelta(hours=1)
self._remarks.append(
"peak wind %dkt from %d degrees at %d:%02d"
% (peak_speed, peak_dir, peak_hour, peak_min)
vis_units = "M"
vis_dist = "10000"
if d["dist"] and d["dist"] != "////":
vis_dist = d["dist"]
if d["dir"] and d["dir"] != "NDV":
vis_dir = d["dir"]
elif d["distu"]:
vis_dist = d["distu"]
if d["units"] and d["units"] != "U":
vis_units = d["units"]
if vis_dist == "9999":
vis_dist = "10000"
vis_less = ">"
if self.vis:
if vis_dir:
self.max_vis_dir = direction(vis_dir)
self.max_vis = distance(vis_dist, vis_units, vis_less)
else:
if vis_dir:
self.vis_dir = direction(vis_dir)
self.vis = distance(vis_dist, vis_units, vis_less)
def getdirection(self, position2):
"""
Calculate the initial direction to another location. (The direction
typically changes as you trace the great circle path to that location.)
See .
"""
lat1 = self.latitude
long1 = self.longitude
lat2 = position2.latitude
long2 = position2.longitude
s = -sin(long1 - long2) * cos(lat2)
c = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(long1 - long2)
d = atan2(s, c) * 180.0 / math.pi
if d < 0.0:
d += 360.0
return direction(d)