Python tool for aircraft Doppler audio geolocation using historical ADS-B flight data (Source-available)
Python acoustic-geolocationads-baircraft-trackingairplaneaudio-forensicsdoppler-effectdoppler-shiftgeolocationosintsignal-processing
Use consistent clock intervals for paired candidates
Cinna Davis504dd9b25e96
diff --git a/src/dopplergeist/matching.py b/src/dopplergeist/matching.pyindex fe1ca8d..6ccba97 100644--- a/src/dopplergeist/matching.py+++ b/src/dopplergeist/matching.py@@ -156,7 +156,7 @@ def association_candidates(table, events, offset_tolerance_s=5.0, time_origin=Noentries, branch visits and stored assignments share an explicit work budget.Exceeding it fails visibly so the outer driver reports incomplete coverage."""- from .search import filter_event+ from .search import filter_association_eventmax_events = max(min_events, len(events)) if max_events is None else max_eventsif not 1 <= min_events <= max_events or max_candidates < 1:raise ValueError("Invalid association event/candidate budget")@@ -171,15 +171,7 @@ def association_candidates(table, events, offset_tolerance_s=5.0, time_origin=Norecords = table.to_dict("records")grouped, survivors = [], []for event in events:- frame = filter_event(table, event, None, time_tolerance_s)- if time_origin is not None:- start = frame.receive_time - event["cpa_receive_s"]- tolerance = event.get("quality", {}).get("cpa_tolerance_s", 0) + offset_tolerance_s/2- # Use the same inclusive shared-clock intervals as the traversal.- # A separate CPA filter omitting offset tolerance can discard valid- # boundary passages before the intersection is considered.- frame = frame[(start - tolerance <= time_origin + time_tolerance_s) &- (start + tolerance >= time_origin - time_tolerance_s)]+ frame = filter_association_event(table, event, offset_tolerance_s, time_origin, time_tolerance_s)reserve(len(frame))survivors.append(len(frame))grouped.append({p: [records[i] for i in group.index] for p, group in frame.groupby("point_id")})diff --git a/src/dopplergeist/search.py b/src/dopplergeist/search.pyindex 778f40a..a35880f 100644--- a/src/dopplergeist/search.py+++ b/src/dopplergeist/search.py@@ -147,9 +147,21 @@ def filter_event(table, event, time_origin=None, time_tolerance=5.0):return table.loc[keep]+def filter_association_event(table, event, offset_tolerance_s, time_origin, time_tolerance_s):+ """Filter with the same shared-clock interval used by association."""+ frame = filter_event(table, event)+ if time_origin is not None:+ start = frame.receive_time - event["cpa_receive_s"]+ tolerance = event.get("quality", {}).get("cpa_tolerance_s", 0) + offset_tolerance_s/2+ frame = frame[(start - tolerance <= time_origin + time_tolerance_s) &+ (start + tolerance >= time_origin - time_tolerance_s)]+ return frame++def pair_candidates(table, events, offset_tolerance_s=5.0, time_origin=None,time_tolerance_s=5.0, silence=None):- filtered = [filter_event(table,event,time_origin,time_tolerance_s) for event in events]+ filtered = [filter_association_event(table, event, offset_tolerance_s, time_origin, time_tolerance_s)+ for event in events]if any(frame.empty for frame in filtered):return [],{"per_event_survivors":[len(f) for f in filtered],"pairs_before_silence":0,"silence_rejected":0}group = [dict(tuple(frame.groupby("point_id"))) for frame in filtered]diff --git a/tests/test_real_fixed_clock_filter.py b/tests/test_real_fixed_clock_filter.pyindex ca5e224..0a594be 100644--- a/tests/test_real_fixed_clock_filter.py+++ b/tests/test_real_fixed_clock_filter.py@@ -1,11 +1,14 @@"""Fixed-clock boundary regression using an observed ADS-B passage and audio proposal."""import numpy as npimport pandas as pd+import pytestfrom dopplergeist.matching import association_candidates+from dopplergeist.search import pair_candidates-def test_real_passage_is_kept_at_inclusive_clock_endpoints():[email protected]("find_candidates", [association_candidates, pair_candidates])+def test_real_passage_is_kept_at_inclusive_clock_endpoints(find_candidates):event = {'cpa_receive_s': 301.25, 'speed_range_mps': [1.0, 308.7],'slant_range_m': [1.0, 20000.0], 'quality': {'cpa_tolerance_s': 7.25}}passage = {'point_id': 0, 'flight_id': '06a128', 'emission_time': 1788899665.5239854,@@ -17,15 +20,15 @@ def test_real_passage_is_kept_at_inclusive_clock_endpoints():for clock, expected in ((np.nextafter(left, -np.inf), False), (left, True),(np.nextafter(left, np.inf), True), (np.nextafter(right, -np.inf), True),(right, True), (np.nextafter(right, np.inf), False)):- candidates, _ = association_candidates(pd.DataFrame([passage]), [event],- offset_tolerance_s=5, time_origin=clock,- time_tolerance_s=0)+ candidates, _ = find_candidates(pd.DataFrame([passage]), [event],+ offset_tolerance_s=5, time_origin=clock,+ time_tolerance_s=0)assert bool(candidates) is expected# The declared clock window may itself span multiple seconds.for clock, expected in ((np.nextafter(left - 3, -np.inf), False), (left - 3, True),(right + 3, True), (np.nextafter(right + 3, np.inf), False)):- candidates, _ = association_candidates(pd.DataFrame([passage]), [event],- offset_tolerance_s=5, time_origin=clock,- time_tolerance_s=3)+ candidates, _ = find_candidates(pd.DataFrame([passage]), [event],+ offset_tolerance_s=5, time_origin=clock,+ time_tolerance_s=3)assert bool(candidates) is expected