tsam 2.3.2__py3-none-any.whl → 2.3.5__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/__init__.py +0 -11
- tsam/timeseriesaggregation.py +37 -22
- tsam/utils/durationRepresentation.py +4 -4
- tsam/utils/k_medoids_contiguity.py +7 -0
- tsam/utils/k_medoids_exact.py +5 -0
- {tsam-2.3.2.dist-info → tsam-2.3.5.dist-info}/METADATA +16 -9
- tsam-2.3.5.dist-info/RECORD +16 -0
- {tsam-2.3.2.dist-info → tsam-2.3.5.dist-info}/WHEEL +1 -1
- tsam-2.3.2.dist-info/RECORD +0 -16
- {tsam-2.3.2.dist-info → tsam-2.3.5.dist-info}/LICENSE.txt +0 -0
- {tsam-2.3.2.dist-info → tsam-2.3.5.dist-info}/top_level.txt +0 -0
tsam/__init__.py
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
|
|
3
|
-
if not sys.warnoptions:
|
|
4
|
-
import warnings
|
|
5
|
-
|
|
6
|
-
warnings.filterwarnings(
|
|
7
|
-
action="ignore",
|
|
8
|
-
category=FutureWarning,
|
|
9
|
-
append=True,
|
|
10
|
-
message=r".*The previous implementation of stack is deprecated and will be removed in a future version of pandas.*",
|
|
11
|
-
)
|
tsam/timeseriesaggregation.py
CHANGED
|
@@ -8,7 +8,6 @@ import pandas as pd
|
|
|
8
8
|
import numpy as np
|
|
9
9
|
|
|
10
10
|
from sklearn.metrics import mean_squared_error, mean_absolute_error
|
|
11
|
-
from sklearn.metrics.pairwise import euclidean_distances
|
|
12
11
|
from sklearn import preprocessing
|
|
13
12
|
|
|
14
13
|
from tsam.periodAggregation import aggregatePeriods
|
|
@@ -27,6 +26,9 @@ TOLERANCE = 1e-6
|
|
|
27
26
|
MIN_WEIGHT = 1e-6
|
|
28
27
|
|
|
29
28
|
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
30
32
|
def unstackToPeriods(timeSeries, timeStepsPerPeriod):
|
|
31
33
|
"""
|
|
32
34
|
Extend the timeseries to an integer multiple of the period length and
|
|
@@ -134,6 +136,7 @@ class TimeSeriesAggregation(object):
|
|
|
134
136
|
predefClusterOrder=None,
|
|
135
137
|
predefClusterCenterIndices=None,
|
|
136
138
|
solver="highs",
|
|
139
|
+
numericalTolerance=1e-13,
|
|
137
140
|
roundOutput=None,
|
|
138
141
|
addPeakMin=None,
|
|
139
142
|
addPeakMax=None,
|
|
@@ -252,6 +255,10 @@ class TimeSeriesAggregation(object):
|
|
|
252
255
|
:param solver: Solver that is used for k_medoids clustering. optional (default: 'cbc' )
|
|
253
256
|
:type solver: string
|
|
254
257
|
|
|
258
|
+
:param numericalTolerance: Tolerance for numerical issues. Silences the warning for exceeding upper or lower bounds
|
|
259
|
+
of the time series. optional (default: 1e-13 )
|
|
260
|
+
:type numericalTolerance: float
|
|
261
|
+
|
|
255
262
|
:param roundOutput: Decimals to what the output time series get round. optional (default: None )
|
|
256
263
|
:type roundOutput: integer
|
|
257
264
|
|
|
@@ -319,6 +326,8 @@ class TimeSeriesAggregation(object):
|
|
|
319
326
|
|
|
320
327
|
self.solver = solver
|
|
321
328
|
|
|
329
|
+
self.numericalTolerance = numericalTolerance
|
|
330
|
+
|
|
322
331
|
self.segmentation = segmentation
|
|
323
332
|
|
|
324
333
|
self.roundOutput = roundOutput
|
|
@@ -388,21 +397,21 @@ class TimeSeriesAggregation(object):
|
|
|
388
397
|
try:
|
|
389
398
|
timedelta = self.timeSeries.index[1] - self.timeSeries.index[0]
|
|
390
399
|
self.resolution = float(timedelta.total_seconds()) / 3600
|
|
391
|
-
except AttributeError:
|
|
400
|
+
except AttributeError as exc:
|
|
392
401
|
raise ValueError(
|
|
393
402
|
"'resolution' argument has to be nonnegative float or int"
|
|
394
403
|
+ " or the given timeseries needs a datetime index"
|
|
395
|
-
)
|
|
404
|
+
) from exc
|
|
396
405
|
except TypeError:
|
|
397
406
|
try:
|
|
398
407
|
self.timeSeries.index = pd.to_datetime(self.timeSeries.index)
|
|
399
408
|
timedelta = self.timeSeries.index[1] - self.timeSeries.index[0]
|
|
400
409
|
self.resolution = float(timedelta.total_seconds()) / 3600
|
|
401
|
-
except:
|
|
410
|
+
except Exception as exc:
|
|
402
411
|
raise ValueError(
|
|
403
412
|
"'resolution' argument has to be nonnegative float or int"
|
|
404
413
|
+ " or the given timeseries needs a datetime index"
|
|
405
|
-
)
|
|
414
|
+
) from exc
|
|
406
415
|
|
|
407
416
|
if not (isinstance(self.resolution, int) or isinstance(self.resolution, float)):
|
|
408
417
|
raise ValueError("resolution has to be nonnegative float or int")
|
|
@@ -870,9 +879,9 @@ class TimeSeriesAggregation(object):
|
|
|
870
879
|
)
|
|
871
880
|
|
|
872
881
|
# reset values higher than the upper sacle or less than zero
|
|
873
|
-
typicalPeriods[column].clip(lower=0, upper=scale_ub
|
|
882
|
+
typicalPeriods[column] = typicalPeriods[column].clip(lower=0, upper=scale_ub)
|
|
874
883
|
|
|
875
|
-
typicalPeriods[column].fillna(0.0
|
|
884
|
+
typicalPeriods[column] = typicalPeriods[column].fillna(0.0)
|
|
876
885
|
|
|
877
886
|
# calc new sum and new diff to orig data
|
|
878
887
|
sum_clu_wo_peak = np.sum(
|
|
@@ -967,7 +976,7 @@ class TimeSeriesAggregation(object):
|
|
|
967
976
|
# check for additional cluster parameters
|
|
968
977
|
if self.evalSumPeriods:
|
|
969
978
|
evaluationValues = (
|
|
970
|
-
self.normalizedPeriodlyProfiles.stack(level=0)
|
|
979
|
+
self.normalizedPeriodlyProfiles.stack(future_stack=True,level=0)
|
|
971
980
|
.sum(axis=1)
|
|
972
981
|
.unstack(level=1)
|
|
973
982
|
)
|
|
@@ -1095,23 +1104,29 @@ class TimeSeriesAggregation(object):
|
|
|
1095
1104
|
if np.array(
|
|
1096
1105
|
self.typicalPeriods.max(axis=0) > self.timeSeries.max(axis=0)
|
|
1097
1106
|
).any():
|
|
1098
|
-
warning_list = self.typicalPeriods.max(axis=0)
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1107
|
+
warning_list = self.typicalPeriods.max(axis=0) > self.timeSeries.max(axis=0)
|
|
1108
|
+
diff = self.typicalPeriods.max(axis=0) - self.timeSeries.max(axis=0)
|
|
1109
|
+
if abs(diff).max() > self.numericalTolerance:
|
|
1110
|
+
warnings.warn(
|
|
1111
|
+
"At least one maximal value of the " +
|
|
1112
|
+
"aggregated time series exceeds the maximal value " +
|
|
1113
|
+
"the input time series for: " +
|
|
1114
|
+
"{}".format(diff[warning_list[warning_list>0].index].to_dict()) +
|
|
1115
|
+
". To silence the warning set the 'numericalTolerance' to a higher value."
|
|
1116
|
+
)
|
|
1105
1117
|
if np.array(
|
|
1106
1118
|
self.typicalPeriods.min(axis=0) < self.timeSeries.min(axis=0)
|
|
1107
1119
|
).any():
|
|
1108
1120
|
warning_list = self.typicalPeriods.min(axis=0) < self.timeSeries.min(axis=0)
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1121
|
+
diff = self.typicalPeriods.min(axis=0) - self.timeSeries.min(axis=0)
|
|
1122
|
+
if abs(diff).max() > self.numericalTolerance:
|
|
1123
|
+
warnings.warn(
|
|
1124
|
+
"Something went wrong... At least one minimal value of the " +
|
|
1125
|
+
"aggregated time series exceeds the minimal value " +
|
|
1126
|
+
"the input time series for: " +
|
|
1127
|
+
"{}".format(diff[warning_list[warning_list>0].index].to_dict()) +
|
|
1128
|
+
". To silence the warning set the 'numericalTolerance' to a higher value."
|
|
1129
|
+
)
|
|
1115
1130
|
return self.typicalPeriods
|
|
1116
1131
|
|
|
1117
1132
|
def prepareEnersysInput(self):
|
|
@@ -1237,7 +1252,7 @@ class TimeSeriesAggregation(object):
|
|
|
1237
1252
|
columns=self.normalizedPeriodlyProfiles.columns,
|
|
1238
1253
|
index=self.normalizedPeriodlyProfiles.index,
|
|
1239
1254
|
)
|
|
1240
|
-
clustered_data_df = clustered_data_df.stack(level="TimeStep")
|
|
1255
|
+
clustered_data_df = clustered_data_df.stack(future_stack=True,level="TimeStep")
|
|
1241
1256
|
|
|
1242
1257
|
# back in form
|
|
1243
1258
|
self.normalizedPredictedData = pd.DataFrame(
|
|
@@ -57,7 +57,7 @@ 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().sort_values()
|
|
60
|
+
sortedAttr = candidateValues.stack(future_stack=True,).sort_values()
|
|
61
61
|
# reindex and arrange such that every sorted segment gets represented by its mean
|
|
62
62
|
sortedAttr.index = pd.MultiIndex.from_tuples(clean_index)
|
|
63
63
|
representationValues = sortedAttr.unstack(level=0).mean(axis=1)
|
|
@@ -97,8 +97,8 @@ def durationRepresentation(
|
|
|
97
97
|
# concat centroid values and cluster weights for all clusters
|
|
98
98
|
meansAndWeights = pd.concat(
|
|
99
99
|
[
|
|
100
|
-
pd.DataFrame(np.array(meanVals)).stack(),
|
|
101
|
-
pd.DataFrame(np.array(clusterLengths)).stack(),
|
|
100
|
+
pd.DataFrame(np.array(meanVals)).stack(future_stack=True,),
|
|
101
|
+
pd.DataFrame(np.array(clusterLengths)).stack(future_stack=True,),
|
|
102
102
|
],
|
|
103
103
|
axis=1,
|
|
104
104
|
)
|
|
@@ -107,7 +107,7 @@ def durationRepresentation(
|
|
|
107
107
|
# save order of the sorted centroid values across all clusters
|
|
108
108
|
order = meansAndWeightsSorted.index
|
|
109
109
|
# sort all values of the original time series
|
|
110
|
-
sortedAttr = candidates.loc[:, a].stack().sort_values().values
|
|
110
|
+
sortedAttr = candidates.loc[:, a].stack(future_stack=True,).sort_values().values
|
|
111
111
|
# take mean of sections of the original duration curve according to the cluster and its weight the
|
|
112
112
|
# respective section is assigned to
|
|
113
113
|
representationValues = []
|
tsam/utils/k_medoids_exact.py
CHANGED
|
@@ -5,6 +5,11 @@ import numpy as np
|
|
|
5
5
|
from sklearn.base import BaseEstimator, ClusterMixin, TransformerMixin
|
|
6
6
|
from sklearn.metrics.pairwise import PAIRWISE_DISTANCE_FUNCTIONS
|
|
7
7
|
from sklearn.utils import check_array
|
|
8
|
+
|
|
9
|
+
# switch to numpy 2.0
|
|
10
|
+
np.float_ = np.float64
|
|
11
|
+
np.complex_=np.complex128
|
|
12
|
+
|
|
8
13
|
import pyomo.environ as pyomo
|
|
9
14
|
import pyomo.opt as opt
|
|
10
15
|
from pyomo.contrib import appsi
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: tsam
|
|
3
|
-
Version: 2.3.
|
|
3
|
+
Version: 2.3.5
|
|
4
4
|
Summary: Time series aggregation module (tsam) to create typical periods
|
|
5
5
|
Home-page: https://github.com/FZJ-IEK3-VSA/tsam
|
|
6
6
|
Author: Leander Kotzur, Maximilian Hoffmann
|
|
@@ -14,24 +14,21 @@ Classifier: Natural Language :: English
|
|
|
14
14
|
Classifier: Operating System :: OS Independent
|
|
15
15
|
Classifier: Programming Language :: Python
|
|
16
16
|
Classifier: Programming Language :: Python :: 2
|
|
17
|
-
Classifier: Programming Language :: Python :: 2.7
|
|
18
17
|
Classifier: Programming Language :: Python :: 3
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.4
|
|
20
|
-
Classifier: Programming Language :: Python :: 3.5
|
|
21
|
-
Classifier: Programming Language :: Python :: 3.6
|
|
22
18
|
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
23
19
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.9
|
|
24
21
|
Description-Content-Type: text/markdown
|
|
25
22
|
License-File: LICENSE.txt
|
|
26
23
|
Requires-Dist: scikit-learn >=0.0
|
|
27
|
-
Requires-Dist: pandas
|
|
28
|
-
Requires-Dist: numpy
|
|
24
|
+
Requires-Dist: pandas >=2.0.3
|
|
25
|
+
Requires-Dist: numpy >=1.20.0
|
|
29
26
|
Requires-Dist: pyomo >=6.4.3
|
|
30
27
|
Requires-Dist: networkx
|
|
31
28
|
Requires-Dist: tqdm
|
|
32
29
|
Requires-Dist: highspy
|
|
33
30
|
|
|
34
|
-
[](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)
|
|
35
32
|
[](https://mybinder.org/v2/gh/FZJ-IEK3-VSA/voila-tsam/HEAD?urlpath=voila/render/Time-Series-Aggregation-Module.ipynb)
|
|
36
33
|
|
|
37
34
|
<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>
|
|
@@ -52,10 +49,14 @@ The documentation of the tsam code can be found [**here**](https://tsam.readthed
|
|
|
52
49
|
|
|
53
50
|
|
|
54
51
|
## Installation
|
|
55
|
-
Directly install via pip as follows:
|
|
52
|
+
Directly install via pip from pypi as follows:
|
|
56
53
|
|
|
57
54
|
pip install tsam
|
|
58
55
|
|
|
56
|
+
of install from conda forge with the following command:
|
|
57
|
+
|
|
58
|
+
conda install tsam -c conda-forge
|
|
59
|
+
|
|
59
60
|
Alternatively, clone a local copy of the repository to your computer
|
|
60
61
|
|
|
61
62
|
git clone https://github.com/FZJ-IEK3-VSA/tsam.git
|
|
@@ -70,6 +71,12 @@ Or install directly via python as
|
|
|
70
71
|
python setup.py install
|
|
71
72
|
|
|
72
73
|
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 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
|
+
|
|
75
|
+
### Developer installation
|
|
76
|
+
|
|
77
|
+
In order to setup a virtual environment in Linux, correct the python name in the Makefile and call
|
|
78
|
+
|
|
79
|
+
make setup_venv
|
|
73
80
|
|
|
74
81
|
|
|
75
82
|
## Examples
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
tsam/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
tsam/hyperparametertuning.py,sha256=eM7m7eY80uSlwnLRxmctnis2Jv66D15Z1QD9CCMzSXE,10349
|
|
3
|
+
tsam/periodAggregation.py,sha256=h9CC06jBLNyyaFTMRynGUMN87fOH3NdSEug6EcTsKGA,5471
|
|
4
|
+
tsam/representations.py,sha256=2NL1wanBhGreCeJ8jh0aNdIx05YXEyyMJmMAVFS5-T4,7133
|
|
5
|
+
tsam/timeseriesaggregation.py,sha256=xLkdSmjbJnSxC0GBzF9Vc-6VMK7Y1OPOmQhdHJgymug,56963
|
|
6
|
+
tsam/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
tsam/utils/durationRepresentation.py,sha256=A-RjELO-58jBXbEHxxJ6TPZc2zPC560_SW7kNzw2ZPA,9463
|
|
8
|
+
tsam/utils/k_maxoids.py,sha256=0PyaHQMA8vtV_SuQOZ0qdcGFK46aUvOiMSQofjGkjBQ,4415
|
|
9
|
+
tsam/utils/k_medoids_contiguity.py,sha256=xSN9xT61oc2CPxYERhugR9hDkVCb2o8POvAiLLgrey8,5925
|
|
10
|
+
tsam/utils/k_medoids_exact.py,sha256=CW6BLQV2eTYtMxDmo97-6hY1HljxcvkPVrL4DQPN5IQ,7178
|
|
11
|
+
tsam/utils/segmentation.py,sha256=y8TPv1KEqf6ByOz7TRywm3WC9ZPhGiWvhwAcQbFibt4,6132
|
|
12
|
+
tsam-2.3.5.dist-info/LICENSE.txt,sha256=XEzEzumoCmdJzcp5gKT6UOtKrkH-SiGpxVbIfihkNK4,1224
|
|
13
|
+
tsam-2.3.5.dist-info/METADATA,sha256=ckzCWoHhvFqngqU4vPCUzCFOLmW7aL145Ff63fEPsmw,12581
|
|
14
|
+
tsam-2.3.5.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
15
|
+
tsam-2.3.5.dist-info/top_level.txt,sha256=MFI15PnPuMv8F1hTAOXbjGu41z-l6dJbnK69WlIQNcM,5
|
|
16
|
+
tsam-2.3.5.dist-info/RECORD,,
|
tsam-2.3.2.dist-info/RECORD
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
tsam/__init__.py,sha256=E6QTHxEAgUQUWz5m6udpRN8FdG7bivjaG0sau60TgBA,304
|
|
2
|
-
tsam/hyperparametertuning.py,sha256=eM7m7eY80uSlwnLRxmctnis2Jv66D15Z1QD9CCMzSXE,10349
|
|
3
|
-
tsam/periodAggregation.py,sha256=h9CC06jBLNyyaFTMRynGUMN87fOH3NdSEug6EcTsKGA,5471
|
|
4
|
-
tsam/representations.py,sha256=2NL1wanBhGreCeJ8jh0aNdIx05YXEyyMJmMAVFS5-T4,7133
|
|
5
|
-
tsam/timeseriesaggregation.py,sha256=NpHsu507m6TUGIiccU3dkDKjp2SKJkJp_8IQiTkjXSs,56066
|
|
6
|
-
tsam/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
-
tsam/utils/durationRepresentation.py,sha256=k5pu5m8cRLkU2T9pepZ3wUOgf6I9mn6YmoIHBnVR1yo,9391
|
|
8
|
-
tsam/utils/k_maxoids.py,sha256=0PyaHQMA8vtV_SuQOZ0qdcGFK46aUvOiMSQofjGkjBQ,4415
|
|
9
|
-
tsam/utils/k_medoids_contiguity.py,sha256=IeTucR7OI0iBfbTJs1nVXas5bZ44rVPS2bkb-EewXxc,5843
|
|
10
|
-
tsam/utils/k_medoids_exact.py,sha256=5F2vHZA3GxXkR-mt7XOtecsJSE8WjGAIhJLsjV9nWRI,7100
|
|
11
|
-
tsam/utils/segmentation.py,sha256=y8TPv1KEqf6ByOz7TRywm3WC9ZPhGiWvhwAcQbFibt4,6132
|
|
12
|
-
tsam-2.3.2.dist-info/LICENSE.txt,sha256=XEzEzumoCmdJzcp5gKT6UOtKrkH-SiGpxVbIfihkNK4,1224
|
|
13
|
-
tsam-2.3.2.dist-info/METADATA,sha256=jyD9NgubM4lzgeECguLdiGDF0_fKUgygjlYbVDBMCdQ,12404
|
|
14
|
-
tsam-2.3.2.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
|
|
15
|
-
tsam-2.3.2.dist-info/top_level.txt,sha256=MFI15PnPuMv8F1hTAOXbjGu41z-l6dJbnK69WlIQNcM,5
|
|
16
|
-
tsam-2.3.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|