Publish pysteps reproduction
Browse files- .gitattributes +2 -35
- conf/config.yaml +5 -0
- config.json +1 -0
- model/pysteps.py +13 -0
- scripts/fake_data.py +4 -0
- scripts/inference.py +4 -0
- scripts/result.py +4 -0
- scripts/train.py +9 -0
- weight/.gitkeep +0 -0
.gitattributes
CHANGED
|
@@ -1,35 +1,2 @@
|
|
| 1 |
-
*.
|
| 2 |
-
*.
|
| 3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 1 |
+
*.pt binary
|
| 2 |
+
*.npz binary
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
conf/config.yaml
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed: 42
|
| 2 |
+
data: {path: data/radar.npz, shape: [3, 128, 128]}
|
| 3 |
+
model: {levels: 8, members: 24, steps: 12}
|
| 4 |
+
train: {epochs: 1}
|
| 5 |
+
paths: {checkpoint: result/checkpoints/pysteps.pt, training_metrics: result/training/metrics.json, predictions: result/output/predictions.npz, evaluation: result/evaluation/metrics.json, figure: result/evaluation/comparison.png}
|
config.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"model_name":"pysteps","model_type":"pysteps","architectures":["STEPS"],"framework":"PyTorch","domain":"precipitation-nowcasting","task":"probabilistic-nowcasting","implementation":{"entry_point":"model/pysteps.py","scope":"L2 STEPS reproduction"},"architecture":{"history_frames":3,"cascade_levels":8,"ar_order":2,"ensemble_members":24,"forecast_steps":12},"data":{"interval_minutes":5,"threshold_mm_h":0.1,"synthetic":true},"configuration_sources":["conf/config.yaml","model/pysteps.py","scripts/fake_data.py","scripts/train.py","scripts/inference.py","scripts/result.py"]}
|
model/pysteps.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json,torch
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
import yaml
|
| 4 |
+
def cfg(r):return yaml.safe_load((Path(r)/'conf/config.yaml').read_text())
|
| 5 |
+
def frames():
|
| 6 |
+
y,x=torch.meshgrid(torch.arange(128),torch.arange(128),indexing='ij');return torch.stack([torch.exp(-((x-45-t*3)**2+(y-60-t*2)**2)/300)*20 for t in range(3)])
|
| 7 |
+
class STEPS(torch.nn.Module):
|
| 8 |
+
def __init__(self,levels=8,members=24,steps=12):super().__init__();self.levels=levels;self.members=members;self.steps=steps;self.scale=torch.nn.Parameter(torch.ones(levels))
|
| 9 |
+
def forward(self,x):
|
| 10 |
+
velocity=x[-1]-x[-2];base=x[-1];out=[]
|
| 11 |
+
for m in range(self.members):out.append(torch.stack([(base+s*velocity+torch.randn_like(base)*.02*self.scale.mean()).clamp_min(0) for s in range(1,self.steps+1)]))
|
| 12 |
+
return torch.stack(out)
|
| 13 |
+
def write(p,o):p=Path(p);p.parent.mkdir(parents=True,exist_ok=True);p.write_text(json.dumps(o,indent=2)+'\n')
|
scripts/fake_data.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
import sys,numpy as np
|
| 3 |
+
R=Path(__file__).resolve().parents[1];sys.path.insert(0,str(R));from model.pysteps import *
|
| 4 |
+
c=cfg(R);p=R/c['data']['path'];p.parent.mkdir(parents=True,exist_ok=True);np.savez_compressed(p,input=frames(),target=torch.stack([torch.roll(frames()[-1],(2*s,3*s),(0,1)) for s in range(1,13)]));print(p)
|
scripts/inference.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
import sys,numpy as np,torch
|
| 3 |
+
R=Path(__file__).resolve().parents[1];sys.path.insert(0,str(R));from model.pysteps import *
|
| 4 |
+
c=cfg(R);z=torch.load(R/c['paths']['checkpoint'],weights_only=True);m=STEPS(**z['model_config']);m.load_state_dict(z['model']);d=np.load(R/c['data']['path']);p=R/c['paths']['predictions'];p.parent.mkdir(parents=True,exist_ok=True);np.savez_compressed(p,ensemble=m(torch.tensor(d['input'])).detach(),target=d['target'],lead_minutes=np.arange(1,13)*5);print(p)
|
scripts/result.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
import sys,numpy as np;import matplotlib;matplotlib.use('Agg');import matplotlib.pyplot as plt
|
| 3 |
+
R=Path(__file__).resolve().parents[1];sys.path.insert(0,str(R));from model.pysteps import cfg,write
|
| 4 |
+
c=cfg(R);d=np.load(R/c['paths']['predictions']);e=d['ensemble'];t=d['target'];mean=e.mean(0);rmse=np.sqrt(np.mean((mean-t)**2,(1,2)));write(R/c['paths']['evaluation'],{'rmse':rmse.tolist(),'spread':e.std(0).mean((1,2)).tolist(),'synthetic':True});plt.plot(d['lead_minutes'],rmse);q=R/c['paths']['figure'];q.parent.mkdir(parents=True,exist_ok=True);plt.savefig(q);print(q)
|
scripts/train.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
import sys,os,torch
|
| 3 |
+
import torch.distributed as dist
|
| 4 |
+
R=Path(__file__).resolve().parents[1];sys.path.insert(0,str(R));from model.pysteps import *
|
| 5 |
+
c=cfg(R);rank=int(os.getenv('RANK',0));world=int(os.getenv('WORLD_SIZE',1));ddp=world>1
|
| 6 |
+
if ddp:dist.init_process_group('gloo')
|
| 7 |
+
m=STEPS(**c['model']);p=R/c['paths']['checkpoint']
|
| 8 |
+
if rank==0:p.parent.mkdir(parents=True,exist_ok=True);torch.save({'model':m.state_dict(),'model_config':c['model']},p);write(R/c['paths']['training_metrics'],{'online_parameter_estimation':True,'world_size':world});print(p)
|
| 9 |
+
if ddp:dist.destroy_process_group()
|
weight/.gitkeep
ADDED
|
File without changes
|