traffic.algorithms.filters

traffic comes with some pre-implemented filters to be passed to the filter() method. The method takes either a FilterBase instance, or a string parameter:

  • "default" is a relatively fast option with decent performance on trajectories extracted from the OpenSky database (with their most common glitches)

  • "aggressive" is a composition of several filters which may result in smoother trajectories.

API reference

class traffic.algorithms.filters.ClusteringParams

Bases: TypedDict

class traffic.algorithms.filters.DerivativeParams

Bases: TypedDict

class traffic.algorithms.filters.EKFTaxiway

Bases: ProcessXYFilterBase

class traffic.algorithms.filters.Filter(*args, **kwargs)

Bases: Protocol

class traffic.algorithms.filters.FilterAboveSigmaMedian(**kwargs)

Bases: FilterBase

Filters noisy values above one sigma wrt median filter.

The method first applies a median filter on each feature of the DataFrame. A default kernel size is applied for a number of features (resp. latitude, longitude, altitude, track, groundspeed, IAS, TAS) but other kernel values may be passed as kwargs parameters.

Rather than returning averaged values, the method computes thresholds on sliding windows (as an average of squared differences) and replace unacceptable values with NaNs.

Then, a strategy may be applied to fill the NaN values, by default a forward/backward fill. Other strategies may be passed, for instance do nothing: None; or interpolate: lambda x: x.interpolate().

Note

This method if often more efficient when applied several times with different kernel values.Kernel values may be passed as integers, or list/tuples of integers for cascade of filters:

# this cascade of filters appears to work well on altitude
flight.filter(altitude=17).filter(altitude=53)

# this is equivalent to the default value
flight.filter(altitude=(17, 53))
cascaded_filters(df, feature, kernel_size, filt=None)

Produces a mask for data to be discarded.

The filtering applies a low pass filter (e.g medfilt) to a signal and measures the difference between the raw and the filtered signal.

The average of the squared differences is then produced (sq_eps) and used as a threshold for filtering.

Errors may raised if the kernel_size is too large

class traffic.algorithms.filters.FilterBase(*args, **kwargs)

Bases: Filter

class traffic.algorithms.filters.FilterClustering(time_column='timestamp', **kwargs)

Bases: FilterBase

Filter based on clustering.

The method creates clusters of datapoints based on the difference in time and parameter value. If the cluster is larger than the defined group size the datapoints are kept, otherwise they are removed.

class traffic.algorithms.filters.FilterDerivative(time_column='timestamp', **kwargs)

Bases: FilterBase

Filter based on the 1st and 2nd derivatives of parameters

The method computes the absolute value of the 1st and 2nd derivatives of the parameters. If the value of the derivatives is above the defined threshold values, the datapoint is removed

class traffic.algorithms.filters.FilterMean(**kwargs)

Bases: FilterBase

Rolling mean filter.

class traffic.algorithms.filters.FilterMedian(**kwargs)

Bases: FilterBase

Rolling median filter

class traffic.algorithms.filters.KalmanFilter6D(reject_sigma=3)

Bases: ProcessXYZFilterBase

class traffic.algorithms.filters.KalmanSmoother6D(reject_sigma=3)

Bases: ProcessXYZFilterBase

class traffic.algorithms.filters.KalmanTaxiway

Bases: ProcessXYFilterBase

class traffic.algorithms.filters.ProcessXYFilterBase(*args, **kwargs)

Bases: FilterBase

class traffic.algorithms.filters.ProcessXYZFilterBase(*args, **kwargs)

Bases: FilterBase

class traffic.algorithms.filters.TrackVariable

Bases: Generic[V]