Context: Build a spatial risk assessment system correlating air quality data with children's respiratory disease incidence across Wuhan. Approach: FastAPI backend serving PostGIS spatial queries, React frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline for multi-day (1d/3d/7d) risk prediction. Changes: - backend/ — FastAPI API with auth (JWT), alerts, risk analysis, geocoded case data, grid statistics, and report endpoints - frontend/ — React dashboard with interactive risk maps, alert monitoring, district comparison charts, and timeline player - models/ — SpatialTemporalGCN model with trained weights and ONNX export for inference - scripts/ — ETL pipeline for weather + medical data, grid generation, feature engineering, training, and daily inference - deploy/ — Docker Compose configs for backend, frontend, and MLflow - docs/ — API docs, deployment guide, user guide, and code review Impact: Enables spatial risk visualization, alert monitoring, and ML-driven health risk forecasting for environmental health teams.
54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
"""
|
|
GeoJSON file parsing utilities.
|
|
"""
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
from config import WUHAN_BOUNDARY_PATH
|
|
from utils.risk import risk_value_to_level
|
|
|
|
|
|
def parse_geojson_file(filepath: Path) -> list[dict[str, Any]]:
|
|
"""Parse GeoJSON file and extract grid data with standard fields."""
|
|
with open(filepath, "r", encoding="utf-8") as f:
|
|
geojson = json.load(f)
|
|
|
|
grids: list[dict[str, Any]] = []
|
|
for feature in geojson.get("features", []):
|
|
props = feature.get("properties", {})
|
|
coords = feature.get("geometry", {}).get("coordinates", [0, 0])
|
|
|
|
risk_1d = props.get("risk_1d", 0)
|
|
grids.append({
|
|
"grid_id": str(props.get("node_id", "")),
|
|
"latitude": props.get("lat", coords[1] if len(coords) > 1 else 0),
|
|
"longitude": props.get("lon", coords[0] if len(coords) > 0 else 0),
|
|
"risk_value": risk_1d,
|
|
"risk_3d": props.get("risk_3d", 0),
|
|
"risk_7d": props.get("risk_7d", 0),
|
|
"risk_level": risk_value_to_level(risk_1d),
|
|
})
|
|
|
|
return grids
|
|
|
|
|
|
def load_districts() -> list[dict[str, Any]]:
|
|
"""Load Wuhan district boundaries from GeoJSON."""
|
|
if not WUHAN_BOUNDARY_PATH.exists():
|
|
return []
|
|
|
|
with open(WUHAN_BOUNDARY_PATH, "r", encoding="utf-8") as f:
|
|
geojson = json.load(f)
|
|
|
|
districts = []
|
|
for feature in geojson.get("features", []):
|
|
props = feature.get("properties", {})
|
|
districts.append({
|
|
"name": props.get("name", ""),
|
|
"adcode": props.get("adcode", ""),
|
|
"coordinates": feature.get("geometry", {}).get("coordinates", []),
|
|
})
|
|
|
|
return districts
|