def _handleVisibility(self, d): """ Parse the minimum and maximum visibility groups. The following attributes are set: vis [distance] vis_dir [direction] max_vis [distance] max_vis_dir [direction] """ vis = d["vis"] vis_less = None vis_dir = None 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 _handleWind( self, d ): """ Parse the wind and variable-wind groups. The following attributes are set: wind_dir [direction] wind_speed [speed] wind_gust [speed] wind_dir_from [int] wind_dir_to [int] """ wind_dir = d['dir'].replace('O','0') if wind_dir != "VRB" and wind_dir != "///" and wind_dir != "MMM": self.wind_dir = direction(wind_dir) wind_speed = d['speed'].replace('O','0') units = d['units'] if units == 'KTS' or units == 'K' or units == 'T' or units == 'LT': units = 'KT' if wind_speed.startswith("P"): self.wind_speed = speed(wind_speed[1:], units, ">") elif not MISSING_RE.match(wind_speed): self.wind_speed = speed(wind_speed, units) if d['gust']: wind_gust = d['gust'] if wind_gust.startswith("P"): self.wind_gust = speed(wind_gust[1:], units, ">") elif not MISSING_RE.match(wind_gust): self.wind_gust = speed(wind_gust, units) if d['varfrom']: self.wind_dir_from = direction(d['varfrom']) self.wind_dir_to = direction(d['varto'])
def _handleWind(self, d): """ Parse the wind and variable-wind groups. The following attributes are set: wind_dir [direction] wind_speed [speed] wind_gust [speed] wind_dir_from [int] wind_dir_to [int] """ wind_dir = d["dir"].replace("O", "0") if wind_dir != "VRB" and wind_dir != "///" and wind_dir != "MMM": self.wind_dir = direction(wind_dir) wind_speed = d["speed"].replace("O", "0") units = d["units"] if units == "KTS" or units == "K" or units == "T" or units == "LT": units = "KT" if wind_speed.startswith("P"): self.wind_speed = speed(wind_speed[1:], units, ">") elif not MISSING_RE.match(wind_speed): self.wind_speed = speed(wind_speed, units) if d["gust"]: wind_gust = d["gust"] if wind_gust.startswith("P"): self.wind_gust = speed(wind_gust[1:], units, ">") elif not MISSING_RE.match(wind_gust): self.wind_gust = speed(wind_gust, units) if d["varfrom"]: self.wind_dir_from = direction(d["varfrom"]) self.wind_dir_to = direction(d["varto"])
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 _handleVisibility( self, d ): """ Parse the minimum and maximum visibility groups. The following attributes are set: vis [distance] vis_dir [direction] max_vis [distance] max_vis_dir [direction] """ vis = d['vis'] vis_less = None vis_dir = None 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 _handleVisibility(self, d): """ Parse the minimum and maximum visibility groups. The following attributes are set: vis [distance] vis_dir [direction] max_vis [distance] max_vis_dir [direction] """ vis = d['vis'] vis_less = None vis_dir = None 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 _handleWind(self, d): """ Parse the wind and variable-wind groups. The following attributes are set: wind_dir [direction] wind_speed [speed] wind_gust [speed] wind_dir_from [int] wind_dir_to [int] """ wind_dir = d['dir'].replace('O', '0') if wind_dir != "VRB" and wind_dir != "///" and wind_dir != "MMM": self.wind_dir = direction(wind_dir) wind_speed = d['speed'].replace('O', '0') units = d['units'] if units == 'KTS' or units == 'K' or units == 'T' or units == 'LT': units = 'KT' if wind_speed.startswith("P"): self.wind_speed = speed(wind_speed[1:], units, ">") elif not MISSING_RE.match(wind_speed): self.wind_speed = speed(wind_speed, units) if d['gust']: wind_gust = d['gust'] if wind_gust.startswith("P"): self.wind_gust = speed(wind_gust[1:], units, ">") elif not MISSING_RE.match(wind_gust): self.wind_gust = speed(wind_gust, units) if d['varfrom']: self.wind_dir_from = direction(d['varfrom']) self.wind_dir_to = direction(d['varto'])
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) )
def _handleWind(self, d): """ Parse the wind and variable-wind groups. The following attributes are set: wind_dir [direction] wind_speed [speed] wind_gust [speed] wind_dir_from [int] wind_dir_to [int] """ wind_dir = d["dir"].replace("O", "0") if wind_dir != "VRB" and wind_dir != "///" and wind_dir != "MMM": self.wind_dir = direction(wind_dir) wind_speed = d["speed"].replace("O", "0") units = d["units"] # Ambiguous METAR when no wind speed units are provided if units is None and self.station_id is not None: # Assume US METAR sites are reporting in KT if len(self.station_id) == 3 or self.station_id.startswith("K"): units = "KT" # If units are still None, default to MPS if units is None: units = "MPS" if units == "KTS" or units == "K" or units == "T" or units == "LT": units = "KT" if wind_speed.startswith("P"): self.wind_speed = speed(wind_speed[1:], units, ">") elif not MISSING_RE.match(wind_speed): self.wind_speed = speed(wind_speed, units) if d["gust"]: wind_gust = d["gust"] if wind_gust.startswith("P"): self.wind_gust = speed(wind_gust[1:], units, ">") elif not MISSING_RE.match(wind_gust): self.wind_gust = speed(wind_gust, units) if d["varfrom"]: self.wind_dir_from = direction(d["varfrom"]) self.wind_dir_to = direction(d["varto"])
def test_error_checking(): """Test that exceptions are raised.""" with pytest.raises(ValueError): direction("North") with pytest.raises(ValueError): direction(-10) with pytest.raises(ValueError): direction("361")
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))
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 testUsage(self): self.assertEqual(direction("90").value(), 90.0) self.assertEqual(direction(90).value(), 90.0) self.assertEqual(direction(90.0).value(), 90.0) self.assertEqual(direction("90").string(), "90 degrees") self.assertEqual(direction("E").compass(), "E")
def testConversion(self): self.assertEqual(direction("N").value(), 0.0) self.assertEqual(direction("NNE").value(), 22.5) self.assertEqual(direction("NE").value(), 45.0) self.assertEqual(direction("ENE").value(), 67.5) self.assertEqual(direction("E").value(), 90.0) self.assertEqual(direction("ESE").value(), 112.5) self.assertEqual(direction("SE").value(), 135.0) self.assertEqual(direction("SSE").value(), 157.5) self.assertEqual(direction("S").value(), 180.0) self.assertEqual(direction("SSW").value(), 202.5) self.assertEqual(direction("SW").value(), 225.0) self.assertEqual(direction("WSW").value(), 247.5) self.assertEqual(direction("W").value(), 270.0) self.assertEqual(direction("WNW").value(), 292.5) self.assertEqual(direction("NW").value(), 315.0) self.assertEqual(direction("NNW").value(), 337.5) self.assertEqual(direction("0").compass(), "N") self.assertEqual(direction("5").compass(), "N") self.assertEqual(direction("355").compass(), "N") self.assertEqual(direction("20").compass(), "NNE") self.assertEqual(direction("60").compass(), "ENE") self.assertEqual(direction("247.5").compass(), "WSW")
def testUsage(self): self.assertEqual( direction("90").value(), 90.0 ) self.assertEqual( direction(90).value(), 90.0 ) self.assertEqual( direction(90.0).value(), 90.0 ) self.assertEqual( direction("90").string(), "90 degrees" ) self.assertEqual( direction("E").compass(), "E" )
def testConversion(self): self.assertEqual( direction("N").value(), 0.0 ) self.assertEqual( direction("NNE").value(), 22.5 ) self.assertEqual( direction("NE").value(), 45.0 ) self.assertEqual( direction("ENE").value(), 67.5 ) self.assertEqual( direction("E").value(), 90.0 ) self.assertEqual( direction("ESE").value(), 112.5 ) self.assertEqual( direction("SE").value(), 135.0 ) self.assertEqual( direction("SSE").value(), 157.5 ) self.assertEqual( direction("S").value(), 180.0 ) self.assertEqual( direction("SSW").value(), 202.5 ) self.assertEqual( direction("SW").value(), 225.0 ) self.assertEqual( direction("WSW").value(), 247.5 ) self.assertEqual( direction("W").value(), 270.0 ) self.assertEqual( direction("WNW").value(), 292.5 ) self.assertEqual( direction("NW").value(), 315.0 ) self.assertEqual( direction("NNW").value(), 337.5 ) self.assertEqual( direction("0").compass(), "N" ) self.assertEqual( direction("5").compass(), "N" ) self.assertEqual( direction("355").compass(), "N" ) self.assertEqual( direction("20").compass(), "NNE" ) self.assertEqual( direction("60").compass(), "ENE" ) self.assertEqual( direction("247.5").compass(), "WSW" )