Skip to content

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

Require near-tied locations to fit the returned uncertainty envelope (#9, #36)

Cinna Davis79f2fe5ee69e
diff --git a/src/aircraft_geoloc/confidence.py b/src/aircraft_geoloc/confidence.py
index 269d98a..2a56408 100644
--- a/src/aircraft_geoloc/confidence.py
+++ b/src/aircraft_geoloc/confidence.py
@@ -152,6 +152,10 @@ def decide_location(events, candidates, coverage, *, matching_diagnostics=None,
subset_scores = best["score_kind"] == "matched_group_support_minus_normalized_residual"
if best["score_kind"] != "negative_robust_ridge_loss_hz" and not subset_scores:
return result("unsupported_score_kind", "This ranking score has no declared ambiguity threshold in the decision policy.")
+ # Alternatives must fit inside the envelope around the returned point.
+ # Two overlapping target-radius circles do not establish that containment.
+ ambiguity_radius_m = min(policy.target_radius_m,
+ best.get("uncertainty", {}).get("radius_m", policy.target_radius_m))
for alternative in candidates[1:]:
# Raw losses require equal event sets; subset support has declared units.
if not subset_scores and set(alternative["event_ids"]) != set(best["event_ids"]):
@@ -162,10 +166,10 @@ def decide_location(events, candidates, coverage, *, matching_diagnostics=None,
gap = (best["score"] - alternative["score"]) / max(len(groups), len(alternative_groups))
threshold = policy.near_tie_support_per_group if subset_scores else policy.near_tie_loss_per_event_hz
units = "support_units_per_group" if subset_scores else "loss_hz_per_group"
- if (separation > 2 * policy.target_radius_m or not same_flights) and gap <= threshold:
+ if (separation > ambiguity_radius_m or not same_flights) and gap <= threshold:
diagnostics["competing_hypothesis"] = {"separation_m": separation, "score_gap": gap, "gap_units": units,
- "same_flight_association": same_flights}
- return result("ambiguous_locations" if separation > 2 * policy.target_radius_m else "ambiguous_flight_match",
+ "same_flight_association": same_flights, "checked_radius_m": ambiguity_radius_m}
+ return result("ambiguous_locations" if separation > ambiguity_radius_m else "ambiguous_flight_match",
"Competing hypotheses fit nearly as well; no unique precise location is supported.")
if evidence.get("alternatives_evaluated") is not True:
return result("alternatives_not_assessed", "The retained competing hypotheses have not all been assessed.")
diff --git a/tests/test_confidence.py b/tests/test_confidence.py
index ca1558a..510f70c 100644
--- a/tests/test_confidence.py
+++ b/tests/test_confidence.py
@@ -1,6 +1,7 @@
from copy import deepcopy
import pytest
+from pyproj import Geod
from aircraft_geoloc.confidence import DecisionPolicy, decide_location
from aircraft_geoloc.contracts import validate_result
@@ -83,6 +84,23 @@ def test_distant_tie_and_same_location_different_flights():
assert decide((events, candidates + [alternative], coverage, diag))["reason_code"] == "ambiguous_flight_match"
[email protected]("separation_m,score,status", [
+ (60., -1.2, "succeeded"),
+ (90., -1.2, "inconclusive"),
+ (150., -1.2, "inconclusive"),
+ (90., -5., "succeeded"),
+])
+def test_near_tied_locations_fit_the_returned_envelope(separation_m, score, status):
+ events, candidates, coverage, diag = evidence()
+ best = candidates[0] # The returned radius is 70 m around this point.
+ lon, lat, _ = Geod(ellps="WGS84").fwd(best["lon"], best["lat"], 90., separation_m)
+ alternative = dict(best, lon=lon, lat=lat, score=score)
+ result = decide((events, candidates + [alternative], coverage, diag))
+ assert result["status"] == status
+ if status == "inconclusive":
+ assert result["reason_code"] == "ambiguous_locations"
+
+
def test_malformed_results_fail_instead_of_masquerading_as_insufficient_evidence():
events, candidates, coverage, diag = evidence()
candidates[0]["score"] = float("nan")