ACE2-Seasonal / scripts /result.py
zhangrenchao's picture
Publish ACE2-Seasonal reproduction
01fa30d verified
Raw
History Blame Contribute Delete
1.17 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.ace2_seasonal 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);rmse=np.sqrt(np.mean((mean-t)**2,axis=(1,2,3)));spread=np.sqrt(np.mean(e.std(0)**2,axis=(1,2,3)));nao=mean[:,0,:,:8].mean((1,2))-mean[:,0,:,8:].mean((1,2));truth=t[:,0,:,:8].mean((1,2))-t[:,0,:,8:].mean((1,2));corr=float(np.corrcoef(nao,truth)[0,1]);write_json(ROOT/c["paths"]["evaluation"],{"rmse":rmse.tolist(),"ensemble_spread":spread.tolist(),"nao_correlation":corr,"members":64,"is_complete_global":False,"synthetic":True});fig,ax=plt.subplots(1,2,figsize=(9,3.5));ax[0].plot(d["lead_hours"],rmse,label="RMSE");ax[0].plot(d["lead_hours"],spread,label="spread");ax[0].legend();ax[1].plot(nao,label="forecast");ax[1].plot(truth,label="target");ax[1].legend();ax[1].set_title("NAO proxy");fig.tight_layout();p=ROOT/c["paths"]["figure"];p.parent.mkdir(parents=True,exist_ok=True);fig.savefig(p,dpi=150);print(p)