Spaces:
Runtime error
Runtime error
File size: 935 Bytes
d64c823 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | """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
|