def test_temporary_group_3(self):
     self._test_temporary_group(
         raw="TEMPO 0100/0103 4SM -RA BR",
         start_time=aviation_weather.Time("010000Z"),
         end_time=aviation_weather.Time("010300Z"),
         wind=None,
         visibility=aviation_weather.Visibility("4SM"),
         weather_groups=(aviation_weather.WeatherGroup("-RA"),
                         aviation_weather.WeatherGroup("BR")),
         sky_conditions=())
 def test_probability_group_1(self):
     self._test_probability_group(
         raw="PROB30 1004/1007 1SM -RA BR",
         probability=30,
         start_time=aviation_weather.Time("100400Z"),
         end_time=aviation_weather.Time("100700Z"),
         wind=None,
         visibility=aviation_weather.Visibility("1SM"),
         weather_groups=(aviation_weather.WeatherGroup("-RA"),
                         aviation_weather.WeatherGroup("BR")),
         sky_conditions=())
 def test_temporary_group_2(self):
     self._test_temporary_group(
         raw="TEMPO 0100/0102 2SM -SN BR FEW007 OVC010",
         start_time=aviation_weather.Time("010000Z"),
         end_time=aviation_weather.Time("010200Z"),
         wind=None,
         visibility=aviation_weather.Visibility("2SM"),
         weather_groups=(aviation_weather.WeatherGroup("-SN"),
                         aviation_weather.WeatherGroup("BR")),
         sky_conditions=(aviation_weather.SkyCondition("FEW007"),
                         aviation_weather.SkyCondition("OVC010")))
 def test_parse_KPIT(self):
     self._test_parse(
         raw=(
             "TAF KPIT 091730Z 0918/1024 15005KT 5SM HZ FEW020 WS010/31022KT"
             " FM091930 30015G25KT 3SM SHRA OVC015"
             " TEMPO 0920/0922 1/2SM +TSRA OVC008CB"
             " FM100100 27008KT 5SM SHRA BKN020 OVC040"
             " PROB30 1004/1007 1SM -RA BR"
             " FM101015 18005KT 6SM -SHRA OVC020"
             " BECMG 1013/1015 P6SM NSW SKC"),
         type_=aviation_weather.MessageType("TAF"),
         location=aviation_weather.Location("KPIT"),
         time=aviation_weather.Time("091730Z"),
         valid_period=(aviation_weather.Time("091800Z"),
                       aviation_weather.Time("102400Z")),
         wind=aviation_weather.Wind("15005KT"),
         visibility=aviation_weather.Visibility("5SM"),
         weather_groups=(aviation_weather.WeatherGroup("HZ"), ),
         sky_conditions=(aviation_weather.SkyCondition("FEW020"), ),
         wind_shear=aviation_weather.WindShear("WS010/31022KT"),
         changes=[
             aviation_weather.FromGroup(
                 "FM091930 30015G25KT 3SM SHRA OVC015"),
             aviation_weather.TemporaryGroup(
                 "TEMPO 0920/0922 1/2SM +TSRA OVC008CB"),
             aviation_weather.FromGroup(
                 "FM100100 27008KT 5SM SHRA BKN020 OVC040"),
             aviation_weather.ProbabilityGroup(
                 "PROB30 1004/1007 1SM -RA BR"),
             aviation_weather.FromGroup(
                 "FM101015 18005KT 6SM -SHRA OVC020"),
             aviation_weather.BecomingGroup("BECMG 1013/1015 P6SM NSW SKC")
         ])
 def test_from_group_3(self):
     self._test_from_group(
         raw="FM101015 18005KT 6SM -SHRA OVC020",
         time=aviation_weather.Time("101015Z"),
         wind=aviation_weather.Wind("18005KT"),
         visibility=aviation_weather.Visibility("6SM"),
         weather_groups=(aviation_weather.WeatherGroup("-SHRA"), ),
         sky_conditions=(aviation_weather.SkyCondition("OVC020"), ))
 def test_from_group_1(self):
     self._test_from_group(
         raw="FM091930 30015G25KT 3SM SHRA OVC015",
         time=aviation_weather.Time("091930Z"),
         wind=aviation_weather.Wind("30015G25KT"),
         visibility=aviation_weather.Visibility("3SM"),
         weather_groups=(aviation_weather.WeatherGroup("SHRA"), ),
         sky_conditions=(aviation_weather.SkyCondition("OVC015"), ))
 def test_from_group_2(self):
     self._test_from_group(
         raw="FM100100 27008KT 5SM SHRA BKN020 OVC040",
         time=aviation_weather.Time("100100Z"),
         wind=aviation_weather.Wind("27008KT"),
         visibility=aviation_weather.Visibility("5SM"),
         weather_groups=(aviation_weather.WeatherGroup("SHRA"), ),
         sky_conditions=(aviation_weather.SkyCondition("BKN020"),
                         aviation_weather.SkyCondition("OVC040")))
 def test_becoming_group_1(self):
     self._test_becoming_group(
         raw="BECMG 1013/1015 P6SM NSW SKC",
         start_time=aviation_weather.Time("101300Z"),
         end_time=aviation_weather.Time("101500Z"),
         wind=None,
         visibility=aviation_weather.Visibility("P6SM"),
         weather_groups=(aviation_weather.WeatherGroup("NSW"), ),
         sky_conditions=(aviation_weather.SkyCondition("SKC"), ))
 def test_temporary_group_6(self):
     self._test_temporary_group(
         raw="TEMPO 0215/0218 7000 SHRA BKN014",
         start_time=aviation_weather.Time("021500Z"),
         end_time=aviation_weather.Time("021800Z"),
         wind=None,
         visibility=aviation_weather.Visibility("7000"),
         weather_groups=(aviation_weather.WeatherGroup("SHRA"), ),
         sky_conditions=(aviation_weather.SkyCondition("BKN014"), ))
 def test_temporary_group_5(self):
     self._test_temporary_group(
         raw="TEMPO 0207/0212 22018G28KT 4000 RA BKN012",
         start_time=aviation_weather.Time("020700Z"),
         end_time=aviation_weather.Time("021200Z"),
         wind=aviation_weather.Wind("22018G28KT"),
         visibility=aviation_weather.Visibility("4000"),
         weather_groups=(aviation_weather.WeatherGroup("RA"), ),
         sky_conditions=(aviation_weather.SkyCondition("BKN012"), ))
 def test_temporary_group_4(self):
     self._test_temporary_group(
         raw="TEMPO 0121/0124 8000 -RA",
         start_time=aviation_weather.Time("012100Z"),
         end_time=aviation_weather.Time("012400Z"),
         wind=None,
         visibility=aviation_weather.Visibility("8000"),
         weather_groups=(aviation_weather.WeatherGroup("-RA"), ),
         sky_conditions=())
 def test_temporary_group_1(self):
     self._test_temporary_group(
         raw="TEMPO 0920/0922 1/2SM +TSRA OVC008CB",
         start_time=aviation_weather.Time("092000Z"),
         end_time=aviation_weather.Time("092200Z"),
         wind=None,
         visibility=aviation_weather.Visibility("1/2SM"),
         weather_groups=(aviation_weather.WeatherGroup("+TSRA"), ),
         sky_conditions=(aviation_weather.SkyCondition("OVC008CB"), ))
 def test_probability_group_2(self):
     self._test_probability_group(
         raw="PROB30 0121/0206 2SM BR OVC006",
         probability=30,
         start_time=aviation_weather.Time("012100Z"),
         end_time=aviation_weather.Time("020600Z"),
         wind=None,
         visibility=aviation_weather.Visibility("2SM"),
         weather_groups=(aviation_weather.WeatherGroup("BR"), ),
         sky_conditions=(aviation_weather.SkyCondition("OVC006"), ))
Exemplo n.º 14
0
    def __init__(self, raw):
        try:
            self.wind = aviation_weather.Wind(raw)
            raw = raw.replace(self.wind.raw, "")
        except exceptions.WindDecodeError:
            self.wind = None

        try:
            self.visibility = aviation_weather.Visibility(raw)
            raw = raw.replace(self.visibility.raw, "")
        except exceptions.VisibilityDecodeError:
            self.visibility = None

        r = raw.split()

        # Weather groups
        t = list()
        i = 0
        try:
            while True:
                t.append(aviation_weather.WeatherGroup(r[i]))
                i += 1
        except (exceptions.WeatherGroupDecodeError, IndexError):
            r = r[i:]
        self.weather_groups = tuple(t)

        # Sky conditions
        t = list()
        i = 0
        try:
            while True:
                t.append(aviation_weather.SkyCondition(r[i]))
                i += 1
        except (exceptions.SkyConditionDecodeError, IndexError):
            r = r[i:]
        self.sky_conditions = tuple(t)

        # Remarks (Canadian TAFs seem to always end with remarks)
        self._remarks = None
        if r:
            try:
                self._remarks = aviation_weather.Remarks(" ".join(r))
            except exceptions.RemarksDecodeError as e:
                raise exceptions.ChangeGroupDecodeError from e
Exemplo n.º 15
0
    def _parse(self, raw, parts):
        part = parts[0]
        t = re.match(r"TAF(?: AMD)?\s+", raw)
        if t is None:
            self.type = None
            r = part.split()
        else:
            tg = t.group()
            self.type = aviation_weather.MessageType(tg.rstrip())
            r = part.lstrip(tg).split()

        self.location = aviation_weather.Location(r[0])
        self.time = aviation_weather.Time(r[1])
        self.valid_period = tuple(
            aviation_weather.Time("%s00Z" % period)
            for period in r[2].split("/"))
        self.wind = aviation_weather.Wind(r[3])
        self.visibility = aviation_weather.Visibility(r[4])

        # Weather groups
        t = list()
        i = 5
        try:
            while True:
                t.append(aviation_weather.WeatherGroup(r[i]))
                i += 1
        except (exceptions.WeatherGroupDecodeError, IndexError):
            r = r[i:]
        self.weather_groups = tuple(t)

        # Sky conditions
        t = list()
        i = 0
        try:
            while True:
                t.append(aviation_weather.SkyCondition(r[i]))
                i += 1
        except (exceptions.SkyConditionDecodeError, IndexError):
            r = r[i:]
        self.sky_conditions = tuple(t)

        if r:
            self.wind_shear = aviation_weather.WindShear(r[0])
        else:
            self.wind_shear = None

        # Changes
        self.changes = list()
        for part in parts[1:]:
            if part.startswith("BECMG"):
                p = aviation_weather.BecomingGroup(part)
            elif part.startswith("FM"):
                p = aviation_weather.FromGroup(part)
            elif part.startswith("PROB"):
                p = aviation_weather.ProbabilityGroup(part)
            elif part.startswith("TEMPO"):
                p = aviation_weather.TemporaryGroup(part)
            else:
                p = None
            if p:
                self.changes.append(p)
Exemplo n.º 16
0
    def _parse_body(self, text):
        parts = text.split()
        if len(parts) == 0:
            raise exceptions.ReportDecodeError

        if parts[0] in ("METAR", "SPECI"):
            self.type = aviation_weather.MessageType(parts[0])
            parts = parts[1:]
        else:
            self.type = None

        if "AUTO" in parts:
            self.modifier = "AUTO"
        # elif "COR" in parts:
        #     self.modifier = "COR"
        else:
            self.modifier = None
        if self.modifier:
            parts.remove(self.modifier)

        self.location = aviation_weather.Location(parts[0])
        self.time = aviation_weather.Time(parts[1])

        try:
            self.wind = aviation_weather.Wind(text)
        except (exceptions.WindDecodeError, IndexError):
            self.wind = None
            parts = parts[2:]
        else:
            parts = " ".join(parts[2:]).split(self.wind.raw, 1)[1].split()  # remove used parts

        try:
            self.visibility = aviation_weather.Visibility(" ".join(parts[:2]))
        except (exceptions.VisibilityDecodeError, IndexError):
            self.visibility = None
        else:
            parts = text.split(self.visibility.raw, 1)[1].split()  # remove used parts

        t = list()
        i = 0
        try:
            while True:
                t.append(aviation_weather.RunwayVisualRange(parts[i]))
                i += 1
        except (exceptions.RunwayVisualRangeDecodeError, IndexError):
            parts = parts[i:]
        self.runway_visual_range = tuple(t) or None

        t = list()
        i = 0
        try:
            while True:
                t.append(aviation_weather.WeatherGroup(parts[i]))
                i += 1
        except (exceptions.WeatherGroupDecodeError, IndexError):
            parts = parts[i:]
        self.weather_groups = tuple(t) or None

        t = list()
        i = 0
        try:
            while True:
                t.append(aviation_weather.SkyCondition(parts[i]))
                i += 1
        except (exceptions.SkyConditionDecodeError, IndexError):
            parts = parts[i:]
        self.sky_conditions = tuple(t) or None

        try:
            self.temperature = aviation_weather.Temperature(parts[0])
        except (exceptions.TemperatureDecodeError, IndexError):
            self.temperature = None
        else:
            parts = parts[1:]

        try:
            self.pressure = aviation_weather.Pressure(parts[0])
        except (exceptions.PressureDecodeError, IndexError):
            self.pressure = None

        end = " ".join(parts[1:])
        if end:
            end = _Container(end)
        else:
            end = None
        self._end = end