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.
81 lines
2.6 KiB
Python
81 lines
2.6 KiB
Python
"""
|
|
Centralized configuration and named constants for CBPOA backend.
|
|
Eliminates magic numbers scattered across routers.
|
|
"""
|
|
from pathlib import Path
|
|
|
|
# ============================================================================
|
|
# Paths
|
|
# ============================================================================
|
|
|
|
PROJECT_ROOT = Path(__file__).parent.parent
|
|
DATA_DIR = PROJECT_ROOT / "outputs" / "daily"
|
|
REPORTS_DIR = PROJECT_ROOT / "outputs" / "reports"
|
|
WUHAN_BOUNDARY_PATH = PROJECT_ROOT / "Datas" / "武汉市.geojson"
|
|
PRECOMPUTED_GRID_PATH = PROJECT_ROOT / "outputs" / "grid_risk_summary.csv"
|
|
|
|
# ============================================================================
|
|
# Wuhan Geographic Bounds
|
|
# ============================================================================
|
|
|
|
WUHAN_BOUNDS = {
|
|
"min_lon": 113.702281,
|
|
"max_lon": 115.082378,
|
|
"min_lat": 29.969132,
|
|
"max_lat": 31.361260,
|
|
}
|
|
|
|
# 100m grid step in degrees (at Wuhan center latitude ~30.66)
|
|
LAT_STEP = 0.0009
|
|
LON_STEP = 0.001046
|
|
|
|
# ============================================================================
|
|
# Risk Thresholds
|
|
# ============================================================================
|
|
|
|
RISK_HIGH = 0.8
|
|
RISK_MEDIUM_HIGH = 0.6
|
|
RISK_MEDIUM = 0.4
|
|
RISK_MEDIUM_LOW = 0.2
|
|
|
|
# ============================================================================
|
|
# LOD Configuration
|
|
# ============================================================================
|
|
|
|
LOD_GRID_DIMS = {
|
|
"lod1": {"lat_count": 100, "lon_count": 150},
|
|
"lod2": {"lat_count": 250, "lon_count": 350},
|
|
"lod3": {"lat_count": 1400, "lon_count": 2000},
|
|
}
|
|
|
|
LOD_CONFIG = {
|
|
"lod1": {"zoom_range": (1, 9), "aggregate": 200, "name": "coarse"},
|
|
"lod2": {"zoom_range": (10, 13), "aggregate": 50, "name": "medium"},
|
|
"lod3": {"zoom_range": (14, 20), "aggregate": 1, "name": "fine"},
|
|
}
|
|
|
|
# Max radius for KDTree neighbor lookup (degrees, ~5km)
|
|
LOD_MAX_RADIUS = 0.05
|
|
|
|
# ============================================================================
|
|
# Alert Thresholds
|
|
# ============================================================================
|
|
|
|
ALERT_P1_RISK = 0.8
|
|
ALERT_P2_RISK = 0.6
|
|
ALERT_RISK_7D_WEIGHT = 0.5
|
|
MAX_ALERTS = 2000
|
|
|
|
# ============================================================================
|
|
# Trend Analysis
|
|
# ============================================================================
|
|
|
|
TREND_SLOPE_THRESHOLD = 0.05
|
|
|
|
# ============================================================================
|
|
# Date Format
|
|
# ============================================================================
|
|
|
|
DATE_FORMAT_GEOJSON = "%Y%m%d"
|
|
DATE_FORMAT_ISO = "%Y-%m-%d"
|