flight_processing.data.GraphBuilder¶
-
class
flight_processing.data.
GraphBuilder
(dataset, dataset_location=None)¶ Using already downloaded flight data and a dataframe of airspaces, construct a graph of airspace handovers.
Requires flights to have been downloaded ahead of time using FlightDownloader as well as a dataframe of airspaces.
Summary:
initialisation: __init__, from_dataframe
properties: gdf
processing: process_single_flight, process_flights, process_flights_bulk
visualisation: draw_map
-
__init__
(dataset, dataset_location=None)¶ Initialise the graph builder with a given dataset from file.
- Parameters
dataset (str or DataConfig) – dataset name or specification
dataset_location (pathlib.Path or str, optional) – location of saved dataframe
- Returns
object
- Return type
-
draw_map
(flight=None, subset=None, file_out=None)¶ Draw the dataframe of airspaces on a map, optionally plotting flights and highlighting a subset of airspaces.
Calls pyplot’s draw function so a diagram will be output directly. The result can also be saved to a file.
- Parameters
flight (traffic.core.flight.Flight or traffic.core.traffic.Traffic) – draw a flight or flights on the map
subset (set(int) or list(int) or set(str) or list(str)) – subset of airspaces to highlight (e.g. airspaces a flight passes through), as IDs or names
file_out (pathlib.Path or str, optional) – save the result to a file
-
classmethod
from_dataframe
(dataset, df)¶ Initialise the graph builder with a dataframe which is passed in.
The dataframe must have the following columns: - name - lower_limit - upper_limit
In addition, a DataFrame must have a wkt column containing the well-known text of the airspace’s geometry, and a GeoDataFrame must have a correctly formatted geometry column.
- Parameters
dataset (str or DataConfig) – dataset name or specification
df (pandas.core.frame.DataFrame or geopandas.geodataframe.GeoDataFrame) – dataframe of airspaces
- Returns
object
- Return type
-
property
gdf
¶ Returns the underlying geopandas GeoDataFrame.
- Returns
dataframe
- Return type
geopandas.geodataframe.GeoDataFrame
-
process_flights
(time, npz=True, json=False, yaml=False)¶ Process a file containing flights which have been saved to disk by FlightDownloader, saving the resulting graph to disk.
Graphs will be saved to {data_prefix}/graphs/{dataset}/{date}/{time}.json, where: - data_prefix is specified by the DataConfig object passed in on construction, or the data_location config value is used by default, - dataset is the name of the dataset as specified on construction, - date and time are determined by time_start.
- Parameters
time (datetime.datetime or str) – time of flights to process
npz (bool, optional) – save output as NPZ, default True
json (bool, optional) – save output as JSON, default False
yaml (bool, optional) – save output as YAML, default False
-
process_flights_bulk
(time_start, time_end, npz=True, json=False, yaml=False)¶ Process multiple files containing flights which have been saved to disk by FlightDownloader, saving the resulting graphs to disk.
- Parameters
time_start (datetime.datetime or str) – start time for processing
time_end (datetime.datetime or str) – end time for processing
npz (bool, optional) – save output as NPZ, default True
json (bool, optional) – save output as JSON, default False
yaml (bool, optional) – save output as YAML, default False
-
process_single_flight
(flight)¶ Process a single flight, returning an ordered list of airspace handovers.
- Parameters
flight (traffic.core.flight.Flight) – flight to process
- Returns
list of handovers as pairs of identifiers
- Return type
list(list(int))