traffic.core.mixins

class traffic.core.mixins.DataFrameMixin(data, *args, **kwargs)

Bases: object

DataFrameMixin aggregates a pandas DataFrame and provides the same representation methods.

assign(*args, **kwargs)

Applies the Pandas assign() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

convert_dtypes(*args, **kwargs)

Applies the Pandas convert_dtypes() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

drop(*args, **kwargs)

Applies the Pandas drop() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

drop_duplicates(*args, **kwargs)

Applies the Pandas drop_duplicates() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

fillna(*args, **kwargs)

Applies the Pandas fillna() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

classmethod from_file(filename, **kwargs)

Read data from various formats.

This class method dispatches the loading of data in various format to the proper pandas.read_* method based on the extension of the filename. Potential compression of the file is inferred by pandas itself based on the extension. :rtype: Optional[TypeVar(T, bound= DataFrameMixin)]

Other extensions return None. Specific arguments may be passed to the underlying pandas.read_* method with the kwargs argument.

Example usage:

>>> from traffic.core import Traffic
>>> t = Traffic.from_file(filename)
groupby(*args, **kwargs)

Applies the Pandas groupby() method to the underlying pandas DataFrame.

Return type:

DataFrameGroupBy

merge(*args, **kwargs)

Applies the Pandas merge() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

query(query_str, *args, **kwargs)

Applies the Pandas query() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

Optional[TypeVar(T, bound= DataFrameMixin)]

rename(*args, **kwargs)

Applies the Pandas rename() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

replace(*args, **kwargs)

Applies the Pandas replace() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

reset_index(*args, **kwargs)

Applies the Pandas reset_index() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

sort_values(by, **kwargs)

Applies the Pandas sort_values() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

to_csv(filename, *args, **kwargs)

Exports to CSV format.

Options can be passed to pandas.DataFrame.to_csv() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

to_excel(filename, *args, **kwargs)

Exports to Excel format.

Options can be passed to pandas.DataFrame.to_excel() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

to_feather(filename, *args, **kwargs)

Exports to feather format.

Options can be passed to pandas.DataFrame.to_feather() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

to_hdf(filename, *args, **kwargs)

Exports to HDF format.

Options can be passed to pandas.DataFrame.to_hdf() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

to_json(filename, *args, **kwargs)

Exports to JSON format.

Options can be passed to pandas.DataFrame.to_json() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

to_parquet(filename, *args, **kwargs)

Exports to parquet format.

Options can be passed to pandas.DataFrame.to_parquet() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

to_pickle(filename, *args, **kwargs)

Exports to pickle format.

Options can be passed to pandas.DataFrame.to_pickle() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

class traffic.core.mixins.GeoDBMixin(data, *args, **kwargs)

Bases: DataFrameMixin

assign(*args, **kwargs)

Applies the Pandas assign() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

convert_dtypes(*args, **kwargs)

Applies the Pandas convert_dtypes() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

drop(*args, **kwargs)

Applies the Pandas drop() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

drop_duplicates(*args, **kwargs)

Applies the Pandas drop_duplicates() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

extent(extent, buffer=0.5)

Selects the subset of data inside the given extent.

Parameters:
  • extent (str | ShapelyMixin | tuple[float, float, float, float]) –

    The parameter extent may be passed as:

    • a string to query OSM Nominatim service;

    • the result of an OSM Nominatim query (ShapelyMixin);

    • any kind of shape (ShapelyMixin, including Airspace);

    • extent in the order: (west, east, south, north)

  • buffer (float) – As the extent of a given shape may be a little too strict to catch elements we may expect when we look into an area, the buffer parameter (by default, 0.5 degree) helps enlarging the area of interest.

Return type:

Optional[TypeVar(G, bound= GeoDBMixin)]

This works with databases like Airways, Airports or Navaids.

>>> from traffic.data import airways
>>> airways.extent(eurofirs['LFBB'])  
  route    id   navaid   latitude    longitude
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  A25      6    GODAN    47.64       -1.96
  A25      7    TMA28    47.61       -1.935
  A25      8    NTS      47.16       -1.613
  A25      9    TIRAV    46.6        -1.391
  A25      10   LUSON    46.5        -1.351
  A25      11   OLERO    45.97       -1.15
  A25      12   MAREN    45.73       -1.062
  A25      13   ROYAN    45.67       -1.037
  A25      14   BMC      44.83       -0.7211
  A25      15   SAU      44.68       -0.1529
 ... (703 more lines)
>>> from traffic.data import airports
>>> airports.extent("Bornholm")  
 name                 country   icao      iata   latitude   longitude
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 Bodilsker Airstrip   Denmark   DK-0027   nan    55.06      15.05
 Bornholm Airport     Denmark   EKRN      RNN    55.06      14.76
 Ro Airport           Denmark   EKRR      nan    55.21      14.88
>>> from traffic.data import navaids
>>> navaids['ZUE']
Navaid('ZUE', type='NDB', latitude=30.9, longitude=20.06833333, altitude=0.0, description='ZUEITINA NDB', frequency='369.0kHz')
>>> navaids.extent('Switzerland')['ZUE']
Navaid('ZUE', type='VOR', latitude=47.59216667, longitude=8.81766667, altitude=1730.0, description='ZURICH EAST VOR-DME', frequency='110.05MHz')
fillna(*args, **kwargs)

Applies the Pandas fillna() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

classmethod from_file(filename, **kwargs)

Read data from various formats.

This class method dispatches the loading of data in various format to the proper pandas.read_* method based on the extension of the filename. Potential compression of the file is inferred by pandas itself based on the extension. :rtype: Optional[TypeVar(T, bound= DataFrameMixin)]

Other extensions return None. Specific arguments may be passed to the underlying pandas.read_* method with the kwargs argument.

Example usage:

>>> from traffic.core import Traffic
>>> t = Traffic.from_file(filename)
geoencode(**kwargs)

Returns an altair encoding of the shape to be composed in an interactive visualization.

Return type:

Chart

groupby(*args, **kwargs)

Applies the Pandas groupby() method to the underlying pandas DataFrame.

Return type:

DataFrameGroupBy

merge(*args, **kwargs)

Applies the Pandas merge() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

query(query_str, *args, **kwargs)

Applies the Pandas query() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

Optional[TypeVar(T, bound= DataFrameMixin)]

rename(*args, **kwargs)

Applies the Pandas rename() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

replace(*args, **kwargs)

Applies the Pandas replace() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

reset_index(*args, **kwargs)

Applies the Pandas reset_index() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

sort_values(by, **kwargs)

Applies the Pandas sort_values() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

to_csv(filename, *args, **kwargs)

Exports to CSV format.

Options can be passed to pandas.DataFrame.to_csv() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

to_excel(filename, *args, **kwargs)

Exports to Excel format.

Options can be passed to pandas.DataFrame.to_excel() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

to_feather(filename, *args, **kwargs)

Exports to feather format.

Options can be passed to pandas.DataFrame.to_feather() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

to_hdf(filename, *args, **kwargs)

Exports to HDF format.

Options can be passed to pandas.DataFrame.to_hdf() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

to_json(filename, *args, **kwargs)

Exports to JSON format.

Options can be passed to pandas.DataFrame.to_json() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

to_parquet(filename, *args, **kwargs)

Exports to parquet format.

Options can be passed to pandas.DataFrame.to_parquet() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

to_pickle(filename, *args, **kwargs)

Exports to pickle format.

Options can be passed to pandas.DataFrame.to_pickle() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

class traffic.core.mixins.GeographyMixin(data, *args, **kwargs)

Bases: DataFrameMixin

Adds Euclidean coordinates to a latitude/longitude DataFrame.

agg_xy(resolution, projection=None, **kwargs)

Aggregates values of a traffic over a grid of x/y, with x and y computed by compute_xy().

Parameters:
  • resolution (None | dict[str, float]) – The resolution of the grid is passed as a dictionary parameter. By default, the grid is made by rounding x and y to the lower ten kilometer values. dict(x=5000, y=3000) will take 1 value per 5000 meters for x (10000, 15000, 20000, …) and 1 value per 3000 meters for y (9000, 12000, 15000, 18000, 20000, …).

  • projection (None | pyproj.Proj | ‘crs.Projection) – is used to compute the x and y values.

The kwargs specifies how to aggregate values:

  • altitude="mean" would average all values in the given cell;

  • timestamp="count" would return the number of samples per cell;

  • icao24="nunique" would return the number of different aircraft int the given cell.

Return type:

pd.DataFrame

Returns:

a DataFrame indexed over x and y values. It is conveniently chainable with the .to_xarray() method in order to plot density heatmaps.

Example usage:

belevingsvlucht.agg_xy(
    resolution=dict(x=3e3, y=3e3),
    vertical_rate="mean",
    timestamp="count"
)
assign(*args, **kwargs)

Applies the Pandas assign() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

compute_latlon_from_xy(projection)

Enrich a DataFrame with new longitude and latitude columns computed from x and y columns. :rtype: TypeVar(T, bound= DataFrameMixin)

Warning

Make sure to use as source projection the one used to compute 'x' and 'y' columns in the first place.

compute_xy(projection=None)

Enrich the structure with new x and y columns computed through a projection of the latitude and longitude columns.

The source projection is WGS84 (EPSG 4326). The default destination projection is a Lambert Conformal Conical projection centred on the data inside the dataframe.

Other valid projections are available: :rtype: T

  • as pyproj.Proj objects;

  • as cartopy.crs.Projection objects.

convert_dtypes(*args, **kwargs)

Applies the Pandas convert_dtypes() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

drop(*args, **kwargs)

Applies the Pandas drop() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

drop_duplicates(*args, **kwargs)

Applies the Pandas drop_duplicates() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

fillna(*args, **kwargs)

Applies the Pandas fillna() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

classmethod from_file(filename, **kwargs)

Read data from various formats.

This class method dispatches the loading of data in various format to the proper pandas.read_* method based on the extension of the filename. Potential compression of the file is inferred by pandas itself based on the extension. :rtype: Optional[TypeVar(T, bound= DataFrameMixin)]

Other extensions return None. Specific arguments may be passed to the underlying pandas.read_* method with the kwargs argument.

Example usage:

>>> from traffic.core import Traffic
>>> t = Traffic.from_file(filename)
geoencode(**kwargs)

Returns an altair encoding of the shape to be composed in an interactive visualization. Specific plot features, such as line widths, can be passed with the kwargs argument. See documentation.

Return type:

Chart

groupby(*args, **kwargs)

Applies the Pandas groupby() method to the underlying pandas DataFrame.

Return type:

DataFrameGroupBy

merge(*args, **kwargs)

Applies the Pandas merge() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

query(query_str, *args, **kwargs)

Applies the Pandas query() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

Optional[TypeVar(T, bound= DataFrameMixin)]

rename(*args, **kwargs)

Applies the Pandas rename() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

replace(*args, **kwargs)

Applies the Pandas replace() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

reset_index(*args, **kwargs)

Applies the Pandas reset_index() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

sort_values(by, **kwargs)

Applies the Pandas sort_values() method to the underlying pandas DataFrame and get the result back in the same structure.

Return type:

TypeVar(T, bound= DataFrameMixin)

to_csv(filename, *args, **kwargs)

Exports to CSV format.

Options can be passed to pandas.DataFrame.to_csv() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

to_excel(filename, *args, **kwargs)

Exports to Excel format.

Options can be passed to pandas.DataFrame.to_excel() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

to_feather(filename, *args, **kwargs)

Exports to feather format.

Options can be passed to pandas.DataFrame.to_feather() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

to_hdf(filename, *args, **kwargs)

Exports to HDF format.

Options can be passed to pandas.DataFrame.to_hdf() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

to_json(filename, *args, **kwargs)

Exports to JSON format.

Options can be passed to pandas.DataFrame.to_json() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

to_parquet(filename, *args, **kwargs)

Exports to parquet format.

Options can be passed to pandas.DataFrame.to_parquet() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

to_pickle(filename, *args, **kwargs)

Exports to pickle format.

Options can be passed to pandas.DataFrame.to_pickle() as args and kwargs arguments.

Read more: How to export and store trajectory and airspace data?

Return type:

None

class traffic.core.mixins.HBoxMixin

Bases: object

Enables a | operator for placing representations next to each other.

class traffic.core.mixins.LatLonDict

Bases: TypedDict

clear() None.  Remove all items from D.
copy() a shallow copy of D
fromkeys(value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
pop(k[, d]) v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() an object providing a view on D's values
class traffic.core.mixins.ShapelyMixin

Bases: object

ShapelyMixin expects a shape attribute as a Geometry and provides methods consistent with GIS geometries.

However no plot method is provided at this level because it depends on the nature of the shape.

property area: float

Returns the area of the shape, in square meters. The shape is projected to an equivalent local projection before computing a value.

property bounds: tuple[float, float, float, float]

Returns the bounds of the (bounding box of the) shape. Bounds are given in the following order in the origin crs: (west, south, east, north)

property centroid: Point

Returns the centroid of the shape as a shapely Point.

property extent: tuple[float, float, float, float]

Returns the extent of the (bounding box of the) shape.

Note

When plotting with Matplotlib and Cartopy, the extent property is convenient in the following use case:

>>> ax.set_extent(obj.extent)
Returns:

Extent is given in the following order in the origin crs: (west, east, south, north)

geoencode(**kwargs)

Returns an altair encoding of the shape to be composed in an interactive visualization. Specific plot features, such as line widths, can be passed with the kwargs argument. See documentation.

Return type:

LayerChart | Chart

geojson()

Returns the GeoJSON representation of the shape as a Dict. The transformation is delegated to shapely mapping method.

Return type:

dict[str, Any] | list[dict[str, Any]]

project_shape(projection=None)

Returns a projected representation of the shape.

Parameters:

projection (None | pyproj.Proj | ‘crs.Projection) – By default (None), an equivalent projection is applied. Equivalent projections locally respect areas, which is convenient for the area attribute.

Return type:

base.BaseGeometry