Spaces:
Runtime error
Runtime error
| """Generate 128×128 union impact thumbnail for WhatsApp mockup attachment label.""" | |
| from pathlib import Path | |
| import geopandas as gpd | |
| import matplotlib.pyplot as plt | |
| from src.config import DECK_SEVERITY_COLORS, PROCESSED_UNIONS | |
| def generate_micro_map(union_name: str, severity: str, out_dir: Path) -> Path: | |
| out_dir.mkdir(parents=True, exist_ok=True) | |
| out = out_dir / f"micro_{union_name.replace(' ', '_')}.png" | |
| if out.exists(): | |
| return out | |
| gdf = gpd.read_file(PROCESSED_UNIONS) | |
| row = gdf[gdf["union_name"] == union_name] | |
| if row.empty: | |
| return out | |
| fig, ax = plt.subplots(figsize=(1.28, 1.28), dpi=100) | |
| color = DECK_SEVERITY_COLORS.get(severity, [128, 128, 128, 255]) | |
| row.plot(ax=ax, color=[c / 255 for c in color[:3]], edgecolor="white", linewidth=0.5) | |
| ax.axis("off") | |
| fig.savefig(out, bbox_inches="tight", pad_inches=0, facecolor="#0B141A") | |
| plt.close(fig) | |
| return out | |