This code derives flights from OpenSky Network state vectors (state_vectors_data4). For one UTC day it finds the flight legs of every aircraft and estimates their departure and arrival airports. It writes them in the schema of the flights_data4 table; for querying that table, see the Trino documentation.
The airport step uses the airport network of PlaneQuery/planequery-data. The approach follows J. Goode, Evaluating and Improving Flight Derivation from ADS-B Data, 14th OpenSky Symposium (pre-print).
| Module | What it does |
|---|---|
job.py |
One day, end to end: prep → legs → airports → write. |
prep.py |
Reads the day's state vectors (local or S3), applies the input filter and splits them by aircraft into hash buckets. |
legs.py |
Flight legs per bucket, plus the callsign, receivers and compressed track of each flight. |
airports.py |
Departure and arrival airport for each end of each flight. |
nn/ |
The PlaneQuery airport network: code and weights, vendored (see NOTICE). |
resources.py |
Sizes worker processes and thread pools to the CPU and memory limits. |
Each run reads one UTC day D of state vectors. It also reads day D-1 for the aircraft in the previous run's carry-over list. Per aircraft:
- Input filter. Keep states with a barometric altitude and a position update, where the position is less than 1 s old.
- Sparse filter. Drop 30-second slots that hold fewer than 4 states.
- Outlier filter. Drop states that are more than 50 m in altitude, or more than 0.5° in latitude or longitude, from the centred running median of 7 states.
- New flight after a long gap. A gap of more than 10 minutes starts a new flight, if the speed across the gap is below a quarter of the aircraft's median speed of the day. That median is taken over the speeds between consecutive states.
- New flight after a low-altitude gap. A gap of 4 to 10 minutes starts a new flight if the aircraft was within 5 km of the same airport, heliport or seaplane base and less than 300 m above it, both before and after the gap.
- End of flight. A flight ends at the last state before a new flight. It also ends at the aircraft's last state of the day, if that state is more than 10 minutes before midnight and below 2,500 m. Otherwise the flight is still in the air and goes into the carry-over list for D+1.
- Minimum duration. Flights with both ends observed and lasting 10 minutes or less are dropped.
Other columns:
callsign: the most frequent callsign of the flight.serials: all receivers that contributed.track: a compressed trajectory.
For each end of a flight, the first rule below that applies decides the airport.
- Positions used. The departure uses the first position of the flight and the arrival uses the last one. Altitudes are barometric.
- Fixed-wing aircraft are matched only to OurAirports types small, medium and large airport.
- Helicopters are also matched to heliports and seaplane bases. The helicopter flag comes from the OpenSky aircraft database.
| Rule | Condition | Airport |
|---|---|---|
| observed | within 2 km of an airport, and either on the ground or less than 300 m above it | that airport |
| helicopter | a helicopter with a field within 10 km | the nearest airport, heliport or seaplane base |
| cruise | above 6,000 m: coverage started or ended en route | none |
| inferred | otherwise | the airport ranked first by the PlaneQuery network, among fixed-wing airports within 200 km |
| none | no position at that end, no network candidate, or (departure only) no firstSeen |
none |
The network ranks candidate airports from the positions in the first or last 10 minutes of the flight.
Airport codes are the OurAirports ident: the ICAO code where one exists, otherwise a local or OurAirports code.
An optional live mode (--live --routes) fills ends that have no usable answer from callsign flight routes. It needs a routes file, which is not part of this repository.
- Flights:
<out>/day=<day of lastSeen>/run-<YYYYMMDD>.parquet, in theflights_data4schema. One run writes day D and a small part of day D-1.- Horizontal and vertical distances are in metres, from the first or last position to the chosen airport, and are null when there is no airport.
- The candidate counts are 0 and the candidate lists are empty.
airportOfDeparture,airportOfDestinationandtakeoffLandingInfoare null.
- Carry-over list:
<ongoing-out>/<epoch of D+1 00:00>/part-0.parquet, with columns_1(icao24) and_2(firstSeen). It is the next run's--ongoing-in.
Python ≥ 3.14, CPU only.
pip install -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu
PYTHONPATH=src python -m opensky_batch_flights.job --day 2026-07-01 \
--states-root s3://<bucket>/state_vectors_data4 \
--ongoing-in <carry-over root>/<epoch of D 00:00> \
--ourairports https://davidmegginson.github.io/ourairports-data/airports.csv \
--acdb <OpenSky aircraft database CSV> \
--work /scratch/flights \
--out <flights root> \
--ongoing-out <carry-over root>
| Option | Notes |
|---|---|
--states-root |
state_vectors_data4 with hour=<epoch> partitions, local or s3://. S3 credentials come from the AWS credential chain. For an S3-compatible store set S3_ENDPOINT=host:port (S3_USE_SSL=false for http) and AWS_ENDPOINT_URL. For a private CA set S3_CA_CERT and SSL_CERT_FILE. |
--ongoing-in |
The previous run's carry-over list (_1/_2 or icao24/firstSeen). Optional. |
--ourairports |
OurAirports airports.csv, as a path or URL. |
--acdb |
OpenSky aircraft database CSV, as a path or URL. Only icaoaircrafttype is used. |
--work |
Local scratch directory, about 20 GB per day. |
--workers |
Worker processes. The default is the CPU limit, capped by the memory limit. |
One day takes about 15–25 minutes on 12 cores, with a peak memory of 25–30 GB.
The settings are constants at the top of their module.
| Setting | Module | Value |
|---|---|---|
LOWGAP |
legs.py |
240 s, 300 m, 5 km |
MIN_DURATION_S |
legs.py |
600 s |
OBS_KM, OBS_AGL_M |
airports.py |
2 km, 300 m |
CRUISE_M |
airports.py |
6,000 m |
HELI_KM |
airports.py |
10 km |
- Code: Marc Liechti and the OpenSky Network.
- Airport network and approach: Jonah Goode (PlaneQuery; pre-print).
- Airport data: OurAirports.
GPL-3.0, see LICENSE. The exception is the vendored PlaneQuery files in src/opensky_batch_flights/nn/ (features.py, model.py, airport_nn_model.pt), which keep their author's terms; see their NOTICE.