Skip to content

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

Preserve compatible prepared indexes after cache change (#307)

Cinna Davise8b8ae837812
diff --git a/docs/DATA_AND_SCALE.md b/docs/DATA_AND_SCALE.md
index ae35021..aae4086 100644
--- a/docs/DATA_AND_SCALE.md
+++ b/docs/DATA_AND_SCALE.md
@@ -28,6 +28,10 @@ global segment remains in the index, and queries outside that warm scope use the
verified original payload. This reduces first-use cache construction without
changing source coverage or filtering aircraft. `FlightIndex.prepare` also accepts
`prepare_scope=(bounds_wsen, time_range_s)` for an explicitly scoped index copy.
+Prepared indexes from the source versions immediately before and after the
+cache-size change remain usable when the exact source and all other builder
+identities match. Unknown source versions continue to use the verified original
+payload instead of trusting incompatible prepared data.
Decoded tracks also have a bounded 128 MiB serialized cache per index per worker,
with at most 2,048 entries. `FlightIndex(track_cache_bytes=...)` accepts a smaller
diff --git a/src/dopplergeist/data_access.py b/src/dopplergeist/data_access.py
index 92d863e..b3c0e6f 100644
--- a/src/dopplergeist/data_access.py
+++ b/src/dopplergeist/data_access.py
@@ -146,8 +146,8 @@ _CANONICAL_TRACK = Track
_PREPARED_ERROR_POLICY = {"divide": "warn", "over": "warn", "under": "ignore", "invalid": "warn"}
-@lru_cache(maxsize=1)
-def _prepared_track_identity():
+@lru_cache(maxsize=4)
+def _prepared_track_identity(data_access_digest=None):
"""Use prepared velocities only with identical normalization and NumPy."""
from . import flight_payload
try:
@@ -157,7 +157,10 @@ def _prepared_track_identity():
files = (Path(__file__), Path(__file__).with_name("tracks.py"),
Path(__file__).with_name("geometry.py"), Path(flight_payload.__file__),
Path(numpy_core.__file__))
- return content_hash({"sources": [sha256(path) for path in files],
+ sources = [sha256(path) for path in files]
+ if data_access_digest is not None:
+ sources[0] = data_access_digest
+ return content_hash({"sources": sources,
"numpy": np.__version__,
"pandas": pd.__version__, "python": sys.version,
"cpu": getattr(numpy_core, "__cpu_features__", {})})
@@ -536,9 +539,17 @@ class FlightIndex:
if report is None:
report = json.loads(db.execute("SELECT value FROM metadata").fetchone()[0])
prepared = report.get("prepared_tracks") if isinstance(report, dict) else None
- if (not isinstance(prepared, dict) or prepared.get("version") != 1
- or prepared.get("builder") != _prepared_track_identity()):
+ if not isinstance(prepared, dict) or prepared.get("version") != 1:
return False
+ builder = prepared.get("builder")
+ identity = _prepared_track_identity()
+ if builder != identity:
+ from .index_compatibility import PREPARED_DATA_ACCESS_EQUIVALENCE
+ current = sha256(Path(__file__))
+ previous = PREPARED_DATA_ACCESS_EQUIVALENCE.get(current, ())
+ if (_prepared_track_identity(current) != identity
+ or all(_prepared_track_identity(source) != builder for source in previous)):
+ return False
columns = [(row[1], row[2].upper(), row[5]) for row in
db.execute("PRAGMA table_info(prepared_tracks)")]
return columns == [("id", "INTEGER", 1), ("source_hash", "TEXT", 0),
diff --git a/src/dopplergeist/index_compatibility.py b/src/dopplergeist/index_compatibility.py
new file mode 100644
index 0000000..9f9aa41
--- /dev/null
+++ b/src/dopplergeist/index_compatibility.py
@@ -0,0 +1,10 @@
+"""Source-pinned equivalent prepared-index normalization implementations."""
+
+# The cache-size-only change and this exact compatibility check do not change
+# decoded observations or normalization. Any source edit disables this mapping.
+PREPARED_DATA_ACCESS_EQUIVALENCE = {
+ "275e38a37f82993b609b6b78c113d35c4da269083ceb3afcb1d94ada48bdc0d4": (
+ "dad02d09d89ad9d267cd8d0424b8e018d0399a28d6b43903b5a55867290b3957",
+ "d664caf4b496599d29a81360c4a9d9736a3248c157e71d885463b349aad6dd36",
+ ),
+}
diff --git a/tests/test_real_prepared_compatibility.py b/tests/test_real_prepared_compatibility.py
new file mode 100644
index 0000000..940bb34
--- /dev/null
+++ b/tests/test_real_prepared_compatibility.py
@@ -0,0 +1,31 @@
+"""Optional previous-source prepared-index regression on archived aircraft."""
+import os
+from pathlib import Path
+
+import pytest
+
+from dopplergeist import data_access, index_compatibility
+from test_real_prepared_index import signature
+
+
[email protected]("variable", ["DOPPLERGEIST_REAL_PREPARED_BEFORE_CACHE", "DOPPLERGEIST_REAL_PREPARED_AFTER_CACHE"])
+def test_prior_prepared_index_is_reused_only_for_pinned_sources(variable, monkeypatch):
+ value = os.environ.get(variable)
+ if not value:
+ pytest.skip("set real prepared indexes made before and after the cache-size change")
+ path = Path(value)
+ prepared = data_access.FlightIndex(path, track_cache_bytes=0)
+ assert prepared._prepared_tracks
+ scope = prepared.report["prepared_tracks"]["scope"]
+ raw = data_access.FlightIndex(path, track_cache_bytes=0)
+ raw._prepared_tracks = False
+ expected = list(raw.query(scope["bounds"], scope["time_range_s"]))
+ actual = list(prepared.query(scope["bounds"], scope["time_range_s"]))
+ assert expected
+ assert [signature(track) for track in actual] == [signature(track) for track in expected]
+ with monkeypatch.context() as patch:
+ patch.setattr(index_compatibility, "PREPARED_DATA_ACCESS_EQUIVALENCE", {})
+ assert not data_access.FlightIndex(path, track_cache_bytes=0)._prepared_tracks
+ with monkeypatch.context() as patch:
+ patch.setattr(data_access, "_prepared_track_identity", lambda *args: "different-runtime")
+ assert not data_access.FlightIndex(path, track_cache_bytes=0)._prepared_tracks