traffic/core/flight.py
def resample(self, rule: Union[str, int] = "1s") -> "Flight":
        """Resample the trajectory at a given frequency or number of points.

        If the rule is a string representing a pandas `time series frequency
        <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#timeseries-offset-aliases>`_
        is passed, then the data is resampled along the timestamp axis, then
        interpolated.

        If the rule is an integer, the trajectory is resampled to the given
        number of evenly distributed points per trajectory.
        """

        if isinstance(rule, str):
            data = (
                self.handle_last_position()
                .unwrap()  # avoid filled gaps in track and heading
                .assign(start=self.start, stop=self.stop)
                .data.set_index("timestamp")
                .resample(rule)
                .first()  # better performance than min() for duplicate index
                .interpolate()
                .reset_index()
                .fillna(method="pad")
            )
        elif isinstance(rule, int):
            # ./site-packages/pandas/core/indexes/base.py:2820: FutureWarning:
            # Converting timezone-aware DatetimeArray to timezone-naive ndarray
            # with 'datetime64[ns]' dtype. In the future, this will return an
            # ndarray with 'object' dtype where each element is a
            # 'pandas.Timestamp' with the correct 'tz'.
            # To accept the future behavior, pass 'dtype=object'.
            # To keep the old behavior, pass 'dtype="datetime64[ns]"'.
            data = (
                self.handle_last_position()
                .unwrap()  # avoid filled gaps in track and heading
                .assign(tz_naive=lambda d: d.timestamp.astype("datetime64[ns]"))
                .data.set_index("tz_naive")
                .asfreq((self.stop - self.start) / (rule - 1), method="nearest")
                .reset_index()
                .drop(columns="tz_naive")
            )
        else:
            raise TypeError("rule must be a str or an int")

        if "track_unwrapped" in data.columns:
            data = data.assign(track=lambda df: df.track_unwrapped % 360)
        if "heading_unwrapped" in data.columns:
            data = data.assign(heading=lambda df: df.heading_unwrapped % 360)

        return self.__class__(data)
Resample the trajectory at a given frequency or number of points.

        If the rule is a string representing a pandas `time series frequency
        <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#timeseries-offset-aliases>`_
        is passed, then the data is resampled along the timestamp axis, then
        interpolated.

        If the rule is an integer, the trajectory is resampled to the given
        number of evenly distributed points per trajectory.
        
Resample the trajectory at a given frequency or number of points.
If the rule is a string representing a pandas `time series frequency
`_
is passed, then the data is resampled along the timestamp axis, then
interpolated.

If the rule is an integer, the trajectory is resampled to the given
number of evenly distributed points per trajectory.
Resample the trajectory at a given frequency or number of points . If the rule is a string representing a pandas ` time series frequency ` _ is passed then the data is resampled along the timestamp axis then interpolated . If the rule is an integer the trajectory is resampled to the given number of evenly distributed points per trajectory .
def resample(self, rule: Union[str, int] = "1s") -> "Flight":
        if isinstance(rule, str):
            data = (
                self.handle_last_position()
                .unwrap()  
                .assign(start=self.start, stop=self.stop)
                .data.set_index("timestamp")
                .resample(rule)
                .first()  
                .interpolate()
                .reset_index()
                .fillna(method="pad")
            )
        elif isinstance(rule, int):
            data = (
                self.handle_last_position()
                .unwrap()  
                .assign(tz_naive=lambda d: d.timestamp.astype("datetime64[ns]"))
                .data.set_index("tz_naive")
                .asfreq((self.stop - self.start) / (rule - 1), method="nearest")
                .reset_index()
                .drop(columns="tz_naive")
            )
        else:
            raise TypeError("rule must be a str or an int")
        if "track_unwrapped" in data.columns:
            data = data.assign(track=lambda df: df.track_unwrapped % 360)
        if "heading_unwrapped" in data.columns:
            data = data.assign(heading=lambda df: df.heading_unwrapped % 360)
        return self.__class__(data)
def resample ( self , rule : Union [ str , int ] = "1s" ) -> "Flight" : if isinstance ( rule , str ) : data = ( self . handle_last_position ( ) . unwrap ( ) . assign ( start = self . start , stop = self . stop ) . data . set_index ( "timestamp" ) . resample ( rule ) . first ( ) . interpolate ( ) . reset_index ( ) . fillna ( method = "pad" ) ) elif isinstance ( rule , int ) : data = ( self . handle_last_position ( ) . unwrap ( ) . assign ( tz_naive = lambda d : d . timestamp . astype ( "datetime64[ns]" ) ) . data . set_index ( "tz_naive" ) . asfreq ( ( self . stop - self . start ) / ( rule - 1 ) , method = "nearest" ) . reset_index ( ) . drop ( columns = "tz_naive" ) ) else : raise TypeError ( "rule must be a str or an int" ) if "track_unwrapped" in data . columns : data = data . assign ( track = lambda df : df . track_unwrapped % 360 ) if "heading_unwrapped" in data . columns : data = data . assign ( heading = lambda df : df . heading_unwrapped % 360 ) return self . __class__ ( data )
Resample the trajectory at a given frequency or number of points.
Resample the trajectory at a given frequency or number of points .
"""Resample the trajectory at a given frequency or number of points.

        If the rule is a string representing a pandas `time series frequency
        <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#timeseries-offset-aliases>`_
        is passed, then the data is resampled along the timestamp axis, then
        interpolated.

        If the rule is an integer, the trajectory is resampled to the given
        number of evenly distributed points per trajectory.
        """ # avoid filled gaps in track and heading # better performance than min() for duplicate index # ./site-packages/pandas/core/indexes/base.py:2820: FutureWarning: # Converting timezone-aware DatetimeArray to timezone-naive ndarray # with 'datetime64[ns]' dtype. In the future, this will return an # ndarray with 'object' dtype where each element is a # 'pandas.Timestamp' with the correct 'tz'. # To accept the future behavior, pass 'dtype=object'. # To keep the old behavior, pass 'dtype="datetime64[ns]"'. # avoid filled gaps in track and heading
self
rule
Union[str, int]