Beispiel #1
0
 def annotate(self, ax: GeoAxesSubplot,
              **kwargs) -> None:  # coverage: ignore
     if "projection" in ax.__dict__:
         kwargs["transform"] = PlateCarree()
     if "s" not in kwargs:
         kwargs["s"] = self.name
     ax.text(*np.array(self.centroid), **kwargs)
Beispiel #2
0
    def plot(self, ax: GeoAxesSubplot, **kwargs) -> Artist:
        """Plotting function. All arguments are passed to the geometry"""

        if "facecolor" not in kwargs:
            kwargs["facecolor"] = "None"
        if "edgecolor" not in kwargs:
            kwargs["edgecolor"] = ax._get_lines.get_next_color()

        if "projection" in ax.__dict__:
            return ax.add_geometries([self.shape], crs=PlateCarree(), **kwargs)
        else:
            return ax.add_patch(
                MplPolygon(list(self.shape.exterior.coords), **kwargs))
Beispiel #3
0
    def plot(self, ax: GeoAxesSubplot, **kwargs) -> List[Artist]:

        if "projection" in ax.__dict__ and "transform" not in kwargs:
            kwargs["transform"] = PlateCarree()
        if self.shape is not None:
            return ax.plot(*self.shape.xy, **kwargs)
        return []
Beispiel #4
0
    def plot(
        self, ax: GeoAxesSubplot, **kwargs
    ) -> List[Artist]:  # coverage: ignore
        """Plots the trajectory on a Matplotlib axis.

        The Flight supports Cartopy axis as well with automatic projection. If
        no projection is provided, a default `PlateCarree
        <https://scitools.org.uk/cartopy/docs/v0.15/crs/projections.html#platecarree>`_
        is applied.

        Example usage:

        >>> from traffic.drawing import Mercator
        >>> fig, ax = plt.subplots(1, subplot_kw=dict(projection=Mercator())
        >>> flight.plot(ax, alpha=.5)

        .. note::
            See also `geoencode() <#traffic.core.Flight.geoencode>`_ for the
            altair equivalent.

        """

        if "projection" in ax.__dict__ and "transform" not in kwargs:
            kwargs["transform"] = PlateCarree()
        if self.shape is not None:
            return ax.plot(*self.shape.xy, **kwargs)
        return []
Beispiel #5
0
    def plot_wind(
        self,
        ax: GeoAxesSubplot,
        resolution: Union[Dict[str, float], None] = None,
        threshold: int = 10,
        filtered: bool = False,
        **kwargs,
    ) -> List[Artist]:  # coverage: ignore
        """Plots the wind field seen by the aircraft on a Matplotlib axis.

        The Flight supports Cartopy axis as well with automatic projection. If
        no projection is provided, a default `PlateCarree
        <https://scitools.org.uk/cartopy/docs/v0.15/crs/projections.html#platecarree>`_
        is applied.

        The `resolution` argument may be:

            - a dictionary, e.g dict(latitude=4, longitude=4), if you
              want a grid with a resolution of 4 points per latitude and
              longitude degree.
            - None (default) for dict(latitude=1, longitude=1)

        Example usage:

        >>> from traffic.drawing import Mercator
        >>> fig, ax = plt.subplots(1, subplot_kw=dict(projection=Mercator()))
        >>> (
        ...     traffic
        ...     .resample("1s")
        ...     .query('altitude > 10000')
        ...     .compute_wind()
        ...     .eval()
        ...     .plot_wind(ax, alpha=.5)
        ... )

        """

        if "projection" in ax.__dict__ and "transform" not in kwargs:
            kwargs["transform"] = crs.PlateCarree()

        if any(w not in self.data.columns for w in ["wind_u", "wind_v"]):
            raise RuntimeError(
                "No wind data in trajectory. Consider Traffic.compute_wind()")

        data = ((self.iterate_lazy().filter(
            roll=17).query("roll.abs() < .5").filter(
                wind_u=17, wind_v=17).eval(desc="")) if filtered else self)

        windfield = (data.windfield(resolution).query(
            f"timestamp > {threshold}").reset_index())

        return ax.barbs(
            windfield.longitude.values,
            windfield.latitude.values,
            windfield.wind_u.values,
            windfield.wind_v.values,
            **kwargs,
        )
Beispiel #6
0
    def plot(self, ax: GeoAxesSubplot, **kwargs) -> None:  # coverage: ignore
        flat = self.flatten()
        if isinstance(flat, base.BaseMultipartGeometry):
            for poly in flat:
                # quick and dirty
                sub = Airspace("", [ExtrudedPolygon(poly, 0, 0)])
                sub.plot(ax, **kwargs)
            return

        if "facecolor" not in kwargs:
            kwargs["facecolor"] = "None"
        if "edgecolor" not in kwargs:
            kwargs["edgecolor"] = ax._get_lines.get_next_color()

        if "projection" in ax.__dict__:
            ax.add_geometries([flat], crs=PlateCarree(), **kwargs)
        else:
            ax.add_patch(MplPolygon(list(flat.exterior.coords), **kwargs))
Beispiel #7
0
 def plot(
     self, ax: GeoAxesSubplot, s: int = 10, **kwargs
 ) -> Artist:  # coverage: ignore
     """Plotting function. All arguments are passed to ax.scatter"""
     return ax.scatter(
         self.data.longitude,
         self.data.latitude,
         s=s,
         transform=PlateCarree(),
         **kwargs,
     )
Beispiel #8
0
 def plot(
     self, ax: GeoAxesSubplot, cmap: str = "inferno", s: int = 5, **kwargs
 ) -> Artist:
     """Plotting function. All arguments are passed to ax.scatter"""
     return ax.scatter(
         self.df.longitude,
         self.df.latitude,
         s=s,
         transform=PlateCarree(),
         c=-self.df.altitude,
         cmap=cmap,
         **kwargs,
     )
Beispiel #9
0
    def plot(
        self,
        ax: GeoAxesSubplot,
        airports: bool = True,
        airports_kw: Optional[Dict[str, Any]] = None,
        labels: Union[None, bool, str] = None,
        labels_kw: Optional[Dict[str, Any]] = None,
        **kwargs,
    ) -> List[Artist]:  # coverage: ignore
        """Plots the trajectory on a Matplotlib axis.

        FlightPlans support Cartopy axis as well with automatic projection. If
        no projection is provided, a default `PlateCarree
        <https://scitools.org.uk/cartopy/docs/v0.15/crs/projections.html#platecarree>`_
        is applied.

        Example usage:

        .. code:: python

            from traffic.drawing import Mercator
            fig, ax = plt.subplots(1, subplot_kw=dict(projection=Mercator())
            flightplan.plot(ax, labels=True, alpha=.5)

        .. note::
            See also `geoencode() <#traffic.core.Flight.geoencode>`_ for the
            altair equivalent.

        """

        cumul = []
        if "projection" in ax.__dict__ and "transform" not in kwargs:
            kwargs["transform"] = PlateCarree()

        if self.shape is not None:
            if isinstance(self.shape, LineString):
                cumul.append(ax.plot(*self.shape.xy, **kwargs))
            else:
                for s_ in self.shape:
                    cumul.append(ax.plot(*s_.xy, **kwargs))

        airports_style = dict(s=50, marker=markers.atc_tower)
        if airports_kw is not None:
            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