Skip to content

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

Report search progress as tiles finish (#10)

Cinna Davis6dcd9ad969a0
diff --git a/src/dopplergeist/automatic.py b/src/dopplergeist/automatic.py
index 8e4ecd1..eb9189d 100644
--- a/src/dopplergeist/automatic.py
+++ b/src/dopplergeist/automatic.py
@@ -137,9 +137,15 @@ def analyze(request, output_dir, config=None, progress=lambda *args, **kwargs: N
if not events:
return finish("inconclusive", "no_supported_events", "No supported moving-tone Doppler events were discovered in the recording.")
progress("acquisition", 0.35, **state)
+
+ def report_search_progress(fraction=0.0):
+ fraction = min(1.0, max(0.0, float(fraction)))
+ progress("search", 0.55 + 0.29 * fraction, **state)
+
try:
from .data_access import DataUnavailable
- search, prepared_events, measurements, indexes, terrain = _search(request, recording, events, output, config, lambda: progress("search", 0.55, **state))
+ search, prepared_events, measurements, indexes, terrain = _search(
+ request, recording, events, output, config, report_search_progress)
except ImportError as exc:
return finish("failed", "component_unavailable", f"Automatic matching/data components are not installed: {exc}")
except MissingData as exc:
@@ -269,7 +275,8 @@ def _search(request, recording, events, output, config, search_progress):
"recording_start_window_s": [lo, hi]}
report = search_national(indexes, terrain, prepared, measurements, time_range_s=time_range, output_dir=output / "search",
bounds=bounds, budget=SearchBudget(**config.get("search_budget", {})),
- scoring=scoring, filters=filters, input_hashes=hashes)
+ scoring=scoring, filters=filters, input_hashes=hashes,
+ search_progress=search_progress)
write_json(output / "data-provenance.json", {"flight_indexes": [index.report for index in indexes],
"terrain": terrain.provenance() if hasattr(terrain, "provenance") else hashes})
return report, prepared, measurements, indexes, terrain
diff --git a/src/dopplergeist/tiled_search.py b/src/dopplergeist/tiled_search.py
index 57b405b..70f3863 100644
--- a/src/dopplergeist/tiled_search.py
+++ b/src/dopplergeist/tiled_search.py
@@ -465,7 +465,7 @@ def _record_support(output, stage, counts, summary):
def search_national(indexes, terrain, events, measurements, *, time_range_s, output_dir,
bounds=CONUS, budget=None, scoring=None, filters=None, crs="EPSG:5070", input_hashes=None,
- workers=None):
+ workers=None, search_progress=None):
"""Bounded outer driver using existing physical CPA/locked-event scoring.
`events, measurements` come from `matching.prepare_events`. `time_range_s`
@@ -503,6 +503,18 @@ def search_national(indexes, terrain, events, measurements, *, time_range_s, out
from .parallel_tiles import TileFailure, initialize_tile_worker, ordered_tile_results
xmin, ymin, xmax, ymax = _grid_extent(bounds, budget.spacing_m, crs)
total = (xmax // budget.tile_cells - xmin // budget.tile_cells + 1) * (ymax // budget.tile_cells - ymin // budget.tile_cells + 1)
+ coarse_total = min(total, budget.max_tiles or total)
+ last_progress = 0.0
+
+ def report_search_progress(fraction, *, force=False):
+ nonlocal last_progress
+ if search_progress is None:
+ return
+ fraction = min(1.0, max(0.0, float(fraction)))
+ if fraction > last_progress and (force or fraction - last_progress >= 0.025):
+ search_progress(fraction)
+ last_progress = fraction
+
available = len(os.sched_getaffinity(0)) if hasattr(os, "sched_getaffinity") else (os.cpu_count() or 1)
if workers is None:
workers = max(1, available - 1)
@@ -550,7 +562,7 @@ def search_national(indexes, terrain, events, measurements, *, time_range_s, out
else {"robust_ridge": "negative_robust_ridge_loss_hz", "ridge": "negative_ridge_rmse_hz",
"brightness": "summed_spectral_contrast"}[mode])
ledger = RetentionLedger(output / "retention.sqlite", run_hash, score_kind)
- began, ranked, failures, done, resumed, points_searched = time.monotonic(), [], [], 0, 0, 0
+ began, ranked, failures, done, processed, resumed, points_searched = time.monotonic(), [], [], 0, 0, 0, 0
support = dict(unsupported_cpa_track_evaluations=0, unclassified_score_candidates=0,
bounded_score_candidates=0, unbounded_score_candidates=0,
evaluated_trials=0, rejected_trials=0, unknown_trials=0, unreported_trial_envelopes=0)
@@ -657,6 +669,10 @@ def search_national(indexes, terrain, events, measurements, *, time_range_s, out
if isinstance(error, TileFailure):
restore_terrain(error.provenance)
failures.append({"tile": tile_id, "reason": str(error)})
+ processed += 1
+ if coarse_total:
+ report_search_progress(0.8 * processed / coarse_total)
+ report_search_progress(0.8, force=True)
coarse = list(ranked)
# Refine only global finalists; tile selection never controls refinement rank.
refinement_failure = None
@@ -701,6 +717,7 @@ def search_national(indexes, terrain, events, measurements, *, time_range_s, out
ranked = merge_candidates(itertools.chain(ranked, rows), budget.top_k,
ledger=ledger, stage=f"fine-global:{seed_index}:{x0}:{y0}")
completed_rectangles.append((cx - width, cy - width, cx + width + 1, cy + width + 1))
+ report_search_progress(0.8 + 0.2 * (seed_index + 1) / len(chosen))
except (DataUnavailable, ValueError, OSError) as error:
refinement_failure = str(error)
coverage = [i.coverage_for(bounds, time_range_s) for i in indexes]
@@ -766,6 +783,7 @@ def search_national(indexes, terrain, events, measurements, *, time_range_s, out
"bounded_concurrency": workers if parallel else 1, "max_grid_points_per_tile": budget.tile_cells ** 2,
"scoring_time_is_locked": True, "ground_truth_used_by_search": False, "scope": list(bounds)}
write_json(output / "search-report.json", report)
+ report_search_progress(1.0, force=True)
return report