tsam 2.3.4__py3-none-any.whl → 2.3.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tsam/utils/durationRepresentation.py +44 -28
- {tsam-2.3.4.dist-info → tsam-2.3.6.dist-info}/METADATA +72 -22
- {tsam-2.3.4.dist-info → tsam-2.3.6.dist-info}/RECORD +6 -6
- {tsam-2.3.4.dist-info → tsam-2.3.6.dist-info}/LICENSE.txt +0 -0
- {tsam-2.3.4.dist-info → tsam-2.3.6.dist-info}/WHEEL +0 -0
- {tsam-2.3.4.dist-info → tsam-2.3.6.dist-info}/top_level.txt +0 -0
|
@@ -57,17 +57,18 @@ def durationRepresentation(
|
|
|
57
57
|
# get all the values of a certain attribute and cluster
|
|
58
58
|
candidateValues = candidates.loc[indice[0], a]
|
|
59
59
|
# sort all values
|
|
60
|
-
sortedAttr = candidateValues.stack(
|
|
60
|
+
sortedAttr = candidateValues.stack(
|
|
61
|
+
future_stack=True,
|
|
62
|
+
).sort_values()
|
|
61
63
|
# reindex and arrange such that every sorted segment gets represented by its mean
|
|
62
64
|
sortedAttr.index = pd.MultiIndex.from_tuples(clean_index)
|
|
63
65
|
representationValues = sortedAttr.unstack(level=0).mean(axis=1)
|
|
64
66
|
# respect max and min of the attributes
|
|
65
67
|
if representMinMax:
|
|
66
68
|
representationValues.loc[0] = sortedAttr.values[0]
|
|
67
|
-
representationValues.loc[
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
representationValues.loc[representationValues.index[-1]] = (
|
|
70
|
+
sortedAttr.values[-1]
|
|
71
|
+
)
|
|
71
72
|
|
|
72
73
|
# get the order of the representation values such that euclidean distance to the candidates is minimized
|
|
73
74
|
order = candidateValues.mean().sort_values().index
|
|
@@ -97,8 +98,12 @@ def durationRepresentation(
|
|
|
97
98
|
# concat centroid values and cluster weights for all clusters
|
|
98
99
|
meansAndWeights = pd.concat(
|
|
99
100
|
[
|
|
100
|
-
pd.DataFrame(np.array(meanVals)).stack(
|
|
101
|
-
|
|
101
|
+
pd.DataFrame(np.array(meanVals)).stack(
|
|
102
|
+
future_stack=True,
|
|
103
|
+
),
|
|
104
|
+
pd.DataFrame(np.array(clusterLengths)).stack(
|
|
105
|
+
future_stack=True,
|
|
106
|
+
),
|
|
102
107
|
],
|
|
103
108
|
axis=1,
|
|
104
109
|
)
|
|
@@ -107,7 +112,14 @@ def durationRepresentation(
|
|
|
107
112
|
# save order of the sorted centroid values across all clusters
|
|
108
113
|
order = meansAndWeightsSorted.index
|
|
109
114
|
# sort all values of the original time series
|
|
110
|
-
sortedAttr =
|
|
115
|
+
sortedAttr = (
|
|
116
|
+
candidates.loc[:, a]
|
|
117
|
+
.stack(
|
|
118
|
+
future_stack=True,
|
|
119
|
+
)
|
|
120
|
+
.sort_values()
|
|
121
|
+
.values
|
|
122
|
+
)
|
|
111
123
|
# take mean of sections of the original duration curve according to the cluster and its weight the
|
|
112
124
|
# respective section is assigned to
|
|
113
125
|
representationValues = []
|
|
@@ -124,8 +136,7 @@ def durationRepresentation(
|
|
|
124
136
|
keepSum=True,
|
|
125
137
|
)
|
|
126
138
|
|
|
127
|
-
|
|
128
|
-
# transform all representation values to a data frame and arrange it
|
|
139
|
+
# transform all representation values to a data frame and arrange it
|
|
129
140
|
# according to the order of the sorted
|
|
130
141
|
# centroid values
|
|
131
142
|
representationValues = pd.DataFrame(np.array(representationValues))
|
|
@@ -139,9 +150,9 @@ def durationRepresentation(
|
|
|
139
150
|
return clusterCenters
|
|
140
151
|
|
|
141
152
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
153
|
+
def _representMinMax(
|
|
154
|
+
representationValues, sortedAttr, meansAndWeightsSorted, keepSum=True
|
|
155
|
+
):
|
|
145
156
|
"""
|
|
146
157
|
Represents the the min and max values of the original time series in the
|
|
147
158
|
duration curve representation such that the min and max values of the
|
|
@@ -164,8 +175,8 @@ def _representMinMax(representationValues, sortedAttr, meansAndWeightsSorted,
|
|
|
164
175
|
if np.any(np.array(representationValues) < 0):
|
|
165
176
|
raise ValueError("Negative values in the duration curve representation")
|
|
166
177
|
|
|
167
|
-
# first retrieve the change of the values to the min and max values
|
|
168
|
-
# of the original time series and their duration in the original
|
|
178
|
+
# first retrieve the change of the values to the min and max values
|
|
179
|
+
# of the original time series and their duration in the original
|
|
169
180
|
# time series
|
|
170
181
|
delta_max = sortedAttr.max() - representationValues[-1]
|
|
171
182
|
appearance_max = meansAndWeightsSorted[1].iloc[-1]
|
|
@@ -174,31 +185,36 @@ def _representMinMax(representationValues, sortedAttr, meansAndWeightsSorted,
|
|
|
174
185
|
|
|
175
186
|
if delta_min == 0 and delta_max == 0:
|
|
176
187
|
return representationValues
|
|
177
|
-
|
|
188
|
+
|
|
178
189
|
if keepSum:
|
|
179
190
|
|
|
180
|
-
# now anticipate the shift of the sum of the time series
|
|
191
|
+
# now anticipate the shift of the sum of the time series
|
|
181
192
|
# due to the change of the min and max values
|
|
182
193
|
# of the duration curve
|
|
183
194
|
delta_sum = delta_max * appearance_max + delta_min * appearance_min
|
|
184
|
-
# and derive how much the other values have to be changed to preserve
|
|
195
|
+
# and derive how much the other values have to be changed to preserve
|
|
185
196
|
# the mean of the duration curve
|
|
186
|
-
correction_factor =
|
|
187
|
-
|
|
188
|
-
|
|
197
|
+
correction_factor = (
|
|
198
|
+
-delta_sum
|
|
199
|
+
/ (meansAndWeightsSorted[1].iloc[1:-1] * representationValues[1:-1]).sum()
|
|
200
|
+
)
|
|
201
|
+
|
|
189
202
|
if correction_factor < -1 or correction_factor > 1:
|
|
190
|
-
warnings.warn(
|
|
203
|
+
warnings.warn(
|
|
204
|
+
"The cluster is too small to preserve the sum of the duration curve and additionally the min and max values of the original cluster members. The min max values of the cluster are not preserved. This does not necessarily mean that the min and max values of the original time series are not preserved."
|
|
205
|
+
)
|
|
191
206
|
return representationValues
|
|
192
207
|
|
|
193
|
-
# correct the values of the duration curve such
|
|
208
|
+
# correct the values of the duration curve such
|
|
194
209
|
# that the mean of the duration curve is preserved
|
|
195
210
|
# since the min and max values are changed
|
|
196
|
-
representationValues[1:-1] = np.multiply(
|
|
197
|
-
1+ correction_factor)
|
|
198
|
-
|
|
199
|
-
|
|
211
|
+
representationValues[1:-1] = np.multiply(
|
|
212
|
+
representationValues[1:-1], (1 + correction_factor)
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
# change the values of the duration curve such that the min and max
|
|
200
216
|
# values are preserved
|
|
201
217
|
representationValues[-1] += delta_max
|
|
202
218
|
representationValues[0] += delta_min
|
|
203
|
-
|
|
219
|
+
|
|
204
220
|
return representationValues
|
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: tsam
|
|
3
|
-
Version: 2.3.
|
|
3
|
+
Version: 2.3.6
|
|
4
4
|
Summary: Time series aggregation module (tsam) to create typical periods
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
Author-email: Leander Kotzur <leander.kotzur@googlemail.com>, Maximilian Hoffmann <maximilian.hoffmann@julumni.fz-juelich.de>
|
|
6
|
+
Maintainer-email: Julian Belina <j.belina@fz-juelich.de>
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
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)
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
8
28
|
Keywords: clustering,optimization
|
|
9
29
|
Classifier: Development Status :: 4 - Beta
|
|
10
30
|
Classifier: Intended Audience :: End Users/Desktop
|
|
@@ -17,18 +37,26 @@ Classifier: Programming Language :: Python :: 2
|
|
|
17
37
|
Classifier: Programming Language :: Python :: 3
|
|
18
38
|
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
19
39
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
-
Requires-Python:
|
|
40
|
+
Requires-Python: <3.13,>=3.9
|
|
21
41
|
Description-Content-Type: text/markdown
|
|
22
42
|
License-File: LICENSE.txt
|
|
23
|
-
Requires-Dist: scikit-learn
|
|
24
|
-
Requires-Dist: pandas
|
|
25
|
-
Requires-Dist: numpy
|
|
26
|
-
Requires-Dist: pyomo
|
|
43
|
+
Requires-Dist: scikit-learn>=0.0
|
|
44
|
+
Requires-Dist: pandas>=2.0.3
|
|
45
|
+
Requires-Dist: numpy>=1.20.0
|
|
46
|
+
Requires-Dist: pyomo>=6.4.3
|
|
27
47
|
Requires-Dist: networkx
|
|
28
48
|
Requires-Dist: tqdm
|
|
29
49
|
Requires-Dist: highspy
|
|
30
|
-
|
|
31
|
-
|
|
50
|
+
Provides-Extra: dev
|
|
51
|
+
Requires-Dist: pytest; extra == "dev"
|
|
52
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
53
|
+
Requires-Dist: codecov; extra == "dev"
|
|
54
|
+
Requires-Dist: sphinx; extra == "dev"
|
|
55
|
+
Requires-Dist: sphinx-autobuild; extra == "dev"
|
|
56
|
+
Requires-Dist: sphinx-book-theme; extra == "dev"
|
|
57
|
+
Requires-Dist: twine; extra == "dev"
|
|
58
|
+
|
|
59
|
+
[](https://github.com/FZJ-IEK3-VSA/tsam/actions) [](https://pypi.python.org/pypi/tsam) [](https://anaconda.org/conda-forge/tsam) [](https://tsam.readthedocs.io/en/latest/) []((https://github.com/FZJ-IEK3-VSA/tsam/blob/master/LICENSE.txt)) [](https://codecov.io/gh/FZJ-IEK3-VSA/tsam)
|
|
32
60
|
[](https://mybinder.org/v2/gh/FZJ-IEK3-VSA/voila-tsam/HEAD?urlpath=voila/render/Time-Series-Aggregation-Module.ipynb)
|
|
33
61
|
|
|
34
62
|
<a href="https://www.fz-juelich.de/en/iek/iek-3"><img src="https://www.fz-juelich.de/static/media/Logo.2ceb35fc.svg" alt="Forschungszentrum Juelich Logo" width="230px"></a>
|
|
@@ -49,28 +77,50 @@ The documentation of the tsam code can be found [**here**](https://tsam.readthed
|
|
|
49
77
|
|
|
50
78
|
|
|
51
79
|
## Installation
|
|
80
|
+
It is recommended to install tsam within its own environment. If you are no familiar with python environments, plaese consider to read some [external documentation](https://realpython.com/python-virtual-environments-a-primer/). In the following we assume you have a [mamba](https://mamba.readthedocs.io/en/latest/installation/mamba-installation.html) or [conda](https://www.anaconda.com/) installation. All conda and mamba command are interchangeable.
|
|
81
|
+
|
|
82
|
+
### Direct Installations from Package Manager Repositories
|
|
83
|
+
|
|
84
|
+
If you want to prevent any possible dependency conflicts create a new environment using the following command:
|
|
85
|
+
|
|
86
|
+
mamba create -n tsam_env python pip
|
|
87
|
+
|
|
88
|
+
Activate an existing or the newly create environment afterward
|
|
89
|
+
|
|
90
|
+
mamba activate tsam_env
|
|
91
|
+
|
|
52
92
|
Directly install via pip from pypi as follows:
|
|
53
93
|
|
|
54
94
|
pip install tsam
|
|
55
95
|
|
|
56
|
-
|
|
96
|
+
or install from conda forge with the following command:
|
|
57
97
|
|
|
58
98
|
conda install tsam -c conda-forge
|
|
59
99
|
|
|
100
|
+
### Local Installation for Development
|
|
60
101
|
Alternatively, clone a local copy of the repository to your computer
|
|
61
102
|
|
|
62
103
|
git clone https://github.com/FZJ-IEK3-VSA/tsam.git
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
104
|
+
|
|
105
|
+
Change the directory of your shell into the root folder of the repository
|
|
106
|
+
|
|
66
107
|
cd tsam
|
|
67
|
-
pip install .
|
|
68
|
-
|
|
69
|
-
Or install directly via python as
|
|
70
108
|
|
|
71
|
-
|
|
109
|
+
For development, it is recommended to install tsam into its own environment using conda e.g.
|
|
110
|
+
|
|
111
|
+
conda env create --file=requirement.yml
|
|
112
|
+
|
|
113
|
+
Afterward activate the environment
|
|
114
|
+
|
|
115
|
+
conda activate tsam_env
|
|
116
|
+
|
|
117
|
+
Then install tsam via pip as follows
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
pip install -e .[dev]
|
|
72
121
|
|
|
73
|
-
|
|
122
|
+
### Installation of MILP Solver for k-medoids
|
|
123
|
+
In order to use the k-medoids clustering, make sure that you have installed a MILP solver. As default [HiGHS](https://github.com/ERGO-Code/HiGHS) is installed and used. Nevertheless, in case you have access to a license we recommend commercial solvers (e.g. Gurobi or CPLEX) since they have a better performance.
|
|
74
124
|
|
|
75
125
|
### Developer installation
|
|
76
126
|
|
|
@@ -136,7 +186,7 @@ Copyright (C) 2016-2022 Leander Kotzur (FZJ IEK-3), Maximilian Hoffmann (FZJ IEK
|
|
|
136
186
|
You should have received a copy of the MIT License along with this program.
|
|
137
187
|
If not, see https://opensource.org/licenses/MIT
|
|
138
188
|
|
|
139
|
-
The core developer team sits in the [Institute of Energy and Climate Research - Techno-Economic Energy Systems Analysis (IEK-3)](https://www.fz-juelich.de/iek/iek-3/EN/Home/home_node.html) belonging to the [Forschungszentrum
|
|
189
|
+
The core developer team sits in the [Institute of Energy and Climate Research - Techno-Economic Energy Systems Analysis (IEK-3)](https://www.fz-juelich.de/iek/iek-3/EN/Home/home_node.html) belonging to the [Forschungszentrum Jülich](https://www.fz-juelich.de/).
|
|
140
190
|
|
|
141
191
|
## Citing and further reading
|
|
142
192
|
|
|
@@ -155,7 +205,7 @@ The publications about time series aggregation for energy system optimization mo
|
|
|
155
205
|
[**Typical periods or typical time steps? A multi-model analysis to determine the optimal temporal aggregation for energy system models**](https://www.sciencedirect.com/science/article/abs/pii/S0306261921011545)
|
|
156
206
|
* Hoffmann et al. (2020):\
|
|
157
207
|
[**A Review on Time Series Aggregation Methods for Energy System Models**](https://www.mdpi.com/1996-1073/13/3/641)
|
|
158
|
-
*
|
|
208
|
+
* Kannengießer et al. (2019):\
|
|
159
209
|
[**Reducing Computational Load for Mixed Integer Linear Programming: An Example for a District and an Island Energy System**](https://www.mdpi.com/1996-1073/12/14/2825)
|
|
160
210
|
* Kotzur et al. (2018):\
|
|
161
211
|
[**Time series aggregation for energy system design: Modeling seasonal storage**](https://www.sciencedirect.com/science/article/pii/S0306261918300242)\
|
|
@@ -4,13 +4,13 @@ tsam/periodAggregation.py,sha256=h9CC06jBLNyyaFTMRynGUMN87fOH3NdSEug6EcTsKGA,547
|
|
|
4
4
|
tsam/representations.py,sha256=2NL1wanBhGreCeJ8jh0aNdIx05YXEyyMJmMAVFS5-T4,7133
|
|
5
5
|
tsam/timeseriesaggregation.py,sha256=xLkdSmjbJnSxC0GBzF9Vc-6VMK7Y1OPOmQhdHJgymug,56963
|
|
6
6
|
tsam/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
-
tsam/utils/durationRepresentation.py,sha256=
|
|
7
|
+
tsam/utils/durationRepresentation.py,sha256=psjUTrLxr5eqBeSZzzRIUWEEfzMa5b30zPRmxwx2IBg,9713
|
|
8
8
|
tsam/utils/k_maxoids.py,sha256=0PyaHQMA8vtV_SuQOZ0qdcGFK46aUvOiMSQofjGkjBQ,4415
|
|
9
9
|
tsam/utils/k_medoids_contiguity.py,sha256=xSN9xT61oc2CPxYERhugR9hDkVCb2o8POvAiLLgrey8,5925
|
|
10
10
|
tsam/utils/k_medoids_exact.py,sha256=CW6BLQV2eTYtMxDmo97-6hY1HljxcvkPVrL4DQPN5IQ,7178
|
|
11
11
|
tsam/utils/segmentation.py,sha256=y8TPv1KEqf6ByOz7TRywm3WC9ZPhGiWvhwAcQbFibt4,6132
|
|
12
|
-
tsam-2.3.
|
|
13
|
-
tsam-2.3.
|
|
14
|
-
tsam-2.3.
|
|
15
|
-
tsam-2.3.
|
|
16
|
-
tsam-2.3.
|
|
12
|
+
tsam-2.3.6.dist-info/LICENSE.txt,sha256=XEzEzumoCmdJzcp5gKT6UOtKrkH-SiGpxVbIfihkNK4,1224
|
|
13
|
+
tsam-2.3.6.dist-info/METADATA,sha256=EUeJ5yP64aG4tXBZ4b_LmL9kB9ODkD3sSbvNUq64FUU,15389
|
|
14
|
+
tsam-2.3.6.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
15
|
+
tsam-2.3.6.dist-info/top_level.txt,sha256=MFI15PnPuMv8F1hTAOXbjGu41z-l6dJbnK69WlIQNcM,5
|
|
16
|
+
tsam-2.3.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|