Ctrl K

ETHOS.TSAM

tsam is a python package which uses different machine learning algorithms for the aggregation of time series.

706
mentions
5
contributors
Get started
662 commitsLast commit ≈ 6 days ago177 stars40 forks

Description

ETHOS.TSAM - Time Series Aggregation Module

Time series aggregation for large optimization models — and any other time series.

PyPI version conda-forge version Tests Coverage Documentation License

📖 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.

Features

  • 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

Installation

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 tsam

Or from conda-forge:

conda create -n tsam_env -c conda-forge tsam

conda and mamba can be used interchangeably

Development Installation

git clone https://github.com/FZJ-IEK3-VSA/tsam.git
cd tsam

Using uv (recommended)

uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
uv pip install -e ".[develop]"

Using conda-forge

conda env create -n tsam_env --file=environment.yml
conda activate tsam_env
pip install -e . --no-deps

Set up pre-commit hooks

pre-commit install

See CONTRIBUTING.md for detailed development guidelines.

MILP Solver for k-medoids

HiGHS is installed by default. For better performance on large problems, commercial solvers (Gurobi, CPLEX) are recommended if you have a license

Getting Started

Basic workflow

A small example how ETHOS.TSAM can be used is described as follows:

import pandas as pd
import tsam

Read 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')

Coming from version 2 or 3?

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.

Detailed examples

The documentation is built around runnable notebooks:

The example time series are based on a department publication and the test reference years of the DWD.

Citation

If you want to use ETHOS.TSAM in a published work, please kindly cite:

Further reading

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.

Contributions and Support

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.

License

MIT License

About Us

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.

Code of Conduct

Please respect our code of conduct.

Acknowledgments

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.

Logo of ETHOS.TSAM
Keywords
Programming languages
  • Python 93%
  • HTML 7%
License
</>Source code
Packages
pypi.org
anaconda.org

Participating organisations

Forschungszentrum Jülich

Reference papers

Mentions

Contributors

MH
Maximilian Hoffmann
Maintainer (former)
Forschungszentrum Jülich
JB
Julian Belina
OO
Olalekan Omoyele
Maintainer
Forschungszentrum Jülich

Helmholtz Program-oriented Funding IV