Skip to content

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

Skip proven distant tracks before CPA tables

Cinna Davis33ba83c6f799
diff --git a/src/dopplergeist/geometry.py b/src/dopplergeist/geometry.py
index 988c034..958082c 100644
--- a/src/dopplergeist/geometry.py
+++ b/src/dopplergeist/geometry.py
@@ -55,6 +55,9 @@ class Track:
if not np.all(np.isfinite(np.column_stack((self.time, self.lat, self.lon, self.altitude)))):
raise ValueError(f"{self.id}: nonfinite track data")
self.xyz = ecef(self.lat, self.lon, self.altitude)
+ self._xyz_min = self.xyz.min(axis=0)
+ self._xyz_max = self.xyz.max(axis=0)
+ self._max_sample_gap = float(np.max(np.diff(self.time)))
self.origin = self.time[0]
self.relative_time = self.time - self.origin
v = self.velocity
@@ -111,6 +114,26 @@ class Track:
raise AcousticSupportError(self.id, "non_subsonic_motion",
emission_intervals_s=[[float(self.time[i]), float(self.time[i+1])] for i in indices])
+ def outside_observer_radius(self, observers, radius, c=343.0):
+ """Prove all observers are beyond a validated track's range.
+
+ Every instant lies at most half a native sample interval from one
+ endpoint. Subsonic speed therefore bounds each ECEF component's
+ displacement from an observed position by c * max_gap / 2. An axis
+ separation larger than the radius proves the entire cubic trajectory
+ and its sampled polyline cannot enter any observer's search sphere.
+ """
+ self.validate_motion_support(c)
+ if not np.isfinite(radius):
+ return False
+ scale = max(1.0, float(np.max(np.abs(self._xyz_min))),
+ float(np.max(np.abs(self._xyz_max))), abs(radius), abs(c * self._max_sample_gap))
+ rounding = 64 * np.finfo(float).eps * scale
+ margin = c * self._max_sample_gap / 2 + rounding
+ lower = self._xyz_min - margin - radius - rounding
+ upper = self._xyz_max + margin + radius + rounding
+ return bool(np.all(np.any((observers < lower) | (observers > upper), axis=-1)))
+
def _check_motion_support(self, receive_time, observer, c):
"""Reject possible arrivals from unsupported native emission intervals.
diff --git a/src/dopplergeist/tiled_search.py b/src/dopplergeist/tiled_search.py
index ab20b9d..51ddd53 100644
--- a/src/dopplergeist/tiled_search.py
+++ b/src/dopplergeist/tiled_search.py
@@ -20,7 +20,7 @@ from pyproj import Transformer
from .data_access import CONUS, DataUnavailable, content_hash, sha256, write_json
from .finite_search import RetentionLedger, bounded_assessment, classified_assessment, identify_mode, mode_seed
-from .geometry import AcousticSupportError
+from .geometry import AcousticSupportError, ecef
from .matching import _cache_ridge_fits
from .search import cpa_table, filter_association_event, pair_candidates, score_candidate
@@ -157,6 +157,7 @@ def _tracks(indexes, bounds, time_range, budget):
@_cache_ridge_fits
def _score(points, tracks, events, measurements, budget, parameters, filters, start_window=None, *, ledger=None, stage=None):
radius = max(e["slant_range_m"][1] for e in events)
+ observers = ecef(points.lat.to_numpy(), points.lon.to_numpy(), points.elev_m.to_numpy())
tables, count = [], 0
unsupported = []
# Bound materialized CPA rows before pairing; one track at a time keeps the
@@ -170,6 +171,8 @@ def _score(points, tracks, events, measurements, budget, parameters, filters, st
chunk_points = max(1, budget.max_cpa_rows // samples)
track_tables, track_rows = [], 0
try:
+ if track.outside_observer_radius(observers, radius, parameters.get("c", 343.0)):
+ continue
for first in range(0, len(points), chunk_points):
table = cpa_table([track], points.iloc[first:first + chunk_points], radius, parameters.get("c", 343.0), budget.cpa_step_s)
track_rows += len(table)
diff --git a/tests/test_real_cpa_spatial_sieve.py b/tests/test_real_cpa_spatial_sieve.py
new file mode 100644
index 0000000..9d8bc87
--- /dev/null
+++ b/tests/test_real_cpa_spatial_sieve.py
@@ -0,0 +1,80 @@
+"""Optional end-to-end CPA sieve comparison using recorded audio and real tracks."""
+import json
+import os
+from pathlib import Path
+
+import pandas as pd
+import pytest
+
+from dopplergeist.geometry import AcousticSupportError, Track, ecef
+from dopplergeist.matching import prepare_events
+from dopplergeist.search import cpa_table
+from dopplergeist.tiled_search import SearchBudget, _score
+from dopplergeist.tracks import load_tracks
+
+
+def test_real_search_sieve_preserves_candidates_and_support(monkeypatch):
+ root = os.environ.get("DOPPLERGEIST_REAL_REFERENCE_ROOT")
+ discovery = os.environ.get("DOPPLERGEIST_REAL_REFERENCE_DISCOVERY")
+ if not root or not discovery:
+ pytest.skip("set the real reference checkout and discovery JSON paths")
+ root = Path(root)
+ seed = json.loads((root / "results/reference-local/ranked.json").read_text())[0]
+ events = json.loads(Path(discovery).read_text())["events"]
+ events, measurements = prepare_events(events)
+ clock = seed["recording_start_time_s"]
+ tracks, _ = load_tracks(root / "data/adsb/2026-09-08/reference-region.parquet",
+ time_range=(clock - 120, clock + 3720))
+ points = pd.DataFrame([{key: seed[key] for key in ("point_id", "lat", "lon", "elev_m", "x", "y")}])
+ options = dict(budget=SearchBudget(top_k=5),
+ parameters={"mode": "robust_ridge", "time_origin": clock, "time_sweep_s": 0},
+ filters={})
+
+ # This is an existing regional development point, not an evaluation search
+ # or a claim about the microphone's location. The baseline calls the same
+ # CPA table and scoring code but disables this one spatial prefilter.
+ original = Track.outside_observer_radius
+ monkeypatch.setattr(Track, "outside_observer_radius", lambda *args, **kwargs: False)
+ before = _score(points, tracks, events, measurements, **options)
+ excluded = []
+
+ def counting(track, *args, **kwargs):
+ result = original(track, *args, **kwargs)
+ if result:
+ excluded.append(track.id)
+ return result
+
+ monkeypatch.setattr(Track, "outside_observer_radius", counting)
+ after = _score(points, tracks, events, measurements, **options)
+ assert excluded
+ assert after[1]["cpa_rows"] > 0
+ assert json.dumps(after, sort_keys=True, allow_nan=True) == json.dumps(before, sort_keys=True, allow_nan=True)
+
+
+def test_real_multi_point_sieve_does_not_discard_cpas():
+ source = os.environ.get("DOPPLERGEIST_REAL_REFERENCE_ROOT")
+ if not source:
+ pytest.skip("set DOPPLERGEIST_REAL_REFERENCE_ROOT to the real reference checkout")
+ root = Path(source)
+ clock = json.loads((root / "results/reference-local/ranked.json").read_text())[0]["recording_start_time_s"]
+ candidates = json.loads((root / "results/reference-faint-alltypes-local/ranked.json").read_text())[:64]
+ points = pd.DataFrame(candidates).drop_duplicates("point_id")
+ observers = ecef(points.lat.to_numpy(), points.lon.to_numpy(), points.elev_m.to_numpy())
+ tracks, _ = load_tracks(root / "data/adsb/2026-09-08/reference-region.parquet",
+ time_range=(clock - 120, clock + 3720))
+ excluded, retained_rows, unsupported = 0, 0, 0
+ for track in tracks:
+ try:
+ outside = track.outside_observer_radius(observers, 20000)
+ except AcousticSupportError:
+ unsupported += 1
+ with pytest.raises(AcousticSupportError):
+ cpa_table([track], points, 20000)
+ continue
+ table = cpa_table([track], points, 20000)
+ if outside:
+ excluded += 1
+ assert table.empty
+ else:
+ retained_rows += len(table)
+ assert excluded > 0 and retained_rows > 0 and unsupported > 0