Delta-HBV / scripts /inference.py
zhangrenchao's picture
Publish Delta-HBV reproduction
48fc6c1 verified
Raw
History Blame Contribute Delete
618 Bytes
from pathlib import Path
import sys,numpy as np,torch
R=Path(__file__).resolve().parents[1];sys.path.insert(0,str(R));from model.delta_hbv import *
c=cfg(R);d=np.load(R/c['data']['path']);z=torch.load(R/c['paths']['checkpoint'],map_location='cpu',weights_only=True);m=DeltaHBV(**z['model_config']);m.load_state_dict(z['model'])
with torch.no_grad():q,e=m(torch.tensor(d['forcing']),torch.tensor(d['attributes']))
p=R/c['paths']['predictions'];p.parent.mkdir(parents=True,exist_ok=True);np.savez_compressed(p,streamflow=q.numpy(),target=d['streamflow'],et=e.numpy(),et_target=d['et'],basin_ids=d['basin_ids']);print(p)