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.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.FilterMean(**kwargs)

Bases: FilterBase

Rolling mean filter.

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

Bases: FilterBase

Rolling median filter