Skip to content

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

Exercise real first-interval CPA in tiled search

Cinna Davis191459a89d16
diff --git a/tests/test_real_tiled_cpa_edge.py b/tests/test_real_tiled_cpa_edge.py
index 22cd276..dd9a1c9 100644
--- a/tests/test_real_tiled_cpa_edge.py
+++ b/tests/test_real_tiled_cpa_edge.py
@@ -8,6 +8,7 @@ import pandas as pd
import pytest
from scipy.optimize import minimize_scalar
+from dopplergeist.data_access import FlightIndex
from dopplergeist.geometry import ecef
from dopplergeist.search import cpa_table
from dopplergeist.tracks import load_tracks
@@ -37,3 +38,27 @@ def test_real_tiled_cpa_preserves_final_interval_passage():
assert len(matching) == 1
assert matching.iloc[0].emission_time == pytest.approx(lo + minimum.x, abs=0.01)
assert matching.iloc[0].distance_m == pytest.approx(minimum.fun ** 0.5, abs=0.1)
+
+
+def test_real_tiled_cpa_preserves_first_interval_passage():
+ source = os.environ.get("DOPPLERGEIST_REAL_REFERENCE_ROOT")
+ index_path = os.environ.get("DOPPLERGEIST_REAL_FLIGHT_INDEX")
+ if not source or not index_path:
+ pytest.skip("set the real reference root and all-type flight index paths")
+ root = Path(source)
+ candidates = json.loads((root / "results/reference-faint-alltypes-local/ranked.json").read_text())
+ point = next(row for row in candidates if row["point_id"] == 2936)
+ flight = "[email protected]:38"
+ track = next(FlightIndex(index_path).lookup([flight]))
+ observer = ecef(point["lat"], point["lon"], point["elev_m"])
+ samples = np.unique(np.r_[np.arange(track.time[0], track.time[-1], 2), track.time[-1]])
+ lo, hi = samples[:2]
+ minimum = minimize_scalar(lambda dt: np.sum((track.position(lo + dt) - observer) ** 2),
+ bounds=(0, hi - lo), method="bounded", options={"xatol": 0.0001})
+ assert 0 < minimum.x < hi - lo and minimum.fun < 20000 ** 2
+ points = pd.DataFrame([{key: point[key] for key in ("point_id", "lat", "lon", "elev_m", "x", "y")}])
+ rows = cpa_table([track], points, 20000)
+ matching = rows[(rows.emission_time >= lo) & (rows.emission_time <= hi)]
+ assert len(matching) == 1
+ assert matching.iloc[0].emission_time == pytest.approx(lo + minimum.x, abs=0.01)
+ assert matching.iloc[0].distance_m == pytest.approx(minimum.fun ** 0.5, abs=0.1)