flight_processing.data.AirspaceGraph

class flight_processing.data.AirspaceGraph(dataset, df=None, dataset_location=None)

Having constructed a graph of handovers from processing downloaded flights, load the graph and perform data processing on it.

Requires a dataframe of airspaces as well as flights to have been processed using GraphBuilder - they must first be saved using FlightDownloader.

Summary:

__init__(dataset, df=None, dataset_location=None)

Initialise the graph builder with a given dataset, either from a file or directly from a dataframe.

By default the dataframe will be loaded from a file as specified in the config.

A loaded 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, optional) – dataframe of airspaces

  • dataset_location (pathlib.Path or str, optional) – location of saved dataframe

Returns

object

Return type

AirspaceGraph

airspace_distance(long, lat, height, airspace)

Returns the distance from the given point to the given airspace in feet.

Parameters
  • long (float) – longitude of point

  • lat (float) – latitude of point

  • height (float) – height in ft

  • airspace (str or int) – airspace name or identifier

Returns

distance to airspace in feet

Return type

float

average_edge_weight(median=False)

Get the average edge weight across the whole graph.

Parameters

median (bool, optional) – return median weight instead of mean, default False

Returns

average edge weight

Return type

float

confidence(edge, distance1=None, distance2=None)

Given a graph edge and (optional) distance to an airspace, return information on the confidence about that handover.

Parameters
  • edge (dict) – edge from handover graph

  • distance1 (float, optional) – distance to first airspace

  • distance2 (float, optional) – distance to second airspace

Returns

information about handover confidence

Return type

dict

draw_graph_map(flight=None, subset=None, logscale=False, file_out=None)

Draw the dataframe of airspaces on a map with the graph of handovers overlaid on top, 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

  • logscale (bool) – edges are coloured according to a logarithmic (rather than linear) scale, default False

  • file_out (pathlib.Path or str, optional) – save the result to a file

edge_weight(airspace1, airspace2)

Get the weight of the edge between the given airspaces on the graph.

Parameters
  • airspace1 (str or int) – first airspace name or identifier

  • airspace2 (str or int) – second airspace name or identifier

Returns

edge weight

Return type

float

property gdf

Returns the underlying geopandas GeoDataFrame.

Returns

dataframe

Return type

geopandas.geodataframe.GeoDataFrame

get_airspace(airspace)

Returns the row corresponding to the given airspace name or identifier.

Parameters

airspace (str or int) – airspace name or identifier

Returns

airspace data

Return type

pandas.core.series.Series

property graph

Returns the underlying graph of airspace handovers.

Returns

graph

Return type

networkx.classes.digraph.DiGraph

load_graph_files(files)

Load the graph of handovers from a given list of NPZ file locations.

Parameters

files (list(pathlib.Path) or list(str) or pathlib.Path or str) – file or files to load

load_graphs(time_start, time_end)

Load the graph of handovers from a series of NPZ files within a given time range.

Graphs will be loaded from {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 the timestamp.

Parameters
  • time_start (datetime.datetime or str) – start time

  • time_end (datetime.datetime or str) – end time

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))

set_confidence_values(distance_zero=None, distance_one=None, minimum_weight=None, minimum_weight_adjusted=None, confidence_distance=None, confidence_distance_modifier=None, confidence_weight=None, confidence_weight_adjusted=None)

Sets the confidence values used in confidence, test_point, test_handover, and test_flight.

These values are set to the following by default: - distance_zero = 5000 - distance_one = 3000 - minimum_weight = 50 - minimum_weight_adjusted = 0.05 - confidence_distance = 1.0 - confidence_distance_modifier = 0.8 - confidence_weight = 1.0 - confidence_weight_adjusted = 1.0

These values should be modified according to data extracted from handovers and from the specific graph used.

distance_zero and distance_one do not depend on the graph, but minimum_weight and minimum_weight_adjusted should be modified to fit the graph since they are based on its weights.

It must hold that distance_zero >= distance_one.

Parameters
  • distance_zero (float) – distance from airspace border above which confidence is not increased

  • distance_one (float) – distance from airspace border below which confidence is increased by confidence_distance

  • minimum_weight (float) – minimum graph edge weight before confidence value is increased

  • minimum_weight_adjusted – minimum “adjusted” graph edge weight before confidence value is increased - adjusted weight is the edge weight divided by the total weight of all edges leaving that node

  • confidence_distance (float) – if distance is sufficiently low, how much to increase confidence by

  • confidence_distance_modifier (float) – if aircraft is not in either airspace, multiply distance-based confidence by this value (should be <=1.0)

  • confidence_weight (float) – if edge weight is sufficiently high, how much to increase confidence by

  • confidence_weight_adjusted (float) – if “adjusted” edge weight is sufficiently high, how much to increase confidence by

test_flight(flight)

Test a given flight, returning each of the handovers that could have occurred during the flight and information about that handover’s confidence.

Parameters

flight (traffic.core.flight.Flight) – flight to test

Returns

information about handovers

Return type

list(dict)

test_handover(long, lat, height, airspace1, airspace2)

Test a handover at a given point, returning a dictionary containing information about that handover (including confidence).

Parameters
  • long (float) – longitude of point

  • lat (float) – latitude of point

  • height (float) – height in ft

  • airspace1 (str or int) – first airspace name or identifier

  • airspace2 (str or int) – second airspace name or identifier

Returns

information about handover

Return type

dict

test_point(long, lat, height)

Test a point, returning a list of potential handovers which could occur at that point and their confidence.

For each airspace which contains the given point we return a number of airspaces near that point, along with the confidence value of that (potential) handover. This takes the form of a list of dictionaries.

Parameters
  • long (float) – longitude of point

  • lat (float) – latitude of point

  • height (float) – height in ft

Returns

information about handovers

Return type

list(dict)

visualise_graph()

Visualise the graph interactively using HoloViews.

zone_centre(name)

Get the centre of the given airspace.

Parameters

name (str or int) – airspace name or identifier

Returns

coordinates of the airspace centre

Return type

shapely.geometry.point.Point