Skip to content

Python tool for aircraft Doppler audio geolocation using historical ADS-B flight data (Source-available)

Reject ambiguous legacy selection metadata

Cinna Davis0e4d2b304fd2
diff --git a/docs/HISTORICAL_INGESTION.md b/docs/HISTORICAL_INGESTION.md
index adf67cd..f04f28c 100644
--- a/docs/HISTORICAL_INGESTION.md
+++ b/docs/HISTORICAL_INGESTION.md
@@ -9,11 +9,13 @@ that cross a query between recorded samples. The conservative continuous bounds
and 30-second gap limit match the default `FlightIndex` build; a differently
configured gap limit requires a new selection. The report records that limit.
New Parquet files also embed the selection box, time interval intersected with
-the archive's named UTC day, aircraft-type scope and gap limit. An interval with
+the archive's named UTC day, the day itself, aircraft-type scope and gap limit. An interval with
no overlap has empty declared coverage, even if the source contains neighboring
observations. `FlightIndex.from_parquet` rejects coverage claims beyond those
limits or an index gap that differs from the selection gap. Older or generic
Parquet files without this metadata still rely on the caller's coverage evidence.
+Briefly emitted v1 selection metadata did not bind a source day; those tagged
+files are rejected and must be reingested before indexing.
The ingestion report records
`normalization_scope: full_native_trace_before_segment_selection`. Existing output or
diff --git a/scripts/ingest_adsblol_day.py b/scripts/ingest_adsblol_day.py
index 7052276..4a9d7f2 100644
--- a/scripts/ingest_adsblol_day.py
+++ b/scripts/ingest_adsblol_day.py
@@ -77,7 +77,7 @@ if len(paths)<2:raise ValueError("Daily archive download is incomplete")
stats={"trace_files":0,"known_jets_removed":0,"no_conus_points":0,"retained_aircraft":0,"rows":0,"barometric_rows":0}
stats["normalization_scope"]="full_native_trace_before_segment_selection"
stats["selection_max_gap_s"]=30.0
-selection={"bounds":[west,south,east,north],"time_range_s":selected_time,
+selection={"bounds":[west,south,east,north],"time_range_s":selected_time,"archive_day_utc":args.date,
"all_aircraft":args.keep_jets,"max_gap_s":30.0}
writer=None
with io.BufferedReader(SplitReader(paths),buffer_size=1024*1024) as stream:
@@ -108,7 +108,7 @@ with io.BufferedReader(SplitReader(paths),buffer_size=1024*1024) as stream:
# Bound schema explicitly so an all-null metadata field in one
# aircraft cannot change a later parquet batch's physical type.
schema=pa.schema([(c,pa.string() if c in ["flight_id","typecode","altitude_basis"] else pa.float64()) for c in frame.columns],
- metadata={b"dopplergeist.selection.v1":json.dumps(selection,allow_nan=False).encode()})
+ metadata={b"dopplergeist.selection.v2":json.dumps(selection,allow_nan=False).encode()})
batch=pa.Table.from_pandas(frame,schema=schema,preserve_index=False)
if writer is None:writer=pq.ParquetWriter(output_path,schema,compression="zstd")
writer.write_table(batch)
diff --git a/src/dopplergeist/data_access.py b/src/dopplergeist/data_access.py
index 4bd868c..7eac208 100644
--- a/src/dopplergeist/data_access.py
+++ b/src/dopplergeist/data_access.py
@@ -335,9 +335,16 @@ class FlightIndex:
parquet_file = pq.ParquetFile(parquet)
metadata = parquet_file.schema_arrow.metadata or {}
if b"dopplergeist.selection.v1" in metadata:
- selected = json.loads(metadata[b"dopplergeist.selection.v1"])
+ raise DataUnavailable("Legacy selected Parquet lacks archive-day scope; reingest it")
+ if b"dopplergeist.selection.v2" in metadata:
+ selected = json.loads(metadata[b"dopplergeist.selection.v2"])
bounds, times = coverage["bounds"], coverage["time_range_s"]
box, interval = selected["bounds"], selected["time_range_s"]
+ source_day = date.fromisoformat(selected["archive_day_utc"])
+ if source_day.isoformat() != selected["archive_day_utc"]:
+ raise DataUnavailable("Invalid Parquet archive day")
+ day_start = datetime.combine(source_day, datetime.min.time(), tzinfo=timezone.utc).timestamp()
+ day_end = day_start + 86400.0
if (len(bounds) != 4 or len(box) != 4 or len(times) != 2 or
not np.isfinite([*bounds, *box, *times]).all() or
type(selected["all_aircraft"]) is not bool or
@@ -345,8 +352,9 @@ class FlightIndex:
not (box[0] <= bounds[0] <= bounds[2] <= box[2] and
box[1] <= bounds[1] <= bounds[3] <= box[3] and times[0] <= times[1])):
raise DataUnavailable("Declared flight coverage exceeds the Parquet selection bounds")
- if interval is not None and (len(interval) != 2 or not np.isfinite(interval).all() or
- not interval[0] <= times[0] <= times[1] <= interval[1]):
+ if (not isinstance(interval, list) or len(interval) != 2 or
+ not np.isfinite(interval).all() or
+ not day_start <= interval[0] <= times[0] <= times[1] <= interval[1] <= day_end):
raise DataUnavailable("Declared flight coverage exceeds the Parquet selection time")
if coverage.get("all_aircraft", False) and selected["all_aircraft"] is not True:
raise DataUnavailable("Parquet selection excluded aircraft types")
diff --git a/tests/test_ingest_adsblol_day.py b/tests/test_ingest_adsblol_day.py
index be129ae..af66bf1 100644
--- a/tests/test_ingest_adsblol_day.py
+++ b/tests/test_ingest_adsblol_day.py
@@ -60,7 +60,7 @@ def test_native_altitude_support_is_normalized_before_row_selection(tmp_path, se
assert report["barometric_rows"] == 0
assert report["normalization_scope"] == "full_native_trace_before_segment_selection"
assert report["selection_max_gap_s"] == 30.0
- selection_meta = pq.read_schema(day / "new.parquet").metadata[b"dopplergeist.selection.v1"]
+ selection_meta = pq.read_schema(day / "new.parquet").metadata[b"dopplergeist.selection.v2"]
assert json.loads(selection_meta)["max_gap_s"] == 30.0
assert all(hashlib.sha256((day / n).read_bytes()).hexdigest() == h for n, h in original.items())
# Repeating an old output name must preserve its historical bytes.
diff --git a/tests/test_real_flight_selection.py b/tests/test_real_flight_selection.py
index 523d98c..c2378c7 100644
--- a/tests/test_real_flight_selection.py
+++ b/tests/test_real_flight_selection.py
@@ -67,16 +67,18 @@ def test_real_boundary_segments_survive_selection(tmp_path):
assert old_filter_misses > 0
# Real rows with embedded source limits exercise index-side scope checks.
- selection = {"bounds": list(bounds), "time_range_s": [0, 4102444800],
+ day_window = [1788825600.0, 1788912000.0]
+ selection = {"bounds": list(bounds), "time_range_s": day_window, "archive_day_utc": "2026-09-08",
"all_aircraft": False, "max_gap_s": 30.0}
table = pa.Table.from_pandas(frames[0], preserve_index=False)
- table = table.replace_schema_metadata({b"dopplergeist.selection.v1": json.dumps(selection).encode()})
+ table = table.replace_schema_metadata({b"dopplergeist.selection.v2": json.dumps(selection).encode()})
source_parquet = tmp_path / "real-selected.parquet"
pq.write_table(table, source_parquet)
- restricted = dict(coverage, all_aircraft=False)
+ restricted = dict(coverage, all_aircraft=False, time_range_s=day_window)
FlightIndex.from_parquet(tmp_path / "valid.sqlite", source_parquet, coverage=restricted)
with pytest.raises(DataUnavailable, match="excluded aircraft"):
- FlightIndex.from_parquet(tmp_path / "types.sqlite", source_parquet, coverage=coverage)
+ FlightIndex.from_parquet(tmp_path / "types.sqlite", source_parquet,
+ coverage=dict(restricted, all_aircraft=True))
with pytest.raises(DataUnavailable, match="gap limit"):
FlightIndex.from_parquet(tmp_path / "gap.sqlite", source_parquet, coverage=restricted, max_gap_s=60)
with pytest.raises(DataUnavailable, match="selection bounds"):
@@ -84,7 +86,17 @@ def test_real_boundary_segments_survive_selection(tmp_path):
coverage=dict(restricted, bounds=[-180, -90, 181, 90]))
with pytest.raises(DataUnavailable, match="selection time"):
FlightIndex.from_parquet(tmp_path / "time.sqlite", source_parquet,
- coverage=dict(restricted, time_range_s=[-1, 4102444800]))
+ coverage=dict(restricted, time_range_s=[day_window[0] - 1, day_window[1]]))
+ for i, (tag, selected, message) in enumerate((
+ (b"dopplergeist.selection.v1", dict(selection, time_range_s=None), "Legacy selected Parquet"),
+ (b"dopplergeist.selection.v1", dict(selection, time_range_s=[0, 4102444800]), "Legacy selected Parquet"),
+ (b"dopplergeist.selection.v2", dict(selection, time_range_s=None), "selection time"),
+ (b"dopplergeist.selection.v2", dict(selection, time_range_s=[0, 4102444800]), "selection time"),
+ )):
+ malformed = tmp_path / f"malformed-{i}.parquet"
+ pq.write_table(table.replace_schema_metadata({tag: json.dumps(selected).encode()}), malformed)
+ with pytest.raises(DataUnavailable, match=message):
+ FlightIndex.from_parquet(tmp_path / "malformed.sqlite", malformed, coverage=restricted)
untagged = tmp_path / "real-untagged.parquet"
pq.write_table(table.replace_schema_metadata(None), untagged)
FlightIndex.from_parquet(tmp_path / "untagged.sqlite", untagged, coverage=coverage)
@@ -115,5 +127,6 @@ def test_real_boundary_segments_survive_selection(tmp_path):
env = dict(os.environ, PYTHONPATH=str(Path(__file__).resolve().parents[1] / "src"))
completed = subprocess.run(command, env=env, capture_output=True, text=True)
assert completed.returncode == 0, completed.stderr
- meta = pq.read_schema(day / (output + ".parquet")).metadata[b"dopplergeist.selection.v1"]
- assert json.loads(meta)["time_range_s"] == [1788825600.0, 1788912000.0]
+ meta = pq.read_schema(day / (output + ".parquet")).metadata[b"dopplergeist.selection.v2"]
+ assert json.loads(meta)["time_range_s"] == day_window
+ assert json.loads(meta)["archive_day_utc"] == "2026-09-08"