Downloads · 30 days
11
15% of all-time downloads
kdahal/tnfr-streamflow-arizona
tnfr-streamflow-arizona is a time series forecasting model from kdahal. Use it for the time series forecasting task on the model card, and read the license before you ship it in a product. It is set up for pytorch. The card lists the license as mit.
A standard encoder-decoder Transformer trained to forecast daily streamflow for Arizona basins. This is the time-series-only baseline used in the TADA / Global-TADA study — it does not consume satellite imagery or ViT…
Downloads · 30 days
11
15% of all-time downloads
All-time downloads
75
Public
Parameters
5.3M
21.1 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors21.1 MB · 82%
From the Hugging Face model README
A standard encoder-decoder Transformer trained to forecast daily streamflow for Arizona basins. This is the time-series-only baseline used in the TADA / Global-TADA study — it does not consume satellite imagery or ViT features. Use it as a strong text-of-the-paper baseline, or as the warm-start backbone for the ViT-G gated variant.
from huggingface_hub import snapshot_download
import sys, json, torch
from safetensors.torch import load_file
local = snapshot_download(repo_id="kdahal/tnfr-streamflow-arizona")
sys.path.insert(0, local) # so `model_code` is importable
from model_code import Model
cfg = json.load(open(f"{local}/config.json"))
model = Model(
enc_in=cfg["enc_in"], dec_in=cfg["dec_in"], c_out=cfg["c_out"], out_len=cfg["out_len"],
d_model=cfg["d_model"], n_heads=cfg["n_heads"],
e_layers=cfg["e_layers"], d_layers=cfg["d_layers"], d_ff=cfg["d_ff"],
dropout=cfg["dropout"], embed=cfg["embed"], freq=cfg["freq"],
activation=cfg["activation"], output_attention=cfg["output_attention"], mix=cfg["mix"],
)
model.load_state_dict(load_file(f"{local}/model.safetensors"))
model.eval()
Or run the bundled demo (uses random inputs, just proves the load path works):
pip install -r requirements.txt
python inference.py
| Name | Shape | Dtype | Meaning |
|---|---|---|---|
x_enc | (B, 365, 250) | float32 | Past 365 days of normalized meteorological + static basin features |
x_mark_enc | (B, 365, 4) | float32 | Time marks (month, day, weekday, hour) — zeros are fine for daily data |
x_dec | (B, 180+30, 1) | float32 | Decoder seed: 180 days of known history concatenated with 30 zeros |
x_mark_dec | (B, 180+30, 4) | float32 | Decoder time marks |
Output: (B, 30, 1) — 30-day-ahead streamflow, in the same normalized units
as training (undo with per-basin mean/std).
Encoder-decoder Transformer with:
d_model = d_ff = 256, dropout = 0.1, GELU activationsInput layout (250 features) = daily meteorology (PRISM) + static catchment attributes (CAMELS + Arizona-specific), all z-score normalized against the locked training statistics.
az_streamflow split in the source repo), ~40 years of daily dataReported as median over all Arizona test basins (see the paper for full tables):
| Horizon | NSE (median) | KGE (median) |
|---|---|---|
| D1 | see paper | see paper |
| D7 | see paper | see paper |
| D30 | see paper | see paper |
Inputs to this model must be z-score normalized with the frozen training
statistics — not statistics computed from your own data. Those stats are
shipped as locked_stats.json and cover all 315
Arizona USGS basins used in training.
import json, numpy as np
stats = json.load(open("locked_stats.json"))
site = "09379025" # USGS site number
means = stats["basin_dynamic_stats"][site]["means"] # dict: feat -> mean
stds = stats["basin_dynamic_stats"][site]["stds"] # dict: feat -> std
# apply to a daily dataframe `df` with columns matching feature names
for col in means:
df[col] = (df[col] - means[col]) / (stds[col] + 1e-6)
# un-normalize model output (streamflow is in the same per-basin z-space)
mean_q, std_q = means["streamflow"], stds["streamflow"]
y_real = np.maximum(y_pred.numpy() * std_q + mean_q, 0.0)
Top-level keys in locked_stats.json:
basin_dynamic_stats: {site: {"means": {feat: µ}, "stds": {feat: σ}}} — per-basinglobal_static_stats: {"means": {...}, "stds": {...}} — for static catchment attributesstatic_data_lookup: {site: {feat: value}} — raw static attribute values per basin (already z-scored using global_static_stats when assembling x_enc)model.safetensors — weights (state_dict)config.json — exact constructor kwargslocked_stats.json — frozen per-basin normalization statistics (315 Arizona basins, 40 dynamic features)model_code/ — self-contained PyTorch source (no external repo needed)inference.py — end-to-end demoMIT.
If you use this model, please cite the accompanying paper (dissertation / forthcoming). See the project repo for the canonical BibTeX.
kdahal/vitg-streamflow-arizona — ViT-Gated variant (learnable gate over satellite ViT features)kdahal/cnn-streamflow-arizona — CNN hybrid (ResNet18 on raster tiles + Transformer time-series)