Python tool for aircraft Doppler audio geolocation using historical ADS-B flight data (Source-available)
Python acoustic-geolocationads-baircraft-trackingairplaneaudio-forensicsdoppler-effectdoppler-shiftgeolocationosintsignal-processing
Report and verify acoustic bound provenance
Cinna Davis5a1ee866d4a5
diff --git a/scripts/verify_upload_http.py b/scripts/verify_upload_http.pyindex 4191844..6eb224d 100644--- a/scripts/verify_upload_http.py+++ b/scripts/verify_upload_http.py@@ -244,7 +244,9 @@ def bounded_finite_clock_assessment(detail, max_groups):if (not isinstance(assessment, dict) or detail.get("score_kind") != kindor assessment.get("complete") is not Falseor assessment.get("unknown_score_bound_kind") != kind- or assessment.get("unknown_score_bound_method") != "nonnegative_loss_and_validated_event_fits"+ or assessment.get("unknown_score_bound_method") not in+ ("nonnegative_loss_and_validated_event_fits", "group_count_ceiling",+ "nonnegative_loss_validated_fits_and_acoustic_dual")or not isinstance(indices, list) or not indicesor any(type(index) is not int or not 0 <= index < max_groups for index in indices)or indices != sorted(set(indices))):@@ -259,7 +261,21 @@ def bounded_finite_clock_assessment(detail, max_groups):or assessment.get("empty_clock_domain") is not Falseor assessment["scheduled_trials"] != sum(assessment[name] for name in names[1:4])):return False+ method = assessment["unknown_score_bound_method"]+ dual = assessment.get("acoustic_bound_rejected_trials", 0)+ if type(dual) is not int:+ return False+ if method == "nonnegative_loss_validated_fits_and_acoustic_dual":+ if not 0 < dual <= rejected:+ return False+ elif dual != 0:+ return Falseupper = assessment.get("unknown_score_upper_bound")+ if method == "group_count_ceiling":+ return (detail.get("finite_best") is False+ and assessment["evaluated_trials"] == assessment["rejected_trials"] == 0+ and unknown == assessment["scheduled_trials"] and rejected == 0+ and type(upper) in (int, float) and math.isfinite(upper) and upper == len(indices))return (upper is None if rejected == bounded elsetype(upper) in (int, float) and math.isfinite(upper) and 0 <= upper <= len(indices))diff --git a/src/dopplergeist/finite_search.py b/src/dopplergeist/finite_search.pyindex 739f022..d471613 100644--- a/src/dopplergeist/finite_search.py+++ b/src/dopplergeist/finite_search.py@@ -62,7 +62,8 @@ def bounded_assessment(row):or assessment.get("unknown_score_bound_kind") != kindor row.get("score_kind") != kindor assessment.get("unknown_score_bound_method") not in- ("nonnegative_loss_and_validated_event_fits", "group_count_ceiling")+ ("nonnegative_loss_and_validated_event_fits", "group_count_ceiling",+ "nonnegative_loss_validated_fits_and_acoustic_dual")or not isinstance(indices, list) or not indicesor any(type(i) is not int or i < 0 for i in indices) or indices != sorted(set(indices))or len(row.get("flight_ids", [])) != len(indices)):@@ -80,8 +81,17 @@ def bounded_assessment(row):unknown, bounded, rejected = (assessment[k] for k in fields[2:])if not 0 < unknown == bounded or rejected > bounded:return False+ method = assessment["unknown_score_bound_method"]+ dual = assessment.get("acoustic_bound_rejected_trials", 0)+ if type(dual) is not int:+ return False+ if method == "nonnegative_loss_validated_fits_and_acoustic_dual":+ if not 0 < dual <= rejected:+ return False+ elif dual != 0:+ return Falseupper = assessment.get("unknown_score_upper_bound")- if assessment["unknown_score_bound_method"] == "group_count_ceiling":+ if method == "group_count_ceiling":# This method skips every fit, so only the trivial per-group ceiling is valid.return (row.get("score") is Noneand assessment["evaluated_trials"] == 0 and assessment["rejected_trials"] == 0diff --git a/src/dopplergeist/search.py b/src/dopplergeist/search.pyindex acf267e..4d46af3 100644--- a/src/dopplergeist/search.py+++ b/src/dopplergeist/search.py@@ -637,7 +637,8 @@ def score_candidate(candidate, point, tracks, events, measurements, mode="brightbounded_unknown_rejections=sum(value == -np.inf for value in unknown_bounds if value is not None),unknown_score_upper_bound=max(finite_bounds) if finite_bounds else None,unknown_score_bound_kind="matched_group_support_minus_normalized_residual",- unknown_score_bound_method="nonnegative_loss_and_validated_event_fits")+ unknown_score_bound_method=("nonnegative_loss_validated_fits_and_acoustic_dual"+ if dual_pruned else "nonnegative_loss_and_validated_event_fits"))if partial_prunes:assessment["retention_score_floor"] = score_floorassessment["retention_pruned_trials"] = partial_prunesdiff --git a/tests/test_real_dual_provenance.py b/tests/test_real_dual_provenance.pynew file mode 100644index 0000000..86de8b0--- /dev/null+++ b/tests/test_real_dual_provenance.py@@ -0,0 +1,53 @@+"""Bound certificates must describe how actual observations were screened."""+import copy+import importlib.util+import json+import os+from pathlib import Path+from types import SimpleNamespace++import pandas as pd+import pytest++from dopplergeist.data_access import FlightIndex+from dopplergeist.finite_search import bounded_assessment+from dopplergeist.matching import association_candidates, prepare_events+from dopplergeist.search import score_candidate+++def test_real_bound_methods_and_independent_verifier():+ source = os.environ.get("DOPPLERGEIST_REAL_CPA_FIXTURE")+ if not source:+ pytest.skip("set DOPPLERGEIST_REAL_CPA_FIXTURE to the real reference diagnostic")+ fixture = json.loads(Path(source).read_text())+ events, measurements = prepare_events(fixture["events"])+ candidates, _ = association_candidates(pd.DataFrame(fixture["cpa_rows"]), events, max_candidates=20000)+ point = SimpleNamespace(**fixture["point"], x=0.0, y=0.0)+ spec = importlib.util.spec_from_file_location("upload_verifier", Path(__file__).resolve().parents[1] / "scripts/verify_upload_http.py")+ verifier = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(verifier)++ singleton = next(c for c in candidates if len(c["event_indices"]) == 1)+ ceiling = score_candidate(singleton, point, {}, events, measurements, mode="robust_ridge", score_floor=2.0)+ detail = dict(ceiling, finite_best=False)+ assert bounded_assessment(ceiling)+ assert verifier.bounded_finite_clock_assessment(detail, len(events))++ candidate = candidates[287]+ tracks = {track.id: track for track in FlightIndex(fixture["real_index"]).lookup(+ [entry["flight_id"] for entry in candidate["passes"]])}+ row = score_candidate(candidate, point, tracks, events, measurements, mode="robust_ridge", score_floor=0.0)+ assessment = row["scoring_assessment"]+ assert assessment["acoustic_bound_rejected_trials"] > 0+ assert assessment["unknown_score_bound_method"] == "nonnegative_loss_validated_fits_and_acoustic_dual"+ assert bounded_assessment(row)+ assert verifier.bounded_finite_clock_assessment(dict(row, finite_best=False), len(events))++ for field, value in (("acoustic_bound_rejected_trials", True),+ ("acoustic_bound_rejected_trials", 0),+ ("acoustic_bound_rejected_trials", assessment["bounded_unknown_rejections"] + 1),+ ("unknown_score_bound_method", "nonnegative_loss_and_validated_event_fits")):+ invalid = copy.deepcopy(row)+ invalid["scoring_assessment"][field] = value+ assert not bounded_assessment(invalid)+ assert not verifier.bounded_finite_clock_assessment(dict(invalid, finite_best=False), len(events))