Python tool for aircraft Doppler audio geolocation using historical ADS-B flight data (Source-available)
Python acoustic-geolocationads-baircraft-trackingairplaneaudio-forensicsdoppler-effectdoppler-shiftgeolocationosintsignal-processing
Classify every robust clock trial and expose typed emission failures (#13, #64)
Cinna Davis84d5877794c0
diff --git a/docs/SCORING_ASSESSMENT.md b/docs/SCORING_ASSESSMENT.mdnew file mode 100644index 0000000..dc451e6--- /dev/null+++ b/docs/SCORING_ASSESSMENT.md@@ -0,0 +1,35 @@+# Bounded robust-clock trial accounting++`search.score_candidate` returns `scoring_assessment` for `robust_ridge` mode:+`complete`, `evaluated_trials`, `rejected_trials`, `unknown_trials` and `reasons`.+These fields describe every clock trial actually requested by the existing+bounded sweep. They do not change the clock grid, fitted source model, scores,+association ordering or score thresholds.++A complete, finite ridge fit at every selected event is an evaluated trial.+When that fit exceeds the existing subset acoustic-loss limit, it is a known+rejection, including an envelope whose every trial is rejected. Missing ridge or+trajectory support and nonfinite model work remain unknown. A finite best row+cannot hide another unknown trial. An empty clock domain is unassessed rather+than vacuously complete. Completion requires zero unknown trials.++`geometry.AcousticSupportError` is a `ValueError` subclass with string attributes+`track_id` and `reason`. Its message is `"<track_id>: <reason>"`. The existing+nonpositive emission-to-arrival derivative failure now uses reason+`non_monotone_arrival`. The scorer catches only this typed model-support failure+and counts the trial as unknown; unrelated `ValueError`s still propagate.+W2's outer driver can use the same type to preserve other track rows while+marking unsupported coverage partial. This increment does not perform that outer+isolation, audit every continuous speed interval, normalize historical traces or+establish complete real-track coverage; those remain #64 work.++W2's finite ledger consumes these exact fields and exposes only classified core+seed IDs. W4's finite-grid consumer and W5's explicit assessment mapping still+apply all coverage, competing-mode, profile and ambiguity gates. Legacy modes+and historical jobs are unchanged. This accounting is not a probability,+continuous-space uniqueness claim or accepted physical replay.++Regression commands and native outputs are retained in the accompanying W1+integration evidence. The controls include a finite best with an unsupported+competing clock, all-trial acoustic rejection, a typed real `Track` failure,+unrelated exceptions and an empty clock domain.diff --git a/src/aircraft_geoloc/geometry.py b/src/aircraft_geoloc/geometry.pyindex 1817251..c826f32 100644--- a/src/aircraft_geoloc/geometry.py+++ b/src/aircraft_geoloc/geometry.py@@ -12,6 +12,13 @@ from scipy.optimize import minimize_scalarfrom scipy.signal import find_peaks+class AcousticSupportError(ValueError):+ """A trajectory cannot support the assumed emission-time acoustic model."""+ def __init__(self, track_id, reason):+ self.track_id, self.reason = track_id, reason+ super().__init__(f"{track_id}: {reason}")++def ecef(lat, lon, height):lat, lon, height = np.broadcast_arrays(np.deg2rad(lat), np.deg2rad(lon), height)a, e2 = 6378137.0, 6.6943799901413165e-3@@ -79,7 +86,7 @@ class Track:radial = np.sum(delta * self.speed_vector(tau), axis=-1) / distancederivative = 1 + radial / cif np.any(derivative <= 0):- raise ValueError("Acoustic model requires a subsonic source")+ raise AcousticSupportError(self.id, "non_monotone_arrival")correction = (tau - t + distance / c) / derivativetau = np.clip(tau - correction, start, end)if np.max(np.abs(correction)) < 1e-7:diff --git a/src/aircraft_geoloc/search.py b/src/aircraft_geoloc/search.pyindex 0fb3e83..228ae12 100644--- a/src/aircraft_geoloc/search.py+++ b/src/aircraft_geoloc/search.py@@ -6,7 +6,7 @@ import pandas as pdfrom scipy.signal import find_peaksfrom scipy.spatial import cKDTree-from .geometry import ecef+from .geometry import AcousticSupportError, ecefdef cpa_table_dense(tracks, points, max_distance, c=343.0, step_s=2.0, chunk_size=256):@@ -251,14 +251,32 @@ def score_candidate(candidate, point, tracks, events, measurements, mode="brightelse:shifts = np.linspace(lower-anchor,upper-anchor,max(1,int(np.ceil((upper-lower)/time_step_s)))+1)best = {"score":-np.inf}+ assessment = {"complete": False, "evaluated_trials": 0, "rejected_trials": 0,+ "unknown_trials": 0, "reasons": []}+ reasons = set()for shift in shifts:if mode == "robust_ridge":from .matching import score_ridges- result = score_ridges([tracks[p["flight_id"]] for p in candidate["passes"]],- events,measurements,observer,anchor+shift,c)+ try:+ result = score_ridges([tracks[p["flight_id"]] for p in candidate["passes"]],+ events,measurements,observer,anchor+shift,c)+ except AcousticSupportError as error:+ assessment["unknown_trials"] += 1+ reasons.add(str(error))+ continue+ supported = all(d.get("support_fraction") == 1 and np.isfinite(d["score"])+ for d in result["event_diagnostics"])if association:from .matching import association_scoreresult = association_score(result, events)+ if not supported or np.isnan(result["score"]) or result["score"] == np.inf:+ assessment["unknown_trials"] += 1+ reasons.add("incomplete_ridge_or_trajectory_support")+ elif result["score"] == -np.inf:+ assessment["rejected_trials"] += 1+ reasons.add("acoustic_loss_exceeds_limit")+ else:+ assessment["evaluated_trials"] += 1if result["score"] > best["score"]:best = dict(result,recording_start_time_s=float(anchor+shift),time_adjustment_s=float(shift))continue@@ -273,6 +291,13 @@ def score_candidate(candidate, point, tracks, events, measurements, mode="brightif total>best["score"]:best = {"score":total,"event_scores":scores,"f0_hz":f0s,"recording_start_time_s":float(anchor+shift),"time_adjustment_s":float(shift)}+ if mode == "robust_ridge":+ if not len(shifts):+ assessment["unknown_trials"] = 1+ reasons.add("no_clock_trials")+ assessment["complete"] = assessment["unknown_trials"] == 0+ assessment["reasons"] = sorted(reasons)+ best["scoring_assessment"] = assessmentreturn dict(best,**association_fields,point_id=int(point.point_id),lat=float(point.lat),lon=float(point.lon),elev_m=float(point.elev_m),x=float(point.x),y=float(point.y),flight_ids=[p["flight_id"] for p in candidate["passes"]])diff --git a/tests/test_scoring_assessment.py b/tests/test_scoring_assessment.pynew file mode 100644index 0000000..52d0b6d--- /dev/null+++ b/tests/test_scoring_assessment.py@@ -0,0 +1,88 @@+"""Independent protocol checks for classified bounded clock trials."""+from types import SimpleNamespace++import numpy as np+import pytest++from aircraft_geoloc import geometry+from aircraft_geoloc.matching import RidgeTimes+from aircraft_geoloc.search import score_candidate+++class Model:+ def __init__(self, last_supported=np.inf, error=None):+ self.last_supported, self.error = last_supported, error++ def acoustic(self, times, observer, c):+ if self.error is not None:+ raise self.error+ times = np.asarray(times)+ factor = np.where(times <= self.last_supported, 1.0, np.nan)+ return factor, times - 5, np.full_like(times, 1700.0)+++def score(model, *, ridge_hz=120.0, association=False, bounds=None):+ times = np.arange(0, 20, 0.5)+ measurement = (RidgeTimes(times), np.full_like(times, ridge_hz), np.ones_like(times), {})+ point = SimpleNamespace(point_id=0, lat=40, lon=-100, elev_m=0, x=0, y=0)+ candidate = {"passes": [{"flight_id": "test-flight", "receive_time": 10}]}+ if association:+ candidate["event_indices"] = [0]+ if bounds is not None:+ candidate["recording_start_bounds_s"] = bounds+ event = {"event_id": "event", "cpa_receive_s": 10, "f0_range_hz": [119, 121]}+ return score_candidate(candidate, point, {"test-flight": model}, [event], [measurement],+ mode="robust_ridge", time_origin=0, time_sweep_s=1, time_step_s=1)+++def test_all_declared_clock_trials_are_evaluated():+ result = score(Model())+ assert result["score"] == pytest.approx(0)+ assert result["scoring_assessment"] == {"complete": True, "evaluated_trials": 3,+ "rejected_trials": 0, "unknown_trials": 0, "reasons": []}+++def test_finite_best_does_not_hide_unknown_clock_trial():+ result = score(Model(last_supported=20))+ assert np.isfinite(result["score"])+ assessment = result["scoring_assessment"]+ assert not assessment["complete"]+ assert (assessment["evaluated_trials"], assessment["rejected_trials"], assessment["unknown_trials"]) == (2, 0, 1)+ assert assessment["reasons"] == ["incomplete_ridge_or_trajectory_support"]+++def test_completed_acoustic_rejection_is_classified_without_a_finite_best():+ result = score(Model(), ridge_hz=200, association=True)+ assert result["score"] == -np.inf+ assert result["scoring_assessment"] == {"complete": True, "evaluated_trials": 0,+ "rejected_trials": 3, "unknown_trials": 0, "reasons": ["acoustic_loss_exceeds_limit"]}+++def test_typed_emission_failure_stays_unknown_instead_of_losing_candidate_accounting():+ error = geometry.AcousticSupportError("test-flight", "non_monotone_arrival")+ result = score(Model(error=error))+ assert result["score"] == -np.inf+ assert result["scoring_assessment"] == {"complete": False, "evaluated_trials": 0,+ "rejected_trials": 0, "unknown_trials": 3,+ "reasons": ["test-flight: non_monotone_arrival"]}+++def test_actual_non_monotone_model_exposes_typed_track_identity():+ track = geometry.Track("broken-observations", [0, 1, 2], [0, 0, 0], [0, 0, 0], [9000, 8000, 7000])+ with pytest.raises(geometry.AcousticSupportError) as failure:+ track.acoustic(np.array([1.0]), geometry.ecef(0, 0, 0))+ assert failure.value.track_id == "broken-observations"+ assert failure.value.reason == "non_monotone_arrival"+ assert isinstance(failure.value, ValueError)+++def test_unrelated_value_error_is_not_relabelled_as_trajectory_support():+ with pytest.raises(ValueError, match="configuration defect"):+ score(Model(error=ValueError("configuration defect")))+++def test_empty_clock_domain_is_not_a_vacuous_completed_assessment():+ result = score(Model(), bounds=[5, 6])+ assert result["score"] == -np.inf+ assert result["scoring_assessment"] == {"complete": False, "evaluated_trials": 0,+ "rejected_trials": 0, "unknown_trials": 1, "reasons": ["no_clock_trials"]}