MCPcopy Index your code
hub / github.com/FZJ-IEK3-VSA/tsam

github.com/FZJ-IEK3-VSA/tsam @v3.4.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v3.4.1 ↗ · + Follow
410 symbols 1,641 edges 53 files 276 documented · 67% updated 1d agov3.4.1 · 2026-05-31★ 17711 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Version Conda Version Documentation Status PyPI - License codecov

  <img src="https://github.com/FZJ-IEK3-VSA/tsam/raw/v3.4.1/docs/assets/tsam-logo-light.svg" alt="ETHOS.TSAM Logo" height="80px">

Jülich System Analysis Header

ETHOS.TSAM - Time Series Aggregation Module

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.

The documentation of the ETHOS.TSAM code can be found here.

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

Examples

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

Legacy API

For backward compatibility, the class-based API of TSAM Version 2 is still available.

import tsam.timeseriesaggregation as tsam_legacy

aggregation = tsam_legacy.TimeSeriesAggregation(
    raw,
    noTypicalPeriods=8,
    hoursPerPeriod=24,
    segmentation=True,
    noSegments=8,
    representationMethod="distributionAndMinMaxRepresentation",
    clusterMethod='hierarchical'
)
cluster_representatives = aggregation.createTypicalPeriods()

Detailed examples

Detailed examples can be found at:/docs/notebooks/

A quickstart example shows the capabilities of ETHOS.TSAM as a Jupyter notebook.

A second example shows in more detail how to access the relevant aggregation results required for parameterizing e.g. an optimization.

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

License

MIT License

Citing and further reading

If you want to use ETHOS.TSAM in a published work, please kindly cite our latest journal articles: * Hoffmann et al. (2022):\ The Pareto-Optimal Temporal Aggregation of Energy System Models

If you are further interested in the impact of time series aggregation on the cost-optimal results on different energy system use cases, you can find a publication which validates the methods and describes their cababilites via the following link. A second publication introduces a method how to model state variables (e.g. the state of charge of energy storage components) between the aggregated typical periods which can be found here. Finally yet importantly the potential of time series aggregation to simplify mixed integer linear problems is investigated here.

The publications about time series aggregation for energy system optimization models published alongside the development of ETHOS.TSAM are listed below: * Hoffmann et al. (2021):\ The Pareto-Optimal Temporal Aggregation of Energy System Models\ (open access manuscript to be found here) * Hoffmann et al. (2021):\ Typical periods or typical time steps? A multi-model analysis to determine the optimal temporal aggregation for energy system models * Hoffmann et al. (2020):\ A Review on Time Series Aggregation Methods for Energy System Models * Kannengießer et al. (2019):\ Reducing Computational Load for Mixed Integer Linear Programming: An Example for a District and an Island Energy System * Kotzur et al. (2018):\ Time series aggregation for energy system design: Modeling seasonal storage\ (open access manuscript to be found here) * Kotzur et al. (2018):\ Impact of different time series aggregation methods on optimal energy system design\ (open access manuscript to be found here)

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.

Acknowledgement

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.

<img src="https://raw.githubusercontent.com/FZJ-IEK3-VSA/README_assets/v.1.0.0/Helmholtz_Logos/Helmholtz-Logo-Dark-Blue-RGB.svg" alt="Helmholtz Logo" width="200px" style="float:right">

Core symbols most depended-on inside this repo

aggregate
called by 114
src/tsam/api.py
disaggregate
called by 34
src/tsam/config.py
apply
called by 18
src/tsam/config.py
to_json
called by 13
src/tsam/config.py
from_json
called by 13
src/tsam/config.py
to_dict
called by 12
src/tsam/config.py
cluster_members
called by 11
src/tsam/plot.py
createTypicalPeriods
called by 10
src/tsam/timeseriesaggregation.py

Shape

Method 230
Function 126
Class 48
Route 6

Languages

Python100%

Modules by API surface

test/test_new_api.py55 symbols
test/test_plot.py45 symbols
test/test_disaggregate.py44 symbols
src/tsam/config.py41 symbols
test/test_clustering_e2e.py26 symbols
src/tsam/timeseriesaggregation.py24 symbols
src/tsam/tuning.py22 symbols
src/tsam/result.py17 symbols
src/tsam/plot.py14 symbols
src/tsam/utils/k_medoids_exact.py12 symbols
src/tsam/api.py9 symbols
test/test_reconstruct_samemean_segmentation.py8 symbols

For agents

$ claude mcp add tsam \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page