Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
337 changes: 43 additions & 294 deletions docs/notebooks/08c-clustering.ipynb

Large diffs are not rendered by default.

609 changes: 0 additions & 609 deletions docs/notebooks/08d-clustering-multiperiod.ipynb

This file was deleted.

540 changes: 0 additions & 540 deletions docs/notebooks/08e-clustering-internals.ipynb

This file was deleted.

647 changes: 0 additions & 647 deletions docs/notebooks/08f-clustering-segmentation.ipynb

This file was deleted.

33 changes: 8 additions & 25 deletions flixopt/clustering/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
"""
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 ClusteringResult.

Example usage:

# Cluster a FlowSystem to reduce timesteps
from tsam import ExtremeConfig

fs_clustered = flow_system.transform.cluster(
Expand All @@ -16,36 +14,21 @@
extremes=ExtremeConfig(method='new_cluster', max_value=['Demand|fixed_relative_profile']),
)

# 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 result: {clustering.clustering_result}')

# Access tsam 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.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')
# Use include_original_data=False for smaller files (~38% reduction)
fs_clustered.to_netcdf('system.nc', include_original_data=False)
# Access tsam_xarray AggregationResult (only before saving/loading)
result = clustering.aggregation_result
result.cluster_representatives # DataArray
result.accuracy # AccuracyMetrics

# Expand back to full resolution
fs_expanded = fs_clustered.transform.expand()
"""

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

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