Python tool for aircraft Doppler audio geolocation using historical ADS-B flight data (Source-available)
Python acoustic-geolocationads-baircraft-trackingairplaneaudio-forensicsdoppler-effectdoppler-shiftgeolocationosintsignal-processing
Enforce selected flight source coverage in Parquet
Cinna Davisdfc9d8871d78
diff --git a/docs/HISTORICAL_INGESTION.md b/docs/HISTORICAL_INGESTION.mdindex fd89482..f3b70c0 100644--- a/docs/HISTORICAL_INGESTION.md+++ b/docs/HISTORICAL_INGESTION.md@@ -8,6 +8,10 @@ This preserves altitude calibration, segment boundary derivatives and passagesthat cross a query between recorded samples. The conservative continuous boundsand 30-second gap limit match the default `FlightIndex` build; a differentlyconfigured gap limit requires a new selection. The report records that limit.+New Parquet files also embed the selection box, time interval, aircraft-type scope+and gap limit. `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.The ingestion report records`normalization_scope: full_native_trace_before_segment_selection`. Existing output ordiff --git a/scripts/ingest_adsblol_day.py b/scripts/ingest_adsblol_day.pyindex b9277c3..ed718d7 100644--- a/scripts/ingest_adsblol_day.py+++ b/scripts/ingest_adsblol_day.py@@ -71,6 +71,8 @@ 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":time_range,+ "all_aircraft":args.keep_jets,"max_gap_s":30.0}writer=Nonewith io.BufferedReader(SplitReader(paths),buffer_size=1024*1024) as stream:with tarfile.open(fileobj=stream,mode="r|") as archive:@@ -99,7 +101,8 @@ with io.BufferedReader(SplitReader(paths),buffer_size=1024*1024) as stream:frame["heading_deg"]=frame.heading_deg.astype(float)# 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])+ 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()})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.pyindex 3430d3b..e9b3300 100644--- a/src/dopplergeist/data_access.py+++ b/src/dopplergeist/data_access.py@@ -321,11 +321,31 @@ class FlightIndex:def from_parquet(cls, path, parquet, *, coverage, **kwargs):import pyarrow.parquet as pqparquet = Path(parquet)- source = {"path": str(parquet.resolve()), "sha256": sha256(parquet), "bytes": parquet.stat().st_size}try:- frames = (batch.to_pandas() for batch in pq.ParquetFile(parquet).iter_batches(batch_size=16384))+ 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"])+ bounds, times = coverage["bounds"], coverage["time_range_s"]+ box, interval = selected["bounds"], selected["time_range_s"]+ 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+ not np.isfinite(selected["max_gap_s"]) or selected["max_gap_s"] <= 0 or+ 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]):+ 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")+ if selected["max_gap_s"] != kwargs.get("max_gap_s", 30.0):+ raise DataUnavailable("Index gap limit differs from the Parquet selection gap")+ source = {"path": str(parquet.resolve()), "sha256": sha256(parquet), "bytes": parquet.stat().st_size}+ frames = (batch.to_pandas() for batch in parquet_file.iter_batches(batch_size=16384))return cls.build(path, frames, sources=[source], coverage=coverage, **kwargs)- except (OSError, ValueError) as error:+ except (OSError, ValueError, KeyError, TypeError) as error:raise DataUnavailable(f"Invalid/truncated Parquet: {parquet}: {error}") from errordef query(self, bounds, time_range):diff --git a/tests/test_ingest_adsblol_day.py b/tests/test_ingest_adsblol_day.pyindex b4c24f8..be129ae 100644--- a/tests/test_ingest_adsblol_day.py+++ b/tests/test_ingest_adsblol_day.py@@ -11,6 +11,7 @@ import sysimport tarfileimport pandas as pd+import pyarrow.parquet as pqimport pytest@@ -59,6 +60,8 @@ def test_native_altitude_support_is_normalized_before_row_selection(tmp_path, seassert report["barometric_rows"] == 0assert 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"]+ assert json.loads(selection_meta)["max_gap_s"] == 30.0assert 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.artifact = (day / "new.parquet").read_bytes()diff --git a/tests/test_real_flight_selection.py b/tests/test_real_flight_selection.pyindex 8b16628..6be278d 100644--- a/tests/test_real_flight_selection.py+++ b/tests/test_real_flight_selection.py@@ -6,9 +6,11 @@ from pathlib import Pathimport tarfileimport numpy as np+import pyarrow as pa+import pyarrow.parquet as pqimport pytest-from dopplergeist.data_access import FlightIndex+from dopplergeist.data_access import DataUnavailable, FlightIndexfrom dopplergeist.flight_selection import intersects_index_queryfrom dopplergeist.tracks import adsblol_frame@@ -56,3 +58,26 @@ def test_real_boundary_segments_survive_selection(tmp_path):breakassert checked == 5assert old_filter_misses > 0++ # Real rows with embedded source limits exercise index-side scope checks.+ selection = {"bounds": list(bounds), "time_range_s": [0, 4102444800],+ "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()})+ source_parquet = tmp_path / "real-selected.parquet"+ pq.write_table(table, source_parquet)+ restricted = dict(coverage, all_aircraft=False)+ 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)+ 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"):+ FlightIndex.from_parquet(tmp_path / "bounds.sqlite", source_parquet,+ 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]))+ 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)