Skip to main content

Time series aggregation module (tsam) to create typical periods

Reason this release was yanked:

This versions misses important parameters from the 2.3.9 version

Project description

Version Conda Version Documentation Status PyPI - License codecov badge

Forschungszentrum Juelich Logo

tsam - Time Series Aggregation Module

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

The documentation of the 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 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 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/source/examples_notebooks/

A first example shows the capabilites of tsam as jupyter notebook.

A second example shows in more detail how to access the relevant aggregation results required for paramtrizing 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

Copyright (C) 2017-2025 Leander Kotzur (FZJ IEK-3), Maximilian Hoffmann (FZJ IEK-3), Peter Markewitz (FZJ IEK-3), Martin Robinius (FZJ IEK-3), Detlef Stolten (FZJ IEK-3)

You should have received a copy of the MIT License along with this program. If not, see https://opensource.org/licenses/MIT

The core developer team sits in the Institute of Energy and Climate Research - Techno-Economic Energy Systems Analysis (IEK-3) belonging to the Forschungszentrum Jülich.

Citing and further reading

If you want to use tsam in a published work, please kindly cite our latest journal articles:

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 tsam are listed below:

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.

Helmholtz Logo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tsam-3.0.0.tar.gz (92.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tsam-3.0.0-py3-none-any.whl (69.5 kB view details)

Uploaded Python 3

File details

Details for the file tsam-3.0.0.tar.gz.

File metadata

  • Download URL: tsam-3.0.0.tar.gz
  • Upload date:
  • Size: 92.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for tsam-3.0.0.tar.gz
Algorithm Hash digest
SHA256 8574f045f28a06340cbc3a7909f3fb023c88ed996fcb2593b058b9f88830186f
MD5 c5cf79972c8da8cacccc95abd01b6dd9
BLAKE2b-256 dd265affb43c01dcc8b2a0d3cb780ce20a1333987b036c5285a1a517ba7f9b72

See more details on using hashes here.

File details

Details for the file tsam-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: tsam-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 69.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for tsam-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d86ef5f75ae09a451c0e9a4249d1b189c689eb63c8bcbea0b0bc8f1748a51a43
MD5 ee786c7268a95a76b3a8719048d9bdbd
BLAKE2b-256 8b8d0990c8d4ba564f9f5feab2ae77c2a49cba8e5ae80efc65b3d97d1321e3be

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page