tsam_xarray¶
Lightweight xarray wrapper for tsam time series aggregation.
tsam_xarray lets you aggregate multi-dimensional xarray DataArrays using tsam's clustering algorithms. It handles:
- DataFrame conversion — stack/unstack dimensions automatically
- Independent slicing — aggregate per scenario, year, region, etc. in one call
- Result assembly — cluster representatives, accuracy metrics, cluster weights, and segment durations are concatenated into coherent multi-dimensional xarray objects
Quick example¶
import tsam_xarray
result = tsam_xarray.aggregate(
da,
time_dim="time",
cluster_dim=["variable", "region"],
n_clusters=8,
)
result.cluster_representatives # (cluster, timestep, variable, region)
result.cluster_weights # (cluster,)
result.accuracy.rmse # (variable, region)
result.reconstructed # same shape as input
All tsam.aggregate() keyword arguments pass through — clustering methods, segmentation, extreme periods, etc.
Installation¶
Next steps¶
- Getting Started — basic workflow
- Data Model — understand the result objects and their attributes
- Multi-Dimensional Data — stacking, slicing, weights
- API Reference — full function and class documentation