How to use the traffic.data.airports 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_airports.py View on Github external
def test_getter() -> None:
    airport = airports["LHR"]
    assert airport is not None
    assert airport.icao == "EGLL"
    assert airport.iata == "LHR"
    assert airport.country == "United Kingdom"
    assert airport.name == "London Heathrow Airport"
    lat, lon = airport.latlon
    assert max(abs(lat - 51.471626), abs(lon + 0.467081)) < 1e-2
github xoolive / traffic / tests / test_flight.py View on Github external
def test_closest_point() -> None:
    from traffic.data import navaids, airports

    item = belevingsvlucht.between(
        "2018-05-30 16:00", "2018-05-30 17:00"
    ).closest_point(  # type: ignore
        [
            airports["EHLE"],  # type: ignore
            airports["EHAM"],  # type: ignore
            navaids["NARAK"],  # type: ignore
        ]
    )
    res = f"{item.timestamp:%H:%M:%S}, {item.point}, {item.distance:.2f}m"
    assert res == "16:53:46, Lelystad Airport, 49.11m"
github xoolive / traffic / traffic / core / flightplan.py View on Github external
def _info_html(self) -> str:
        from traffic.data import airports

        title = (
            "<h4><b>FlightPlan{from_}{to_}</b></h4>"
            "<div style="max-width: 600px"><code>"
        ).format(
            from_=f" from {airports[self.origin]}"
            if self.origin is not None
            else "",
            to_=f" to {airports[self.destination]}"
            if self.destination is not None
            else "",
        )
        title += " ".join(re.sub(r"\s+", " ", self.repr).strip().split())
        title += "</code></div>"
        return title
github xoolive / traffic / traffic / core / flightplan.py View on Github external
airports_style = {**airports_style, **airports_kw}

        labels_style = dict(s=30, marker="^", zorder=3)
        if labels_kw is not None:
            labels_style = {**labels_style, **labels_kw}

        if airports and self.origin:
            from traffic.data import airports as airport_db

            ap = airport_db[self.origin]
            if ap is not None:
                cumul.append(ap.point.plot(ax, **airports_style))
        if airports and self.destination:
            from traffic.data import airports as airport_db

            ap = airport_db[self.destination]
            if ap is not None:
                cumul.append(ap.point.plot(ax, **airports_style))

        if labels:
            for point in self.all_points if labels == "all" else self.points:
                cumul.append(point.plot(ax, **labels_style))

        return cumul
github xoolive / traffic / traffic / data / eurocontrol / ddr / allft.py View on Github external
def _repr_html_(self):
        from ....data import aircraft, airports

        title = f"<h4><b>Flight {self.flight_id}</b> "
        title += f"({self.origin} → "
        title += f"{self.destination})</h4>"
        title += f"callsign: {self.callsign}<br>"
        title += f" from {airports[self.origin]}<br>"
        title += f" to {airports[self.destination]}<br><br>"

        cumul = list()
        if self.icao24 is not None:
            cumul.append(aircraft[self.icao24].T)

        cumul.append(
            pd.DataFrame(
                self.data[
                    [
                        "ifpsId",
                        "AOBT",
                        "IOBT",
                        "COBT",
                        "EOBT",
                        "flightState",
                        "mostPenalizingRegulationId",
github xoolive / traffic / traffic / algorithms / navigation.py View on Github external
The method relies on the `destination` parameter to identify the
        intended destination.

        """
        from ..data import airports

        f_above = self.query("altitude > 15000")  # type: ignore
        if (
            self.destination != self.destination  # type: ignore
            or airports[self.destination] is None  # type: ignore
            or f_above is None
        ):
            return None

        return (
            f_above.distance(airports[self.destination])  # type: ignore
            .diff("distance")
            .agg_time("10T", distance_diff="mean")
            .query("distance_diff > 0")
        )
github xoolive / traffic / traffic / data / adsb / opensky.py View on Github external
specific date (as a string, as an epoch or as a datetime)

        Official documentation
        ----------------------

        Retrieve flights for a certain airport which departed within a given
        time interval [begin, end]. If no flights are found for the given
        period, HTTP stats 404 - Not found is returned with an empty response
        body.

        """

        if isinstance(airport, str):
            from .. import airports

            airport_handle = airports[airport]
            if airport_handle is None:
                raise RuntimeError(f"Unknown airport {airport}")
            airport_code = airport_handle.icao
        else:
            airport_code = airport.icao

        if begin is None:
            begin = round_time(datetime.now(timezone.utc), by=timedelta(days=1))
        begin = to_datetime(begin)
        if end is None:
            end = begin + timedelta(days=1)
        else:
            end = to_datetime(end)

        begin = int(begin.timestamp())
        end = int(end.timestamp())
github xoolive / traffic / traffic / data / adsb / decode.py View on Github external
def __init__(
        self, reference: Union[None, str, Airport, Tuple[float, float]] = None
    ) -> None:
        if isinstance(reference, str):
            from ...data import airports

            reference = airports[reference]

        if reference is None:
            logging.warning(
                "No valid reference position provided. Fallback to (0, 0)"
            )
            lat0, lon0 = 0.0, 0.0
        elif isinstance(reference, Airport):
            lat0, lon0 = reference.latlon
        else:
            lat0, lon0 = reference

        self.acs: AircraftDict = AircraftDict()
        self.acs.set_latlon(lat0, lon0)
        self.thread = None
github xoolive / traffic / traffic / core / distance.py View on Github external
def guess_airport(
    point: Optional[NamedTuple] = None,
    *args,
    latitude: Optional[float] = None,
    longitude: Optional[float] = None,
    dataset: Optional["Airports"] = None,
    warning_distance: Optional[float] = None,
) -> "Airport":

    if dataset is None:
        from ..data import airports

        dataset = airports

    # TODO define a protocol instead of PointMixin
    if point is not None:
        longitude = point.longitude  # type: ignore
        latitude = point.latitude  # type: ignore
    if any((longitude is None, latitude is None)):
        raise RuntimeError("latitude or longitude are None")

    airport_data = closest_point(
        dataset.data, latitude=latitude, longitude=longitude
    )

    airport = dataset[airport_data.icao]
    assert airport is not None
    airport.distance = airport_data.distance  # type: ignore
github xoolive / traffic / traffic / drawing / ipywidgets.py View on Github external
if len(self.area_input.value) == 0:
                from cartotools.osm import request, tags

                west, east, south, north = self.ax_map.get_extent(
                    crs=PlateCarree()
                )
                if abs(east - west) > 1 or abs(north - south) > 1:
                    # that would be a too big request
                    return
                request((west, south, east, north), **tags.airport).plot(
                    self.ax_map
                )
            else:
                from ..data import airports

                airport_handle = airports[self.area_input.value]
                assert airport_handle is not None
                airport_handle.plot(self.ax_map)
            self.canvas_map.draw_idle()