Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions flixopt/clustering/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""
Time Series Aggregation Module for flixopt.

This module provides wrapper classes around tsam's clustering functionality:
- Clustering: Top-level class stored on FlowSystem after clustering
- ClusteringResults: Manages collection of tsam ClusteringResult objects (for IO)
This module provides the Clustering class stored on FlowSystem after clustering,
wrapping tsam_xarray's ClusteringInfo.

Example usage:

Expand All @@ -19,19 +18,13 @@
# Access clustering structure (available before AND after IO)
clustering = fs_clustered.clustering
print(f'Number of clusters: {clustering.n_clusters}')
print(f'Dims: {clustering.dims}') # e.g., ('period', 'scenario')
print(f'Coords: {clustering.coords}') # e.g., {'period': [2024, 2025]}
print(f'Clustering info: {clustering.clustering_info}') # tsam_xarray ClusteringInfo

# Access tsam AggregationResult for detailed analysis
# Access tsam_xarray AggregationResult for detailed analysis
# NOTE: Only available BEFORE saving/loading. Lost after IO.
result = clustering.sel(period=2024, scenario='high')
result.cluster_representatives # DataFrame with aggregated time series
result = clustering.aggregation_result
result.cluster_representatives # DataArray with aggregated time series
result.accuracy # AccuracyMetrics (rmse, mae)
result.plot.compare() # tsam's built-in comparison plot

# Iterate over all results (only before IO)
for key, result in clustering.items():
print(f'{key}: {result.n_clusters} clusters')

# Save and load - structure preserved, AggregationResult access lost
fs_clustered.to_netcdf('system.nc')
Expand All @@ -42,10 +35,8 @@
fs_expanded = fs_clustered.transform.expand()
"""

from .base import AggregationResults, Clustering, ClusteringResults
from .base import Clustering

__all__ = [
'ClusteringResults',
'AggregationResults',
'Clustering',
]
Loading
Loading