Skip to content
Merged
18 changes: 5 additions & 13 deletions benchmarks/src/ddr_benchmarks/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
from tqdm import tqdm

# Reuse ALL DDR imports
from ddr import ddr_functions, dmc, kan, streamflow
from ddr import dmc, kan, streamflow
from ddr._version import __version__
from ddr.geodatazoo.dataclasses import Dates, RoutingDataclass
from ddr.io.readers import read_zarr
from ddr.scripts_utils import compute_daily_runoff
from ddr.validation import Config, Metrics, plot_box_fig, plot_cdf, plot_gauge_map, plot_time_series, utils
from ddr.validation.enums import GeoDataset

Expand Down Expand Up @@ -784,19 +785,10 @@ def benchmark(
diffroute_predictions = diffroute_predictions[non_headwater]

# === EVALUATION (same as test.py) ===
num_days = len(ddr_predictions[0][13 : (-11 + cfg.params.tau)]) // 24
ddr_daily = compute_daily_runoff(torch.tensor(ddr_predictions), cfg.params.tau)
diffroute_daily = compute_daily_runoff(torch.tensor(diffroute_predictions), cfg.params.tau)

ddr_daily = ddr_functions.downsample(
torch.tensor(ddr_predictions[:, (13 + cfg.params.tau) : (-11 + cfg.params.tau)]),
rho=num_days,
).numpy()

diffroute_daily = ddr_functions.downsample(
torch.tensor(diffroute_predictions[:, (13 + cfg.params.tau) : (-11 + cfg.params.tau)]),
rho=num_days,
).numpy()

daily_obs = observations[:, 1:-1]
daily_obs = observations[:, :-2] # Pooled day i ↔ obs day i

# Compute metrics using DDR's Metrics class
log.info("=" * 50)
Expand Down
24 changes: 12 additions & 12 deletions docs/datasets.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ ds = xr.Dataset(
"Qr": (["time", "divide_id"], qr_data), # Lateral inflow in m³/s
},
coords={
"time": time_index, # Daily timestamps
"divide_id": divide_ids, # Catchment identifiers
"time": time_index, # Daily timestamps
"divide_id": divide_ids, # Catchment identifiers
},
attrs={
"units": "m^3/s",
"source": "your_model_name",
}
},
)
```

Expand Down Expand Up @@ -88,13 +88,13 @@ The NOAA-OWP Hydrofabric v2.2 is the recommended geospatial dataset for CONUS ap
```python
# Flowpath attributes
flowpath_attrs = [
"id", # Waterbody identifier (wb-XXXXX)
"toid", # Downstream identifier
"Length_m", # Channel length in meters
"So", # Channel slope (dimensionless)
"TopWdth", # Top width in meters
"ChSlp", # Channel side slope
"MusX", # Muskingum X parameter
"id", # Waterbody identifier (wb-XXXXX)
"toid", # Downstream identifier
"Length_m", # Channel length in meters
"So", # Channel slope (dimensionless)
"TopWdth", # Top width in meters
"ChSlp", # Channel side slope
"MusX", # Muskingum X parameter
]
```

Expand Down Expand Up @@ -203,7 +203,7 @@ ds = xr.Dataset(
},
coords={
"divide_id": divide_ids, # Format: "cat-XXXXX"
}
},
)
```

Expand Down Expand Up @@ -241,7 +241,7 @@ ds = xr.Dataset(
coords={
"time": time_index,
"gage_id": gage_ids, # 8-digit zero-padded strings
}
},
)
```

Expand Down
3 changes: 3 additions & 0 deletions docs/engine/binsparse.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ print(list_geodatasets()) # ['hydrofabric_v2.2', 'lynker', 'merit']
```python
from ddr_engine import register_converter


class MyConverter:
def to_zarr(self, ids):
return np.array(ids, dtype=np.int32)

def from_zarr(self, order):
return order.tolist()


register_converter("my_geodataset", MyConverter())
```

Expand Down
7 changes: 3 additions & 4 deletions docs/engine/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ The `ddr_engine` package exports I/O functions at the package level:
```python
from ddr_engine import (
# Primary API (recommended)
coo_to_zarr, # Write COO matrix (pass geodataset name)
coo_from_zarr, # Read COO matrix (auto-detects geodataset)
coo_to_zarr, # Write COO matrix (pass geodataset name)
coo_from_zarr, # Read COO matrix (auto-detects geodataset)
coo_to_zarr_group, # Write gauge subset

# Converter registry
list_geodatasets, # List available geodatasets
list_geodatasets, # List available geodatasets
register_converter, # Register custom geodataset
)
```
Expand Down
6 changes: 3 additions & 3 deletions docs/gpu.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ DDR stores adjacency matrices in Coordinate (COO) format, which efficiently repr

```python
# COO representation
row_indices = [1, 2, 3, 3] # Downstream segment indices
col_indices = [0, 1, 1, 2] # Upstream segment indices
values = [1, 1, 1, 1] # Connection weights (always 1)
row_indices = [1, 2, 3, 3] # Downstream segment indices
col_indices = [0, 1, 1, 2] # Upstream segment indices
values = [1, 1, 1, 1] # Connection weights (always 1)
shape = (n_segments, n_segments)

# Matrix interpretation:
Expand Down
1 change: 1 addition & 0 deletions docs/startup.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ ddr --help
```python
# Or verify from Python
import ddr

print(ddr.__version__)
```

Expand Down
Loading
Loading