Download scripts/result.py from OneScience-Group/Aardvark-Weather: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/OneScience-Group/Aardvark-Weather/resolve/main/scripts/result.py
- Command line
-
hf download hf://OneScience-Group/Aardvark-Weather/scripts/result.py
-
curl -L -o result.py https://huggingface.co/OneScience-Group/Aardvark-Weather/resolve/main/scripts/result.py
1.4 kB
| """Show the saved Aardvark one-day inference summary.""" | |
| import json | |
| from pathlib import Path | |
| import matplotlib | |
| matplotlib.use("Agg") | |
| import matplotlib.pyplot as plt | |
| import torch | |
| ROOT = Path(__file__).resolve().parents[1] | |
| if __name__ == "__main__": | |
| result_dir = ROOT / "result" | |
| prediction = torch.load(result_dir / "prediction.pt", map_location="cpu", weights_only=True) | |
| target = torch.load(result_dir / "target.pt", map_location="cpu", weights_only=True) | |
| valid = torch.isfinite(target) | |
| rmse = torch.sqrt(torch.mean((prediction[valid] - target[valid]) ** 2)) | |
| mae = torch.mean((prediction[valid] - target[valid]).abs()) | |
| metrics = { | |
| "normalized_rmse": float(rmse), | |
| "normalized_mae": float(mae), | |
| "valid_stations": int(valid.sum()), | |
| "note": "Normalized sample-space metrics; not paper-comparable physical-unit scores.", | |
| } | |
| (result_dir / "metrics.json").write_text(json.dumps(metrics, indent=2) + "\n") | |
| indices = torch.where(valid[0])[0][:300] | |
| plt.figure(figsize=(10, 4)) | |
| plt.plot(target[0, indices], label="Target", linewidth=1) | |
| plt.plot(prediction[0, indices], label="Prediction", linewidth=1) | |
| plt.title(f"Aardvark station temperature (RMSE={rmse:.4f})") | |
| plt.legend() | |
| plt.tight_layout() | |
| plt.savefig(result_dir / "comparison.png", dpi=150) | |
| plt.close() | |
| print(json.dumps(metrics, indent=2)) | |