Python tool for aircraft Doppler audio geolocation using historical ADS-B flight data (Source-available)
Python acoustic-geolocationads-baircraft-trackingairplaneaudio-forensicsdoppler-effectdoppler-shiftgeolocationosintsignal-processing
Abstain when matched ridge groups may be harmonics
Cinna Davis1146cbe3aea8
diff --git a/docs/CONFIDENCE.md b/docs/CONFIDENCE.mdindex 0f0b269..6624258 100644--- a/docs/CONFIDENCE.md+++ b/docs/CONFIDENCE.md@@ -14,6 +14,14 @@ execution exceptions remain execution failures, distinct from insufficientscientific evidence. Coverage means completion of the requested geographic/timescope and availability of requested archives, not capture of every aircraft.+When separately labeled matched groups have strongly overlapping measured+ridge samples compatible with a rational harmonic ratio within a conservative+frequency-uncertainty heuristic, the decision is inconclusive. The diagnostic+records the pair and measured discrepancy; it does not relabel events or assert+that they came from the same aircraft. The heuristic is uncalibrated and may+cause false inconclusive outcomes. A missing flag does not establish event+independence, particularly with missing uncertainties or poorly aligned samples.+## Default policy and evidenceThe current default `DecisionPolicy` is `engineering-v3`; the original v1 receipts@@ -86,7 +94,7 @@ branch; it does not establish that the real producer has provided such evidence.| `search_incomplete` | Requested geographic/time search unfinished || `partial_flight_coverage` | Some required data missing || `no_matching_flights` | No event/track hypothesis |-| `insufficient_independent_events` | Too few flyovers after harmonic grouping |+| `insufficient_independent_events` | Too few flyovers, or matched groups may be overlapping harmonics || `inconsistent_harmonic_association` | Harmonics map to different flights || `incomplete_harmonic_group` | Partial association omits a matched event's harmonic || `unexplained_events` | Unmatched proposals lack explicit subset-association evidence |diff --git a/src/dopplergeist/confidence.py b/src/dopplergeist/confidence.pyindex c43025f..99b5883 100644--- a/src/dopplergeist/confidence.py+++ b/src/dopplergeist/confidence.py@@ -7,6 +7,7 @@ diagnostics belong in a job artifact, outside the strict JobResult fields.from dataclasses import asdict, dataclassimport math+import numpy as npfrom pyproj import Geodfrom .contracts import utc_timestamp, validate_result@@ -40,6 +41,50 @@ def _near_tied(gap, margin):return gap <= margin or math.isclose(gap, margin, rel_tol=1e-12, abs_tol=1e-12)+def _possible_harmonic_overlap(events):+ """Flag an uncalibrated ambiguity; do not merge ridges or assert identity."""+ from .discovery import _HARMONIC_RATIOS++ for index, first in enumerate(events):+ for second in events[index + 1:]:+ if first.get("harmonic_group_id", first["event_id"]) == second.get("harmonic_group_id", second["event_id"]):+ continue+ low, high = first, second+ a = {point["time_s"]: point["frequency_hz"] for point in low["ridge"]}+ b = {point["time_s"]: point["frequency_hz"] for point in high["ridge"]}+ times = sorted(a.keys() & b.keys())+ if len(times) < 10:+ continue+ span = min(low["ridge"][-1]["time_s"] - low["ridge"][0]["time_s"],+ high["ridge"][-1]["time_s"] - high["ridge"][0]["time_s"])+ if span <= 0 or times[-1] - times[0] < 0.6 * span:+ continue+ x, y = (np.array([ridge[t] for t in times], dtype=float) for ridge in (a, b))+ if np.median(x) > np.median(y):+ low, high, x, y = high, low, y, x+ with np.errstate(over="ignore", invalid="ignore", divide="ignore"):+ ratio = float(np.median(y / x))+ if not math.isfinite(ratio):+ continue+ harmonic = min((1.0, *_HARMONIC_RATIOS), key=lambda value: abs(value - ratio))+ def uncertainty(event):+ quality = event.get("quality", {})+ return max(0.0, quality.get("frequency_resolution_hz", 0),+ quality.get("frequency_uncertainty_hz", 0))+ low_uncertainty, high_uncertainty = uncertainty(low), uncertainty(high)+ if low_uncertainty <= 0 or high_uncertainty <= 0:+ continue+ with np.errstate(over="ignore", invalid="ignore"):+ residual = float(np.quantile(np.abs(y - harmonic * x), 0.9))+ tolerance = 2 * (high_uncertainty + harmonic * low_uncertainty)+ if math.isfinite(residual) and math.isfinite(tolerance) and residual <= tolerance:+ return {"event_ids": [low["event_id"], high["event_id"]],+ "harmonic_ratio": harmonic, "observed_median_ratio": ratio,+ "aligned_samples": len(times), "residual_q90_hz": residual,+ "heuristic_tolerance_hz": tolerance}+ return None++def _finite_search(evidence, diagnostics, candidates, group_counts, policy):"""Check producer-accounted evaluated modes, without a continuous-space claim."""if not isinstance(evidence, dict) or type(evidence.get("schema_version")) is not int or evidence["schema_version"] != 1:@@ -194,6 +239,15 @@ def decide_location(events, candidates, coverage, *, matching_diagnostics=None,known_clock = (interval(window) and interval(tested_clock) andtested_clock[0] <= window[0] and tested_clock[1] >= window[1])diagnostics["known_clock_single_event"] = bool(len(groups) == 1 and known_clock)+ diagnostics["harmonic_overlap_screen"] = (+ "Uncalibrated aligned-sample heuristic; no flag does not establish independence.")+ possible_overlap = _possible_harmonic_overlap(matched)+ if possible_overlap is not None:+ diagnostics["matched_group_count"] = len(groups)+ diagnostics["independent_event_groups"] = None+ diagnostics["possible_harmonic_overlap"] = possible_overlap+ return result("insufficient_independent_events",+ "Overlapping matched ridges may be harmonics of one flyover; independent events are not established.")if len(groups) < policy.min_independent_events and not (len(groups) == 1 andpolicy.min_independent_events == 2 and known_clock):return result("insufficient_independent_events", "Too few independent flyovers constrain location; harmonics count once.")diff --git a/tests/test_real_harmonic_ambiguity.py b/tests/test_real_harmonic_ambiguity.pynew file mode 100644index 0000000..d79324c--- /dev/null+++ b/tests/test_real_harmonic_ambiguity.py@@ -0,0 +1,38 @@+"""Investigate ambiguity using existing public recordings, not generated audio."""+import copy+import json+import os+from pathlib import Path++import pytest++from dopplergeist.confidence import _possible_harmonic_overlap+from dopplergeist.contracts import validate_event+++def test_real_overlapping_ridges_have_unresolved_harmonic_ambiguity():+ source = os.environ.get("DOPPLERGEIST_REAL_HARMONIC_SCAN")+ if not source:+ pytest.skip("set DOPPLERGEIST_REAL_HARMONIC_SCAN to the saved real scan JSON")+ events = [validate_event(event) for event in json.loads(Path(source).read_text())["events"]]+ assert len(events) == 2 and events[0]["harmonic_group_id"] != events[1]["harmonic_group_id"]+ flag = _possible_harmonic_overlap(events)+ assert flag and set(flag["event_ids"]) == {event["event_id"] for event in events}+ assert flag["harmonic_ratio"] == 1.5 and flag["aligned_samples"] >= 10+ assert flag["residual_q90_hz"] <= flag["heuristic_tolerance_hz"]+ assert _possible_harmonic_overlap(events[:1]) is None+ # Metadata-only relabeling checks that existing harmonic groups are not+ # compared against themselves; the recorded ridge samples are untouched.+ grouped = copy.deepcopy(events)+ grouped[1]["harmonic_group_id"] = grouped[0]["harmonic_group_id"]+ assert _possible_harmonic_overlap(grouped) is None+++def test_real_unflagged_group_pair_is_not_automatically_rejected():+ source = os.environ.get("DOPPLERGEIST_REAL_HARMONIC_CONTROL")+ if not source:+ pytest.skip("set DOPPLERGEIST_REAL_HARMONIC_CONTROL to a saved real scan JSON")+ events = [validate_event(event) for event in json.loads(Path(source).read_text())["events"]]+ assert len({event["harmonic_group_id"] for event in events}) >= 2+ # Absence of a flag is not proof that these are independent aircraft.+ assert _possible_harmonic_overlap(events) is None