import numpy as np

def build_atlas(history, municipios):
    H = history[-1]["H"].cpu().numpy()
    I = history[-1]["I"].cpu().numpy()

    atlas = []

    for i, mun in enumerate(municipios):
        h = H[i]
        i_ = I[i]

        if h > i_ * 1.5:
            regime = "CHAOTIC"
        elif i_ > h * 1.5:
            regime = "RIGID"
        else:
            regime = "METASTABLE"

        atlas.append({
            "municipio": mun,
            "H": h,
            "I": i_,
            "regime": regime
        })

    return atlas
