Time series aggregation for large optimization models — and any other time series.
📖 Read the full documentation at tsam.readthedocs.io.
ETHOS.TSAM is a python package which uses different machine learning algorithms for the aggregation of time series. The data aggregation can be performed in two freely combinable dimensions: By representing the time series by a user-defined number of typical periods or by decreasing the temporal resolution. ETHOS.TSAM was originally designed for reducing the computational load for large-scale energy system optimization models by aggregating their input data, but is applicable for all types of time series, e.g., weather data, load data, both simultaneously or other arbitrary groups of time series.
ETHOS.TSAM is part of the Energy Transformation PatHway Optimization Suite (ETHOS) at ICE-2. It is tightly integrated into ETHOS.FINE to reduce the temporal complexity of energy system models.
- flexible handling of multidimensional time-series via the pandas module
- different aggregation methods implemented (averaging, k-means, exact k-medoids, hierarchical, k-maxoids, k-medoids with contiguity), which are based on scikit-learn, or self-programmed with pyomo
- hypertuning of aggregation parameters to find the optimal combination of the number of segments inside a period and the number of typical periods
- novel representation methods, keeping statistical attributes, such as the distribution
- flexible integration of extreme periods as own cluster centers
- weighting for the case of multidimensional time-series to represent their relevance
To avoid dependency conflicts, it is recommended that you install ETHOS.TSAM in its own environment. You can use either uv or conda/mamba to manage environments and installations. Before proceeding, you must install either UV or Conda/Mamba, or both.
Quick Install with uv
uv venv tsam_env
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install tsamOr from conda-forge:
conda create -n tsam_env -c conda-forge tsamconda and mamba can be used interchangeably
git clone https://github.com/FZJ-IEK3-VSA/tsam.git
cd tsamuv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e ".[develop]"conda env create -n tsam_env --file=environment.yml
conda activate tsam_env
pip install -e . --no-depspre-commit installSee CONTRIBUTING.md for detailed development guidelines.
HiGHS is installed by default. For better performance on large problems, commercial solvers (Gurobi, CPLEX) are recommended if you have a license
A small example how ETHOS.TSAM can be used is described as follows:
import pandas as pd
import tsamRead in the time series data set with pandas
raw = pd.read_csv('testdata.csv', index_col=0, parse_dates=True)Run the aggregation - specify the number of typical periods and configure clustering/segmentation options:
from tsam import aggregate, ClusterConfig, SegmentConfig
result = tsam.aggregate(
raw,
n_clusters=8,
period_duration='24h', # or 24, '1d'
cluster=ClusterConfig(
method='hierarchical',
representation='distribution_minmax',
),
segments=SegmentConfig(n_segments=8),
)Access the results:
# Get the typical periods DataFrame
cluster_representatives = result.cluster_representatives
# Check accuracy metrics
print(f"RMSE: {result.accuracy.rmse.mean():.4f}")
# Reconstruct the original time series from typical periods
reconstructed = result.reconstructed
# Save results
cluster_representatives.to_csv('cluster_representatives.csv')The class-based TimeSeriesAggregation API has been removed in version 4 — use
tsam.aggregate() as shown above. The
migration guide maps every old
parameter, method, and default to its replacement.
The documentation is built around runnable notebooks:
- Your first aggregation — the whole workflow end to end, as a Jupyter notebook.
- Optimization workflow — how to access the aggregation results needed to parameterize e.g. an optimization.
The example time series are based on a department publication and the test reference years of the DWD.
If you want to use ETHOS.TSAM in a published work, please kindly cite:
- Hoffmann et al. (2022):
The Pareto-Optimal Temporal Aggregation of Energy System Models
The full list of publications behind ETHOS.TSAM and the aggregation methods it implements — with open-access links — is kept in one place in the documentation: Further reading.
All contributions are welcome:
- If you have a question, want to report a bug, or have a feature request, please open an Issue. We will then take care of the issue as soon as possible.
- If you want to contribute with additional features or code improvements, open a Pull request.
See CONTRIBUTING.md for development guidelines.
We are the Institute of Climate and Energy Systems – Jülich Systems Analysis (ICE-2) at the Forschungszentrum Jülich. Our work focuses on independent, interdisciplinary research in energy, bioeconomy, infrastructure, and sustainability. We support a just, greenhouse gas–neutral transformation through open models and policy-relevant science.
Please respect our code of conduct.
This work is supported by the Helmholtz Association under the Joint Initiative "Energy System 2050 – A Contribution of the Research Field Energy" and the program "Energy System Design" and within the BMWi/BMWk funded project METIS.