traffic/core/flight.py
def query_ehs(
        self,
        data: Union[None, pd.DataFrame, "RawData"] = None,
        failure_mode: str = "warning",
        progressbar: Union[bool, Callable[[Iterable], Iterable]] = True,
    ) -> "Flight":
        """Extends data with extra columns from EHS messages.

        By default, raw messages are requested from the OpenSky Network
        database.

        .. warning::
            Making a lot of small requests can be very inefficient and may look
            like a denial of service. If you get the raw messages using a
            different channel, you can provide the resulting dataframe as a
            parameter. See the page about `OpenSky Impala access
            <opensky_impala.html>`_

        The data parameter expect three columns: ``icao24``, ``rawmsg`` and
        ``mintime``, in conformance with the OpenSky API.

        .. note::
            Read more about access to the OpenSky Network database `here
            <opensky_impala.html>`_
        """

        from ..data import opensky
        from ..data.adsb.raw_data import RawData  # noqa: F811

        if not isinstance(self.icao24, str):
            raise RuntimeError("Several icao24 for this flight")

        if not isinstance(self.callsign, str):
            raise RuntimeError("Several callsigns for this flight")

        def fail_warning():
            """Called when nothing can be added to data."""
            id_ = self.flight_id
            if id_ is None:
                id_ = self.callsign
            logging.warning(f"No data on Impala for flight {id_}.")
            return self

        def fail_silent():
            return self

        failure_dict = dict(warning=fail_warning, silent=fail_silent)
        failure = failure_dict[failure_mode]

        if data is None:
            ext = opensky.extended(self.start, self.stop, icao24=self.icao24)
            df = ext.data if ext is not None else None
        else:
            df = data if isinstance(data, pd.DataFrame) else data.data
            df = df.query(
                "icao24 == @self.icao24 and "
                "@self.start < mintime < @self.stop"
            )

        if df is None or df.shape[0] == 0:
            return failure()

        timestamped_df = df.sort_values("mintime").assign(
            timestamp=lambda df: df.mintime.dt.round("s")
        )

        referenced_df = (
            timestamped_df.merge(self.data, on="timestamp", how="outer")
            .sort_values("timestamp")
            .rename(
                columns=dict(
                    altitude="alt",
                    altitude_y="alt",
                    groundspeed="spd",
                    track="trk",
                )
            )[["timestamp", "latitude", "longitude", "alt", "spd", "trk"]]
            .ffill()
            .drop_duplicates()  # bugfix! NEVER ERASE THAT LINE!
            .merge(
                timestamped_df[["timestamp", "icao24", "rawmsg"]],
                on="timestamp",
                how="right",
            )
        )

        identifier = (
            self.flight_id if self.flight_id is not None else self.callsign
        )

        t = RawData(referenced_df).decode(
            reference=self.origin if isinstance(self.origin, str) else None,
            progressbar=progressbar,
            progressbar_kw=dict(leave=False, desc=f"{identifier}:"),
        )

        extended = t[self.icao24] if t is not None else None
        if extended is None:
            return failure()

        # fix for https://stackoverflow.com/q/53657210/1595335
        if "last_position" in self.data.columns:
            extended = extended.assign(last_position=pd.NaT)
        if "start" in self.data.columns:
            extended = extended.assign(start=pd.NaT)
        if "stop" in self.data.columns:
            extended = extended.assign(stop=pd.NaT)

        aggregate = extended + self
        if "flight_id" in self.data.columns:
            aggregate.data.flight_id = self.flight_id

        # sometimes weird callsigns are decoded and should be discarded
        # so it seems better to filter on callsign rather than on icao24
        flight = aggregate[self.callsign]
        if flight is None:
            return failure()

        if self.number is not None:
            flight = flight.assign(number=self.number)
        if self.origin is not None:
            flight = flight.assign(origin=self.origin)
        if self.destination is not None:
            flight = flight.assign(destination=self.destination)

        return flight.sort_values("timestamp")
Extends data with extra columns from EHS messages.

        By default, raw messages are requested from the OpenSky Network
        database.

        .. warning::
            Making a lot of small requests can be very inefficient and may look
            like a denial of service. If you get the raw messages using a
            different channel, you can provide the resulting dataframe as a
            parameter. See the page about `OpenSky Impala access
            <opensky_impala.html>`_

        The data parameter expect three columns: ``icao24``, ``rawmsg`` and
        ``mintime``, in conformance with the OpenSky API.

        .. note::
            Read more about access to the OpenSky Network database `here
            <opensky_impala.html>`_
        
Extends data with extra columns from EHS messages.
By default, raw messages are requested from the OpenSky Network
database.

:
Making a lot of small requests can be very inefficient and may look
like a denial of service. If you get the raw messages using a
different channel, you can provide the resulting dataframe as a
parameter. See the page about `OpenSky Impala access
`_



:
Read more about access to the OpenSky Network database `here
`_
Extends data with extra columns from EHS messages . By default raw messages are requested from the OpenSky Network database . : Making a lot of small requests can be very inefficient and may look like a denial of service . If you get the raw messages using a different channel you can provide the resulting dataframe as a parameter . See the page about ` OpenSky Impala access ` _ : Read more about access to the OpenSky Network database ` here ` _
def query_ehs(
        self,
        data: Union[None, pd.DataFrame, "RawData"] = None,
        failure_mode: str = "warning",
        progressbar: Union[bool, Callable[[Iterable], Iterable]] = True,
    ) -> "Flight":
        from ..data import opensky
        from ..data.adsb.raw_data import RawData  
        if not isinstance(self.icao24, str):
            raise RuntimeError("Several icao24 for this flight")
        if not isinstance(self.callsign, str):
            raise RuntimeError("Several callsigns for this flight")
        def fail_warning():
            id_ = self.flight_id
            if id_ is None:
                id_ = self.callsign
            logging.warning(f"No data on Impala for flight {id_}.")
            return self
        def fail_silent():
            return self
        failure_dict = dict(warning=fail_warning, silent=fail_silent)
        failure = failure_dict[failure_mode]
        if data is None:
            ext = opensky.extended(self.start, self.stop, icao24=self.icao24)
            df = ext.data if ext is not None else None
        else:
            df = data if isinstance(data, pd.DataFrame) else data.data
            df = df.query(
                "icao24 == @self.icao24 and "
                "@self.start < mintime < @self.stop"
            )
        if df is None or df.shape[0] == 0:
            return failure()
        timestamped_df = df.sort_values("mintime").assign(
            timestamp=lambda df: df.mintime.dt.round("s")
        )
        referenced_df = (
            timestamped_df.merge(self.data, on="timestamp", how="outer")
            .sort_values("timestamp")
            .rename(
                columns=dict(
                    altitude="alt",
                    altitude_y="alt",
                    groundspeed="spd",
                    track="trk",
                )
            )[["timestamp", "latitude", "longitude", "alt", "spd", "trk"]]
            .ffill()
            .drop_duplicates()  
            .merge(
                timestamped_df[["timestamp", "icao24", "rawmsg"]],
                on="timestamp",
                how="right",
            )
        )
        identifier = (
            self.flight_id if self.flight_id is not None else self.callsign
        )
        t = RawData(referenced_df).decode(
            reference=self.origin if isinstance(self.origin, str) else None,
            progressbar=progressbar,
            progressbar_kw=dict(leave=False, desc=f"{identifier}:"),
        )
        extended = t[self.icao24] if t is not None else None
        if extended is None:
            return failure()
        if "last_position" in self.data.columns:
            extended = extended.assign(last_position=pd.NaT)
        if "start" in self.data.columns:
            extended = extended.assign(start=pd.NaT)
        if "stop" in self.data.columns:
            extended = extended.assign(stop=pd.NaT)
        aggregate = extended + self
        if "flight_id" in self.data.columns:
            aggregate.data.flight_id = self.flight_id
        flight = aggregate[self.callsign]
        if flight is None:
            return failure()
        if self.number is not None:
            flight = flight.assign(number=self.number)
        if self.origin is not None:
            flight = flight.assign(origin=self.origin)
        if self.destination is not None:
            flight = flight.assign(destination=self.destination)
        return flight.sort_values("timestamp")
def query_ehs ( self , data : Union [ None , pd . DataFrame , "RawData" ] = None , failure_mode : str = "warning" , progressbar : Union [ bool , Callable [ [ Iterable ] , Iterable ] ] = True , ) -> "Flight" : from . . data import opensky from . . data . adsb . raw_data import RawData if not isinstance ( self . icao24 , str ) : raise RuntimeError ( "Several icao24 for this flight" ) if not isinstance ( self . callsign , str ) : raise RuntimeError ( "Several callsigns for this flight" ) def fail_warning ( ) : """Called when nothing can be added to data.""" id_ = self . flight_id if id_ is None : id_ = self . callsign logging . warning ( f"No data on Impala for flight {id_}." ) return self def fail_silent ( ) : return self failure_dict = dict ( warning = fail_warning , silent = fail_silent ) failure = failure_dict [ failure_mode ] if data is None : ext = opensky . extended ( self . start , self . stop , icao24 = self . icao24 ) df = ext . data if ext is not None else None else : df = data if isinstance ( data , pd . DataFrame ) else data . data df = df . query ( "icao24 == @self.icao24 and " "@self.start < mintime < @self.stop" ) if df is None or df . shape [ 0 ] == 0 : return failure ( ) timestamped_df = df . sort_values ( "mintime" ) . assign ( timestamp = lambda df : df . mintime . dt . round ( "s" ) ) referenced_df = ( timestamped_df . merge ( self . data , on = "timestamp" , how = "outer" ) . sort_values ( "timestamp" ) . rename ( columns = dict ( altitude = "alt" , altitude_y = "alt" , groundspeed = "spd" , track = "trk" , ) ) [ [ "timestamp" , "latitude" , "longitude" , "alt" , "spd" , "trk" ] ] . ffill ( ) . drop_duplicates ( ) . merge ( timestamped_df [ [ "timestamp" , "icao24" , "rawmsg" ] ] , on = "timestamp" , how = "right" , ) ) identifier = ( self . flight_id if self . flight_id is not None else self . callsign ) t = RawData ( referenced_df ) . decode ( reference = self . origin if isinstance ( self . origin , str ) else None , progressbar = progressbar , progressbar_kw = dict ( leave = False , desc = f"{identifier}:" ) , ) extended = t [ self . icao24 ] if t is not None else None if extended is None : return failure ( ) if "last_position" in self . data . columns : extended = extended . assign ( last_position = pd . NaT ) if "start" in self . data . columns : extended = extended . assign ( start = pd . NaT ) if "stop" in self . data . columns : extended = extended . assign ( stop = pd . NaT ) aggregate = extended + self if "flight_id" in self . data . columns : aggregate . data . flight_id = self . flight_id flight = aggregate [ self . callsign ] if flight is None : return failure ( ) if self . number is not None : flight = flight . assign ( number = self . number ) if self . origin is not None : flight = flight . assign ( origin = self . origin ) if self . destination is not None : flight = flight . assign ( destination = self . destination ) return flight . sort_values ( "timestamp" )
Extends data with extra columns from EHS messages.
Extends data with extra columns from EHS messages .
"""Extends data with extra columns from EHS messages.

        By default, raw messages are requested from the OpenSky Network
        database.

        .. warning::
            Making a lot of small requests can be very inefficient and may look
            like a denial of service. If you get the raw messages using a
            different channel, you can provide the resulting dataframe as a
            parameter. See the page about `OpenSky Impala access
            <opensky_impala.html>`_

        The data parameter expect three columns: ``icao24``, ``rawmsg`` and
        ``mintime``, in conformance with the OpenSky API.

        .. note::
            Read more about access to the OpenSky Network database `here
            <opensky_impala.html>`_
        """ # noqa: F811 """Called when nothing can be added to data.""" # bugfix! NEVER ERASE THAT LINE! # fix for https://stackoverflow.com/q/53657210/1595335 # sometimes weird callsigns are decoded and should be discarded # so it seems better to filter on callsign rather than on icao24
self
data
Union[None, pd.DataFrame, "RawData"]
failure_mode
str
progressbar
Union[bool, Callable[[Iterable], Iterable]]