Download scripts/result.py from OneScience-Group/RISE-UNet: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/OneScience-Group/RISE-UNet/resolve/main/scripts/result.py
- Command line
-
hf download hf://OneScience-Group/RISE-UNet/scripts/result.py
-
curl -L -o result.py https://huggingface.co/OneScience-Group/RISE-UNet/resolve/main/scripts/result.py
1.26 kB
| from pathlib import Path | |
| import sys,numpy as np | |
| import matplotlib;matplotlib.use("Agg");import matplotlib.pyplot as plt | |
| ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT)) | |
| from model.rise_unet import load_config,write_json | |
| c=load_config(ROOT);d=np.load(ROOT/c["paths"]["predictions"]);e=d["ensemble"];t=d["target"];mean=e.mean(0);acc=[] | |
| for w in range(5):acc.append(float(np.corrcoef(mean[w].ravel(),t[w].ravel())[0,1])) | |
| crps=(abs(e-t[None]).mean(0)-.5*abs(e[:,None]-e[None,:]).mean((0,1))).mean((1,2));q=np.quantile(t,.2);obs=t<q;hit=mean<q;tp=(obs&hit).sum((1,2));fp=(~obs&hit).sum((1,2));fn=(obs&~hit).sum((1,2));gss=(tp-(tp+fp)*(tp+fn)/obs[0].size)/(tp+fp+fn-(tp+fp)*(tp+fn)/obs[0].size+1e-8);write_json(ROOT/c["paths"]["evaluation"],{"acc":acc,"crps":crps.tolist(),"drought_gss":gss.tolist(),"threshold":"synthetic 20th percentile","synthetic":True});fig,ax=plt.subplots(1,2,figsize=(9,3.5));ax[0].plot(d["lead_weeks"],acc,"o-",label="ACC");ax[0].plot(d["lead_weeks"],crps,"s-",label="CRPS");ax[0].legend();im=ax[1].imshow(mean[2]-t[2],cmap="coolwarm");ax[1].set_title("Week-3 error");fig.colorbar(im,ax=ax[1]);fig.tight_layout();p=ROOT/c["paths"]["figure"];p.parent.mkdir(parents=True,exist_ok=True);fig.savefig(p,dpi=150);print(p) | |