feat: toggleable live map feeds (ADS-B, trains, AIS, radar, WFIGS, NWS)
Wire the free data streams from docs/free-data-streams.md into the dashboard as layer-panel toggles. Third-party APIs are proxied/cached in FastAPI; raster tiles (IEM, RainViewer, GIBS) stay in the browser. - Aircraft via ADSB.lol viewport poll (bbox required, radius ≤ 150 nm) - Amtraker trains, NHC storms, WFIGS incidents/perimeters - NWS + IEM SBW as /api/weather-alerts (does not collide with /api/alerts) - AISStream worker is server-side only and idles without AISSTREAM_API_KEY - Caltrans CWWP2 D1–D12 camera parser; FIRMS dual-write NOAA-20/21
This commit is contained in:
parent
47628cc5f2
commit
f779b1f225
15 changed files with 1662 additions and 39 deletions
131
app/main.py
131
app/main.py
|
|
@ -44,6 +44,11 @@ from ingestor import ingest_event, fetch_and_process
|
|||
from sources import ingest_rss_feed, ingest_gdelt, ingest_earthquakes, ingest_social_signals
|
||||
from fire_sources import ingest_fires
|
||||
from keystore import KeyFormatError, delete_key, list_keys, set_key
|
||||
from live_layers import (
|
||||
fetch_aircraft, fetch_fire_incidents, fetch_fire_perimeters,
|
||||
fetch_radar_meta, fetch_storms, fetch_trains, fetch_vessels,
|
||||
fetch_weather_alerts, overlay_catalog, parse_bbox,
|
||||
)
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = structlog.get_logger("osint.dashboard")
|
||||
|
|
@ -136,6 +141,10 @@ async def startup():
|
|||
head) before uvicorn starts, so they don't run nested inside the event loop.
|
||||
"""
|
||||
await init_extensions()
|
||||
from config import AISSTREAM_IN_APP
|
||||
if AISSTREAM_IN_APP:
|
||||
from ais_stream import run_ais_worker
|
||||
asyncio.create_task(run_ais_worker())
|
||||
|
||||
|
||||
# ── Feed Sources ──────────────────────────────────────────────────────────
|
||||
|
|
@ -1013,6 +1022,13 @@ async def index():
|
|||
|
||||
# ── NASA GIBS basemap map tab ─────────────────────────────────────────────
|
||||
|
||||
def _parse_bbox_query(bbox: str) -> tuple[float, float, float, float]:
|
||||
try:
|
||||
return parse_bbox(bbox)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(422, str(exc)) from exc
|
||||
|
||||
|
||||
@app.get("/api/map/layers")
|
||||
async def map_layers():
|
||||
"""Curated NASA GIBS raster basemap layers for the map tab.
|
||||
|
|
@ -1024,9 +1040,122 @@ async def map_layers():
|
|||
format — tile image extension (jpeg|png)
|
||||
has_time — whether the layer has a Time dimension (=> date selector)
|
||||
max_zoom — highest native zoom served by that tile matrix set
|
||||
|
||||
``overlays`` lists toggleable live feeds (radar tiles, aircraft, …).
|
||||
"""
|
||||
from gibs_map import MAP_LAYERS
|
||||
return {"layers": MAP_LAYERS}
|
||||
return {"layers": MAP_LAYERS, "overlays": overlay_catalog()}
|
||||
|
||||
|
||||
def _upstream_or_502(exc: Exception, name: str):
|
||||
logger.warning("live_layer_upstream_failed", layer=name, error=str(exc))
|
||||
raise HTTPException(502, f"{name} upstream unavailable: {exc}") from exc
|
||||
|
||||
|
||||
@app.get("/api/map/radar")
|
||||
async def map_radar():
|
||||
"""RainViewer frame list + IEM NEXRAD tile template. Browser fetches tiles."""
|
||||
try:
|
||||
return await fetch_radar_meta()
|
||||
except Exception as exc:
|
||||
_upstream_or_502(exc, "radar")
|
||||
|
||||
|
||||
@app.get("/api/aircraft")
|
||||
async def list_aircraft(
|
||||
bbox: str = Query(..., description="minlon,minlat,maxlon,maxlat"),
|
||||
limit: int = Query(2000, ge=1, le=5000),
|
||||
):
|
||||
"""Viewport ADS-B last-known (ADSB.lol). Requires bbox; radius clamped ≤ 150 nm."""
|
||||
_parse_bbox_query(bbox)
|
||||
try:
|
||||
return await fetch_aircraft(bbox, limit)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(422, str(exc)) from exc
|
||||
except Exception as exc:
|
||||
_upstream_or_502(exc, "aircraft")
|
||||
|
||||
|
||||
@app.get("/api/trains")
|
||||
async def list_trains(
|
||||
bbox: str | None = Query(None, description="minlon,minlat,maxlon,maxlat"),
|
||||
limit: int = Query(2000, ge=1, le=5000),
|
||||
):
|
||||
"""Amtrak / Brightline / VIA last-known (Amtraker). Bbox optional (~200 rows)."""
|
||||
if bbox:
|
||||
_parse_bbox_query(bbox)
|
||||
try:
|
||||
return await fetch_trains(bbox, limit)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(422, str(exc)) from exc
|
||||
except Exception as exc:
|
||||
_upstream_or_502(exc, "trains")
|
||||
|
||||
|
||||
@app.get("/api/vessels")
|
||||
async def list_vessels(
|
||||
bbox: str | None = Query(None, description="minlon,minlat,maxlon,maxlat"),
|
||||
limit: int = Query(2000, ge=1, le=5000),
|
||||
):
|
||||
"""AIS last-known from the server-side AISStream worker. Empty without a key."""
|
||||
if bbox:
|
||||
_parse_bbox_query(bbox)
|
||||
try:
|
||||
return await fetch_vessels(bbox, limit)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(422, str(exc)) from exc
|
||||
|
||||
|
||||
@app.get("/api/fire-incidents")
|
||||
async def list_fire_incidents(
|
||||
bbox: str | None = Query(None),
|
||||
limit: int = Query(2000, ge=1, le=5000),
|
||||
):
|
||||
"""NIFC WFIGS current incident points."""
|
||||
if bbox:
|
||||
_parse_bbox_query(bbox)
|
||||
try:
|
||||
return await fetch_fire_incidents(bbox, limit)
|
||||
except Exception as exc:
|
||||
_upstream_or_502(exc, "fire-incidents")
|
||||
|
||||
|
||||
@app.get("/api/fire-perimeters")
|
||||
async def list_fire_perimeters(bbox: str | None = Query(None)):
|
||||
"""NIFC WFIGS current wildfire perimeters (GeoJSON)."""
|
||||
if bbox:
|
||||
_parse_bbox_query(bbox)
|
||||
try:
|
||||
return await fetch_fire_perimeters(bbox)
|
||||
except Exception as exc:
|
||||
_upstream_or_502(exc, "fire-perimeters")
|
||||
|
||||
|
||||
@app.get("/api/weather-alerts")
|
||||
async def list_weather_alerts(
|
||||
area: str | None = Query(None, description="US state two-letter code, e.g. NC"),
|
||||
bbox: str | None = Query(None, description="minlon,minlat,maxlon,maxlat"),
|
||||
):
|
||||
"""Cached NWS active alerts + IEM storm-based warning polygons.
|
||||
|
||||
Named ``/api/weather-alerts`` so it does not collide with dashboard
|
||||
``/api/alerts`` (entity/keyword alert records).
|
||||
"""
|
||||
if bbox:
|
||||
_parse_bbox_query(bbox)
|
||||
try:
|
||||
return await fetch_weather_alerts(area, bbox)
|
||||
except Exception as exc:
|
||||
_upstream_or_502(exc, "weather-alerts")
|
||||
|
||||
|
||||
@app.get("/api/storms")
|
||||
async def list_storms():
|
||||
"""NHC active tropical cyclones."""
|
||||
try:
|
||||
return await fetch_storms()
|
||||
except Exception as exc:
|
||||
_upstream_or_502(exc, "storms")
|
||||
|
||||
|
||||
@app.get("/api/map/times")
|
||||
|
|
|
|||
Loading…
Reference in a new issue