traffic.core.iterate

class traffic.core.FlightIterator(generator)

Bases: object

A FlightIterator is a specific structure providing helpers after methods applied on a Flight that return a sequence of pieces of trajectories.

Methods returning a FlightIterator include:

  • Flight.split("10 min") iterates over pieces of trajectories separated by more than 10 minutes without data;

  • Flight.go_around("LFBO") iterates over landing attempts on a given airport;

  • Flight.aligned_on_ils("LFBO") iterates over segments of trajectories aligned with any of the runways at LFBO.

  • and more.

Since a FlightIterator is not a Flight, you can:

  • iterate on it with a for loop, or with Python built-ins functions;

  • index it with bracket notation (using positive integers or slices);

  • get True if the sequence is non empty with .has();

  • get the first element in the sequence with .next();

  • count the element in the sequence with .sum();

  • concatenate all elements in the sequence with .all();

  • get the biggest/shortest element with .max()/.min(). By default, comparison is made on duration.

Warning

FlightIterator instances consume themselves out.

If you store a FlightIterator in a variable, calling methods twice in a row will yield different results. In Jupyter environments, representing the FlightIterator will consume it too.

To avoid issues, the best practice is to not store any FlightIterator in a variable.

all(flight_id=None)

Returns the concatenation of elements in the FlightIterator.

Return type:

Optional[Flight]

>>> flight.aligned_on_ils("LFBO").all()

This is equivalent to:

>>> flight.all(lambda f: f.aligned_on_ils("LFBO"))
>>> flight.all('aligned_on_ils("LFBO")')
final()

Returns the final (last) element in the FlightIterator.

Example usage:

Return type:

Optional[Flight]

>>> first_attempt = flight.runway_change().final()

This is equivalent to:

>>> flight.final("runway_change")
has()

Returns True if the FlightIterator is not empty.

Example usage:

Return type:

bool

>>> flight.emergency().has()
True

This is equivalent to:

>>> flight.has("emergency")
map(fun)

Applies a function on each segment of an Iterator.

For instance:

Return type:

FlightIterator

>>> flight.split("10min").map(lambda f: f.resample("2s")).all()
max(key='duration')

Returns the biggest element in the Iterator.

By default, comparison is based on duration.

Return type:

Optional[Flight]

>>> flight.query("altitude < 5000").split().max()

but it can be set on start time as well (the last event to start)

>>> flight.query("altitude < 5000").split().max(key="start")
min(key='duration')

Returns the shortest element in the Iterator.

By default, comparison is based on duration.

Return type:

Optional[Flight]

>>> flight.query("altitude < 5000").split().min()

but it can be set on ending time as well (the first event to stop)

>>> flight.query("altitude < 5000").split().min(key="stop")
next()

Returns the first/next element in the FlightIterator.

Example usage:

Return type:

Optional[Flight]

>>> first_attempt = flight.runway_change().next()

This is equivalent to:

>>> flight.next("runway_change")
plot(*args, **kwargs)

Plots all elements in the structure.

Arguments as passed as is to the Flight.plot() method.

Return type:

None

sum()

Returns the size of the FlightIterator.

Example usage:

Return type:

int

>>> flight.go_around().sum()
1

This is equivalent to:

>>> flight.sum("go_around")