tsam
A Python package which uses different machine learning algorithms for the aggregation of time series.
https://github.com/fzj-iek3-vsa/tsam
Category: Energy Systems
Sub Category: Energy System Modeling Frameworks
Keywords
aggregation clustering energy-system optimization python time-series timeseries typical-periods
Keywords from Contributors
energy-system-modeling renewable-energy geospatial-analysis climate-change energy-systems optimisation renewables raster-data geospatial-data general-purpose
Last synced: about 2 hours ago
JSON representation
Repository metadata
Time series aggregation module (tsam). Determines typical operation periods or dereases the temporal resolution. Accelerates model or experiment runs.
- Host: GitHub
- URL: https://github.com/fzj-iek3-vsa/tsam
- Owner: FZJ-IEK3-VSA
- License: mit
- Created: 2017-05-15T08:36:11.000Z (almost 9 years ago)
- Default Branch: develop
- Last Pushed: 2026-02-20T17:37:51.000Z (8 days ago)
- Last Synced: 2026-02-20T18:57:31.590Z (8 days ago)
- Topics: aggregation, clustering, energy-system, optimization, python, time-series, timeseries, typical-periods
- Language: Python
- Homepage: https://tsam.readthedocs.io/
- Size: 122 MB
- Stars: 175
- Watchers: 9
- Forks: 37
- Open Issues: 11
- Releases: 25
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
README.md
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 quickstart example shows the capabilities of 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
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:
- 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 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)
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.
Owner metadata
- Name: Forschungszentrum Jülich - Jülich Systems Analysis
- Login: FZJ-IEK3-VSA
- Email:
- Kind: organization
- Description: Institute of Climate and Energy Systems (ICE)
- Website: https://www.fz-juelich.de/iek/iek-3/EN/Home/home_node.html
- Location: Forschungszentrum Jülich
- Twitter:
- Company:
- Icon url: https://avatars.githubusercontent.com/u/28654423?v=4
- Repositories: 16
- Last ynced at: 2024-12-23T04:12:17.721Z
- Profile URL: https://github.com/FZJ-IEK3-VSA
GitHub Events
Total
- Release event: 1
- Delete event: 2
- Pull request event: 23
- Fork event: 4
- Issues event: 13
- Watch event: 20
- Issue comment event: 35
- Push event: 39
- Pull request review comment event: 15
- Pull request review event: 13
- Create event: 17
Last Year
- Release event: 1
- Delete event: 2
- Pull request event: 23
- Fork event: 4
- Issues event: 13
- Watch event: 12
- Issue comment event: 35
- Push event: 39
- Pull request review comment event: 15
- Pull request review event: 13
- Create event: 17
Committers metadata
Last synced: 1 day ago
Total Commits: 480
Total Committers: 25
Avg Commits per committer: 19.2
Development Distribution Score (DDS): 0.713
Commits in past year: 160
Committers in past year: 7
Avg Commits per committer in past year: 22.857
Development Distribution Score (DDS) in past year: 0.262
| Name | Commits | |
|---|---|---|
| l-kotzur | l****r@f****e | 138 |
| FBumann | 1****n | 118 |
| maximilian-hoffmann | m****n@f****e | 98 |
| Leander Kotzur | l****r@r****e | 26 |
| julian-belina | 5****a | 21 |
| j.belina | j****a@f****e | 18 |
| j.schoenau | j****u@f****e | 10 |
| jo-omoyele | j****e@g****m | 9 |
| Julian Schönau | 6****e | 7 |
| Cord Kaldemeyer | c****r@f****e | 4 |
| Fabian Neumann | f****n@o****e | 4 |
| Samuel Letellier-Duchesne | s****e@m****m | 4 |
| Robert Schwarz | r****t@d****l | 3 |
| dependabot[bot] | 4****] | 3 |
| Amedeo Paolo Ceruti | g****z@m****e | 3 |
| Lars Schellhas | l****s@o****m | 2 |
| Philipp Dunkel | 8****j | 2 |
| andreas smolenko | a****o@f****e | 2 |
| simnh | s****t@u****e | 2 |
| Amedeo Ceruti | a****i@t****e | 1 |
| Francesco Witte | g****b@w****h | 1 |
| ar-fu | a****s@r****e | 1 |
| Dilara Gulcin Caglayan | d****n@f****e | 1 |
| noah80 | n****0 | 1 |
| rodo | r****d@d****m | 1 |
Committer domains:
- fz-juelich.de: 6
- rwth-aachen.de: 2
- dolltons.com: 1
- witte.sh: 1
- tum.de: 1
- uni-flensburg.de: 1
- mytum.de: 1
- doingthemath.nl: 1
- me.com: 1
- outlook.de: 1
- fh-flensburg.de: 1
Issue and Pull Request metadata
Last synced: 4 days ago
Total issues: 40
Total pull requests: 81
Average time to close issues: 6 months
Average time to close pull requests: 21 days
Total issue authors: 19
Total pull request authors: 22
Average comments per issue: 2.33
Average comments per pull request: 1.21
Merged pull request: 55
Bot issues: 0
Bot pull requests: 1
Past year issues: 5
Past year pull requests: 15
Past year average time to close issues: about 2 months
Past year average time to close pull requests: 6 days
Past year issue authors: 3
Past year pull request authors: 5
Past year average comments per issue: 1.2
Past year average comments per pull request: 1.13
Past year merged pull request: 6
Past year bot issues: 0
Past year bot pull requests: 1
Top Issue Authors
- ckaldemeyer (7)
- l-kotzur (6)
- julian-belina (4)
- l-welder (4)
- phil-fzj (3)
- adbuerger (2)
- sbruche (2)
- curiousleo (1)
- jacob-mannhardt (1)
- alicia-le (1)
- mfleschutz (1)
- fneum (1)
- SilkeJo (1)
- ddahawkins-TUDelft (1)
- larsschellhas (1)
Top Pull Request Authors
- l-kotzur (26)
- FBumann (8)
- maximilian-hoffmann (7)
- OfficialCodexplosive (7)
- julian-belina (6)
- larsschellhas (3)
- phil-fzj (3)
- ddceruti (3)
- jo-omoyele (2)
- samuelduchesne (2)
- ar-fu (2)
- fneum (2)
- dcaglayan (1)
- ckaldemeyer (1)
- rschwarz (1)
Top Issue Labels
Top Pull Request Labels
- dependencies (1)
- github-actions (1)
Package metadata
- Total packages: 4
-
Total downloads:
- pypi: 31,251 last-month
- Total dependent packages: 7 (may contain duplicates)
- Total dependent repositories: 29 (may contain duplicates)
- Total versions: 68
- Total maintainers: 5
pypi.org: tsam
Time series aggregation module (tsam) to create typical periods
- Homepage:
- Documentation: https://tsam.readthedocs.io/
- Licenses: MIT License Copyright (c) 2017 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) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- Latest release: 3.1.0 (published 25 days ago)
- Last Synced: 2026-02-19T21:29:26.991Z (9 days ago)
- Versions: 31
- Dependent Packages: 6
- Dependent Repositories: 29
- Downloads: 31,251 Last month
-
Rankings:
- Dependent packages count: 1.596%
- Dependent repos count: 2.716%
- Average: 4.737%
- Downloads: 6.188%
- Stargazers count: 6.257%
- Forks count: 6.928%
- Maintainers (5)
proxy.golang.org: github.com/fzj-iek3-vsa/tsam
- Homepage:
- Documentation: https://pkg.go.dev/github.com/fzj-iek3-vsa/tsam#section-documentation
- Licenses: mit
- Latest release: v2.3.5+incompatible (published over 1 year ago)
- Last Synced: 2026-02-14T20:43:48.363Z (14 days ago)
- Versions: 18
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent packages count: 6.999%
- Average: 8.173%
- Dependent repos count: 9.346%
proxy.golang.org: github.com/FZJ-IEK3-VSA/tsam
- Homepage:
- Documentation: https://pkg.go.dev/github.com/FZJ-IEK3-VSA/tsam#section-documentation
- Licenses: mit
- Latest release: v2.3.5+incompatible (published over 1 year ago)
- Last Synced: 2026-02-23T13:34:58.006Z (5 days ago)
- Versions: 18
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent packages count: 6.999%
- Average: 8.173%
- Dependent repos count: 9.346%
conda-forge.org: tsam
- Homepage: https://github.com/FZJ-IEK3-VSA/tsam
- Licenses: MIT
- Latest release: 2.0.1 (published almost 4 years ago)
- Last Synced: 2026-02-02T14:14:18.685Z (26 days ago)
- Versions: 1
- Dependent Packages: 1
- Dependent Repositories: 0
-
Rankings:
- Dependent packages count: 28.82%
- Stargazers count: 29.339%
- Forks count: 29.863%
- Average: 30.512%
- Dependent repos count: 34.025%
Dependencies
- networkx *
- numpy >=1.11.0
- pandas >=0.18.1
- pyomo >=5.3
- scikit-learn >=0.0
- tqdm *
- actions/checkout v2 composite
- actions/setup-python v2 composite
- pytest * development
- sphinx * development
- sphinx-autobuild * development
- sphinx_book_theme * development
- twine * development
Score: 18.795740251386373