Skip to content

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

Skip flight queries for empty boundary tiles

Cinna Davis489b217f2536
diff --git a/src/dopplergeist/parallel_tiles.py b/src/dopplergeist/parallel_tiles.py
index cd3909f..21f6b8b 100644
--- a/src/dopplergeist/parallel_tiles.py
+++ b/src/dopplergeist/parallel_tiles.py
@@ -6,7 +6,7 @@ import pandas as pd
from .data_access import CachedTerrain, DataUnavailable, FlightIndex
from .finite_search import RetentionLedger
-from .tiled_search import _expanded_bounds, _score, _tracks, tile_points
+from .tiled_search import _expanded_bounds, _sample_tile_terrain, _score, _tile_coordinates, _tracks
class TileFailure(DataUnavailable):
@@ -60,10 +60,10 @@ def score_tile(stage, cells, score_floor=None):
try:
radius = max(event["slant_range_m"][1] for event in state["events"])
- tracks = _tracks(state["indexes"], _expanded_bounds(cells, budget.spacing_m, radius, state["crs"]),
- state["time_range"], budget)
- points = (tile_points(cells, budget.spacing_m, state["bounds"], terrain, state["crs"])
- if tracks else pd.DataFrame())
+ points = _tile_coordinates(cells, budget.spacing_m, state["bounds"], state["crs"])
+ tracks = (_tracks(state["indexes"], _expanded_bounds(cells, budget.spacing_m, radius, state["crs"]),
+ state["time_range"], budget) if len(points) else [])
+ points = _sample_tile_terrain(points, terrain) if tracks else pd.DataFrame()
with tempfile.NamedTemporaryFile(prefix="retention-", suffix=".sqlite",
dir=state["ledger_directory"], delete=False) as handle:
path = Path(handle.name)
diff --git a/src/dopplergeist/tiled_search.py b/src/dopplergeist/tiled_search.py
index d7a2854..57b405b 100644
--- a/src/dopplergeist/tiled_search.py
+++ b/src/dopplergeist/tiled_search.py
@@ -148,15 +148,24 @@ def _to_geographic(crs):
return _cached_to_geographic(crs)
-def tile_points(cells, spacing, bounds, terrain, crs):
+def _tile_coordinates(cells, spacing, bounds, crs):
x0, y0, x1, y1 = cells
x, y = np.meshgrid(np.arange(x0, x1, dtype=np.int64), np.arange(y0, y1, dtype=np.int64))
x, y = x.ravel() * spacing, y.ravel() * spacing
lon, lat = _to_geographic(crs).transform(x, y)
keep = (lon >= bounds[0]) & (lon <= bounds[2]) & (lat >= bounds[1]) & (lat <= bounds[3])
x, y, lat, lon = (a[keep] for a in (x, y, lat, lon))
- return pd.DataFrame({"point_id": np.arange(len(x)), "x": x, "y": y, "lat": lat, "lon": lon,
- "elev_m": terrain.sample(lat, lon) if len(lat) else np.array([])})
+ return pd.DataFrame({"point_id": np.arange(len(x)), "x": x, "y": y, "lat": lat, "lon": lon})
+
+
+def _sample_tile_terrain(points, terrain):
+ points["elev_m"] = (terrain.sample(points.lat.to_numpy(), points.lon.to_numpy())
+ if len(points) else np.array([]))
+ return points
+
+
+def tile_points(cells, spacing, bounds, terrain, crs):
+ return _sample_tile_terrain(_tile_coordinates(cells, spacing, bounds, crs), terrain)
def _expanded_bounds(cells, spacing, radius, crs):
@@ -620,8 +629,10 @@ def search_national(indexes, terrain, events, measurements, *, time_range_s, out
resumed += 1
restore_terrain(payload)
else:
- tracks = _tracks(indexes, _expanded_bounds(cells, budget.spacing_m, radius, crs), time_range_s, budget)
- points = tile_points(cells, budget.spacing_m, bounds, terrain, crs) if tracks else pd.DataFrame()
+ points = _tile_coordinates(cells, budget.spacing_m, bounds, crs)
+ tracks = (_tracks(indexes, _expanded_bounds(cells, budget.spacing_m, radius, crs), time_range_s, budget)
+ if len(points) else [])
+ points = _sample_tile_terrain(points, terrain) if tracks else pd.DataFrame()
if len(points):
rows, counts = _score(points, tracks, events, measurements, budget, parameters, filters, start_window,
ledger=ledger, stage=stage,
diff --git a/tests/test_real_empty_tile.py b/tests/test_real_empty_tile.py
new file mode 100644
index 0000000..ead1e2f
--- /dev/null
+++ b/tests/test_real_empty_tile.py
@@ -0,0 +1,41 @@
+"""Optional regression for an empty boundary tile in the real full-day run."""
+import json
+import os
+from pathlib import Path
+
+import pytest
+
+from dopplergeist.data_access import DataUnavailable, FlightIndex
+from dopplergeist.matching import prepare_events
+from dopplergeist.parallel_tiles import initialize_tile_worker, score_tile
+from dopplergeist.tiled_search import SearchBudget, _expanded_bounds, _tile_coordinates, _tracks, grid_tiles
+
+
+def test_real_empty_boundary_tile_does_not_load_overloaded_tracks(tmp_path):
+ job = os.environ.get("DOPPLERGEIST_REAL_JOB_ROOT")
+ cache = os.environ.get("DOPPLERGEIST_REAL_CACHE_ROOT")
+ if not job or not cache:
+ pytest.skip("set the real job and cache roots")
+ job, cache = Path(job), Path(cache)
+ manifest = json.loads((job / "search/manifest.json").read_text())
+ config = manifest["configuration"]
+ budget = SearchBudget(**config["budget"])
+ cells = dict(grid_tiles(config["bounds"], budget.spacing_m, budget.tile_cells, config["crs"]))["-19_51"]
+ assert len(_tile_coordinates(cells, budget.spacing_m, config["bounds"], config["crs"])) == 0
+ paths = [cache / "flights" / day / "staging-0/all-types-v2-543f483cee75.sqlite"
+ for day in ("2026-09-08", "2026-09-09")]
+ events, measurements = prepare_events(json.loads((job / "discovery/discovery.json").read_text())["events"])
+ radius = max(event["slant_range_m"][1] for event in events)
+ with pytest.raises(DataUnavailable, match="Tile track/sample memory budget exceeded"):
+ _tracks([FlightIndex(path) for path in paths],
+ _expanded_bounds(cells, budget.spacing_m, radius, config["crs"]), config["time_range_s"], budget)
+ parameters = dict(config["scoring"])
+ window = parameters.pop("recording_start_window_s", None)
+ initialize_tile_worker(paths, cache / "terrain", {"offline": True}, events, measurements,
+ config["bounds"], config["time_range_s"], budget, parameters, config["filters"],
+ window, config["crs"], tmp_path, manifest["run_hash"],
+ "matched_group_support_minus_normalized_residual")
+ payload, _ = score_tile("coarse:-19_51", cells)
+ assert payload["grid_points"] == payload["tracks"] == 0
+ assert payload["ranked"] == []
+ assert payload["retention_checksum"]