How to use the traffic.core.flightplan._ElementaryBlock function in traffic

To help you get started, we’ve selected a few traffic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xoolive / traffic / tests / test_flightplan.py View on Github external
def test_direct():
    assert Direct.valid("DCT")
    assert not Direct.valid("N0450F340")
    assert type(_ElementaryBlock.parse("DCT")) is Direct
github xoolive / traffic / traffic / core / flightplan.py View on Github external
class Airway(_ElementaryBlock):
    pattern = r"\w{2,7}$"

    def get(self) -> Optional[Route]:
        from traffic.data import airways

        return airways.global_get(self.elt[0])

    @classmethod
    def valid(cls, elt: str) -> bool:
        return bool(re.match(cls.pattern, elt)) and any(
            i.isdigit() for i in elt
        )


class Point(_ElementaryBlock):
    pattern = r"\D{2,5}$"

    def get(self) -> Optional[Navaid]:
        from traffic.data import navaids

        return navaids.global_get(self.elt[0])


# EXPERIMENTAL
class DirectPoint(Point):
    pass


class SID(Airway):
    @classmethod
    def valid(cls, elt: str) -> bool:
github xoolive / traffic / traffic / core / flightplan.py View on Github external
# M (Altitude in meter)

    def __init__(self, elt):
        x = re.match(self.pattern, elt)
        assert x is not None

        speed, alt = x.group(1), x.group(2)
        self.speed_unit = speed[0]
        self.speed = int(speed[1:])
        self.altitude_unit = alt[0]
        self.altitude = int(alt[1:])

        self.elt = speed, alt


class Airway(_ElementaryBlock):
    pattern = r"\w{2,7}$"

    def get(self) -> Optional[Route]:
        from traffic.data import airways

        return airways.global_get(self.elt[0])

    @classmethod
    def valid(cls, elt: str) -> bool:
        return bool(re.match(cls.pattern, elt)) and any(
            i.isdigit() for i in elt
        )


class Point(_ElementaryBlock):
    pattern = r"\D{2,5}$"
github xoolive / traffic / traffic / core / flightplan.py View on Github external
def decompose(self) -> List[Optional[_ElementaryBlock]]:
        parsed: List[Optional[_ElementaryBlock]] = []
        blocks = repr(self).strip().split()

        for i, elt in enumerate(blocks):
            parsed.append(
                _ElementaryBlock.parse(
                    elt, parsed[-1] if i > 0 else None, len(blocks) - i == 1
                )
            )

        return parsed
github xoolive / traffic / traffic / core / flightplan.py View on Github external
def decompose(self) -> List[Optional[_ElementaryBlock]]:
        parsed: List[Optional[_ElementaryBlock]] = []
        blocks = repr(self).strip().split()

        for i, elt in enumerate(blocks):
            parsed.append(
                _ElementaryBlock.parse(
                    elt, parsed[-1] if i > 0 else None, len(blocks) - i == 1
                )
            )

        return parsed
github xoolive / traffic / traffic / core / flightplan.py View on Github external
return airways.global_get(self.elt[0] + airport)

        if nm_airways.available:
            possible = set(
                nm_airways.data.query(
                    f'route.str.startswith("{self.elt[0]}")'
                ).route
            )
            if len(possible) == 1:
                return nm_airways[possible.pop()]

        warnings.warn(f"Could not find any corresponding SID for {self.elt[0]}")
        return None


class ChangeOfFlightRule(_ElementaryBlock):
    pattern = r"VFR$|IFR$"


class CoordinatePoint(_ElementaryBlock):
    pattern = r"(\d{2}|\d{4})([N,S])(\d{3}|\d{5})([E,W])$"
    lon: float
    lat: float

    def get(self) -> Navaid:
        return Navaid(
            cast(str, self.elt),
            "NDB",
            self.lat,
            self.lon,
            float("nan"),
            None,
github xoolive / traffic / traffic / core / flightplan.py View on Github external
lon, lon_sign = x.group(3), 1 if x.group(4) == "E" else -1

        if len(lat) == 2:
            self.lat = lat_sign * int(lat)
        else:
            self.lat = lat_sign * int(lat) / 100

        if len(lon) == 3:
            self.lon = lon_sign * int(lon)
        else:
            self.lon = lon_sign * int(lon) / 100

        self.elt = elt


class SpeedLevelChangePoint(_ElementaryBlock):

    pattern = "(.*)/(.*)"

    def get(self) -> Optional[Navaid]:
        return self.elt[0].get()

    @property
    def name(self) -> str:
        return self.elt[0].name

    @property
    def text(self) -> str:
        return f"{self.elt[0].name} ({self.elt[1].name})"


class FlightPlan(ShapelyMixin):
github xoolive / traffic / traffic / core / flightplan.py View on Github external
if Point.valid(elt):
                return Point(elt)
            elif SID.valid(elt):
                return SID(elt)

        elif Airway.valid(elt):
            return Airway(elt)

        elif isinstance(previous_elt, Point) and DirectPoint.valid(elt):
            # EXPERIMENTAL
            return DirectPoint(elt)

        return None


class Direct(_ElementaryBlock):
    pattern = "DCT$"


class SpeedLevel(_ElementaryBlock):
    pattern = r"([K,N]\d{4}|M\d{3})(([A,F]\d{3})|[S,M]\d{4})$"

    # -- Speed units --
    # K (Kilometers)
    # N (Knots)
    # M (Mach)
    # -- Altitude units --
    # F (Flight Level)
    # S (Standard Metric)
    # A (Altitude in feet)
    # M (Altitude in meter)
github xoolive / traffic / traffic / core / flightplan.py View on Github external
nm_airways.data.query(
                    f'route.str.startswith("{self.elt[0]}")'
                ).route
            )
            if len(possible) == 1:
                return nm_airways[possible.pop()]

        warnings.warn(f"Could not find any corresponding SID for {self.elt[0]}")
        return None


class ChangeOfFlightRule(_ElementaryBlock):
    pattern = r"VFR$|IFR$"


class CoordinatePoint(_ElementaryBlock):
    pattern = r"(\d{2}|\d{4})([N,S])(\d{3}|\d{5})([E,W])$"
    lon: float
    lat: float

    def get(self) -> Navaid:
        return Navaid(
            cast(str, self.elt),
            "NDB",
            self.lat,
            self.lon,
            float("nan"),
            None,
            None,
            None,
        )
github xoolive / traffic / traffic / core / flightplan.py View on Github external
elif Airway.valid(elt):
            return Airway(elt)

        elif isinstance(previous_elt, Point) and DirectPoint.valid(elt):
            # EXPERIMENTAL
            return DirectPoint(elt)

        return None


class Direct(_ElementaryBlock):
    pattern = "DCT$"


class SpeedLevel(_ElementaryBlock):
    pattern = r"([K,N]\d{4}|M\d{3})(([A,F]\d{3})|[S,M]\d{4})$"

    # -- Speed units --
    # K (Kilometers)
    # N (Knots)
    # M (Mach)
    # -- Altitude units --
    # F (Flight Level)
    # S (Standard Metric)
    # A (Altitude in feet)
    # M (Altitude in meter)

    def __init__(self, elt):
        x = re.match(self.pattern, elt)
        assert x is not None