Skip to content

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

Render the fitted emission-time source drift in replay overlays (#8)

Cinna Davis18ff60a182cb
diff --git a/docs/MATCHING.md b/docs/MATCHING.md
index 3f115ed..4887367 100644
--- a/docs/MATCHING.md
+++ b/docs/MATCHING.md
@@ -128,3 +128,11 @@ and flight heights must already share a defensible ellipsoidal datum. Geometric
interpolation remains labelled and subject to the declared perturbation range.
Terrain must expose an applied geoid conversion or an explicit ellipsoidal-datum
declaration; an unlabelled constant/raster surface keeps the envelope incomplete.
+
+`predict_fitted_ridge(track, observer_ecef, absolute_receive_times_s,
+event_diagnostics)` evaluates the frozen fitted model, including source drift at
+emission time. Diagnostics retain `source_reference_emission_time_s` and
+`source_span_s`; a drifting fit without its reference fails explicitly.
+Unsupported times remain NaN. The legacy replay plotter uses this helper for
+the scored curve. Older historical PNGs that drew only `f0 * factor` remain
+unchanged and are approximations when their associated fit includes drift.
diff --git a/src/aircraft_geoloc/matching.py b/src/aircraft_geoloc/matching.py
index a854b2d..bc249c5 100644
--- a/src/aircraft_geoloc/matching.py
+++ b/src/aircraft_geoloc/matching.py
@@ -56,6 +56,16 @@ def _altitude_bias(track, bias_m):
return shifted
+def predict_fitted_ridge(track, observer, receive_times_s, diagnostics, c=343.0):
+ """Render the frozen fitted source model; unsupported track times stay NaN."""
+ factor, emitted, _ = track.acoustic(receive_times_s, observer, c)
+ slope = diagnostics.get("source_drift_hz_s", 0.0)
+ if slope and "source_reference_emission_time_s" not in diagnostics:
+ raise ValueError("A drifting-source prediction needs its fitted emission-time reference")
+ reference = diagnostics.get("source_reference_emission_time_s", 0.0)
+ return factor*(diagnostics["f0_hz"]+slope*(emitted-reference))
+
+
def association_candidates(table, events, offset_tolerance_s=5.0, time_origin=None,
time_tolerance_s=5.0, silence=None, min_events=1,
max_events=3, max_candidates=20000):
@@ -219,6 +229,8 @@ def fit_ridge(track, observer, measurement, start_time, f0_bounds, c=343.0,
penalty = (2 * sigma_hz * drift / cap)**2 / independent_samples if cap else 0.0
return {"score": -float(np.sqrt(loss + penalty)), "f0_hz": float(fit[0]),
"source_drift_hz": drift, "source_drift_hz_s": drift / span,
+ "source_reference_emission_time_s": float((emission.min()+emission.max())/2),
+ "source_span_s": span,
"drift_bound_hz": float(cap), "drift_at_bound": bool(cap and abs(drift) > 0.99 * cap),
"rmse_hz": float(np.sqrt(np.average(residual**2, weights=w))),
"support_fraction": 1.0, "sample_count": int(len(y)),
diff --git a/src/aircraft_geoloc/pipeline.py b/src/aircraft_geoloc/pipeline.py
index 6b0bab2..00eaf4c 100644
--- a/src/aircraft_geoloc/pipeline.py
+++ b/src/aircraft_geoloc/pipeline.py
@@ -168,13 +168,16 @@ def plot_results(output,ranked,tracks,measurements,c=343.0):
fig.savefig(output/"location-scores.png",dpi=160)
plt.close(fig)
lookup={t.id:t for t in tracks}
+ from .matching import predict_fitted_ridge
for i,(spec,ridge,weight,fit) in enumerate(measurements):
best=ranked[0]
track=lookup[best["flight_ids"][i]]
- factor,_,_=track.acoustic(best["recording_start_time_s"]+spec.time,ecef(best["lat"],best["lon"],best["elev_m"]),c)
+ diagnostics=dict(best.get("event_diagnostics", [{} for _ in measurements])[i],f0_hz=best["f0_hz"][i])
+ predicted=predict_fitted_ridge(track,ecef(best["lat"],best["lon"],best["elev_m"]),
+ best["recording_start_time_s"]+spec.time,diagnostics,c)
fig,ax=plt.subplots(figsize=(10,4),layout="constrained")
ax.pcolormesh(spec.time,spec.frequency,spec.contrast,shading="auto",cmap="magma",vmin=0,vmax=6)
- ax.plot(spec.time,best["f0_hz"][i]*factor,color="cyan",lw=1.1,label="Best physical model")
+ ax.plot(spec.time,predicted,color="cyan",lw=1.1,label="Best physical model")
ax.set(xlabel="Recording time (s)",ylabel="Frequency (Hz)",title=f"Event {i+1}: shared clock, {track.id}")
ax.legend(loc="upper right")
fig.savefig(output/f"event-{i+1}-best-model.png",dpi=160)
diff --git a/tests/test_matching.py b/tests/test_matching.py
index 4eae6a0..358a9d9 100644
--- a/tests/test_matching.py
+++ b/tests/test_matching.py
@@ -266,3 +266,23 @@ def test_unestablished_flight_datum_prevents_complete_sensitivity():
assert not result["sensitivity"]["complete"]
assert result["sensitivity"]["altitude_basis"]["a"] == ["barometric", "unspecified"]
assert any("datum" in p["reason"] for p in result["sensitivity"]["failures"])
+
+
+def test_overlay_prediction_uses_fitted_emission_drift_and_preserves_support():
+ from aircraft_geoloc.matching import predict_fitted_ridge
+ epoch = 1_790_000_000.0
+ measured = measurement(drift=1.8)
+ track = Flyover(epoch+30)
+ fit = fit_ridge(track, None, measured, epoch, [118, 122])
+ predicted = predict_fitted_ridge(track, None, epoch+measured[0].time, fit)
+ rms = np.sqrt(np.mean((predicted-measured[1])**2))
+ assert abs(rms-fit["rmse_hz"]) < 1e-10
+ assert rms < 0.1
+ constant = fit["f0_hz"]*track.acoustic(epoch+measured[0].time, None, 343)[0]
+ assert np.sqrt(np.mean((constant-measured[1])**2)) > 0.4
+ assert epoch < fit["source_reference_emission_time_s"] < epoch+60
+ limited = Flyover(epoch+30, support=epoch+54)
+ assert np.isnan(predict_fitted_ridge(limited, None, [epoch+55], fit)[0])
+ incomplete = {k:v for k,v in fit.items() if k != "source_reference_emission_time_s"}
+ with pytest.raises(ValueError, match="reference"):
+ predict_fitted_ridge(track, None, epoch+measured[0].time, incomplete)