tsam 2.3.6__py3-none-any.whl → 2.3.8__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/timeseriesaggregation.py +3 -0
- tsam/utils/durationRepresentation.py +63 -52
- {tsam-2.3.6.dist-info → tsam-2.3.8.dist-info}/METADATA +5 -4
- {tsam-2.3.6.dist-info → tsam-2.3.8.dist-info}/RECORD +7 -7
- {tsam-2.3.6.dist-info → tsam-2.3.8.dist-info}/WHEEL +1 -1
- {tsam-2.3.6.dist-info → tsam-2.3.8.dist-info/licenses}/LICENSE.txt +0 -0
- {tsam-2.3.6.dist-info → tsam-2.3.8.dist-info}/top_level.txt +0 -0
tsam/timeseriesaggregation.py
CHANGED
|
@@ -199,6 +199,9 @@ class TimeSeriesAggregation(object):
|
|
|
199
199
|
differently evaluated while the clustering process. optional (default: None )
|
|
200
200
|
:type weightDict: dict
|
|
201
201
|
|
|
202
|
+
:param segmentation: Boolean if time steps in periods should be aggregated to segments. optional (default: False)
|
|
203
|
+
:type segmentation: boolean
|
|
204
|
+
|
|
202
205
|
:param extremePeriodMethod: Method how to integrate extreme Periods (peak demand, lowest temperature etc.)
|
|
203
206
|
into to the typical period profiles. optional, default: 'None'
|
|
204
207
|
|br| Options are:
|
|
@@ -28,69 +28,80 @@ def durationRepresentation(
|
|
|
28
28
|
:type representMinMax: bool
|
|
29
29
|
"""
|
|
30
30
|
|
|
31
|
-
#
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
# Convert candidates to numpy array at the beginning if it's a DataFrame
|
|
32
|
+
if isinstance(candidates, pd.DataFrame):
|
|
33
|
+
candidates_array = candidates.values
|
|
34
|
+
else:
|
|
35
|
+
candidates_array = candidates
|
|
36
|
+
|
|
37
|
+
# Create a pandas DataFrame only when necessary
|
|
38
|
+
columnTuples = [(i, j) for i in range(int(candidates_array.shape[1] / timeStepsPerPeriod))
|
|
39
|
+
for j in range(timeStepsPerPeriod)]
|
|
40
|
+
|
|
41
|
+
candidates_df = pd.DataFrame(
|
|
42
|
+
candidates_array, columns=pd.MultiIndex.from_tuples(columnTuples)
|
|
39
43
|
)
|
|
40
|
-
|
|
41
|
-
# There are two options for the duration representation. Either, the distribution of each cluster is preserved
|
|
42
|
-
# (periodWise = True) or the distribution of the total time series is preserved only. In the latter case, the
|
|
43
|
-
# inner-cluster variance is smaller and the variance across the typical periods' mean values is higher
|
|
44
|
+
|
|
44
45
|
if distributionPeriodWise:
|
|
45
46
|
clusterCenters = []
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
#
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
47
|
+
unique_clusters = np.unique(clusterOrder)
|
|
48
|
+
|
|
49
|
+
for clusterNum in unique_clusters:
|
|
50
|
+
indice = np.where(clusterOrder == clusterNum)[0]
|
|
51
|
+
noCandidates = len(indice)
|
|
52
|
+
|
|
53
|
+
# Pre-allocate the full cluster center array
|
|
54
|
+
cluster_values_count = noCandidates * timeStepsPerPeriod * len(candidates_df.columns.levels[0])
|
|
55
|
+
clusterCenter = np.zeros(cluster_values_count)
|
|
56
|
+
current_idx = 0
|
|
57
|
+
|
|
58
|
+
for a in candidates_df.columns.levels[0]:
|
|
59
|
+
# Get values using numpy indexing when possible
|
|
60
|
+
candidateValues = candidates_df.loc[indice, a].values
|
|
61
|
+
|
|
62
|
+
# Reshape to more easily work with numpy
|
|
63
|
+
candidateValues_reshaped = candidateValues.reshape(-1)
|
|
64
|
+
|
|
65
|
+
# Sort values using numpy
|
|
66
|
+
sorted_values = np.sort(candidateValues_reshaped)
|
|
67
|
+
|
|
68
|
+
# Calculate representative values directly
|
|
69
|
+
values_per_timestep = noCandidates
|
|
70
|
+
representation_values = np.zeros(timeStepsPerPeriod)
|
|
71
|
+
|
|
72
|
+
for t in range(timeStepsPerPeriod):
|
|
73
|
+
start_idx = t * values_per_timestep
|
|
74
|
+
end_idx = start_idx + values_per_timestep
|
|
75
|
+
representation_values[t] = np.mean(sorted_values[start_idx:end_idx])
|
|
76
|
+
|
|
77
|
+
# Handle min/max representation if needed
|
|
67
78
|
if representMinMax:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
#
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
clusterCenters.append(clusterCenter)
|
|
83
|
-
|
|
79
|
+
representation_values[0] = sorted_values[0]
|
|
80
|
+
representation_values[-1] = sorted_values[-1]
|
|
81
|
+
|
|
82
|
+
# Re-order values based on the mean of candidate values
|
|
83
|
+
mean_values = np.mean(candidateValues, axis=0)
|
|
84
|
+
order_indices = np.argsort(mean_values)
|
|
85
|
+
|
|
86
|
+
# Reorder representation values
|
|
87
|
+
representation_values_ordered = representation_values[order_indices]
|
|
88
|
+
|
|
89
|
+
# Add to cluster center
|
|
90
|
+
clusterCenter[current_idx:current_idx+len(representation_values)] = representation_values_ordered
|
|
91
|
+
current_idx += len(representation_values)
|
|
92
|
+
|
|
93
|
+
clusterCenters.append(clusterCenter[:current_idx]) # Trim if we didn't use the whole pre-allocation
|
|
94
|
+
|
|
84
95
|
else:
|
|
85
96
|
clusterCentersList = []
|
|
86
|
-
for a in
|
|
97
|
+
for a in candidates_df.columns.levels[0]:
|
|
87
98
|
meanVals = []
|
|
88
99
|
clusterLengths = []
|
|
89
100
|
for clusterNum in np.unique(clusterOrder):
|
|
90
101
|
indice = np.where(clusterOrder == clusterNum)
|
|
91
102
|
noCandidates = len(indice[0])
|
|
92
103
|
# get all the values of a certain attribute and cluster
|
|
93
|
-
candidateValues =
|
|
104
|
+
candidateValues = candidates_df.loc[indice[0], a]
|
|
94
105
|
# calculate centroid of each cluster and append to list
|
|
95
106
|
meanVals.append(candidateValues.mean())
|
|
96
107
|
# make a list of weights of each cluster for each time step within the period
|
|
@@ -113,7 +124,7 @@ def durationRepresentation(
|
|
|
113
124
|
order = meansAndWeightsSorted.index
|
|
114
125
|
# sort all values of the original time series
|
|
115
126
|
sortedAttr = (
|
|
116
|
-
|
|
127
|
+
candidates_df.loc[:, a]
|
|
117
128
|
.stack(
|
|
118
129
|
future_stack=True,
|
|
119
130
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: tsam
|
|
3
|
-
Version: 2.3.
|
|
3
|
+
Version: 2.3.8
|
|
4
4
|
Summary: Time series aggregation module (tsam) to create typical periods
|
|
5
5
|
Author-email: Leander Kotzur <leander.kotzur@googlemail.com>, Maximilian Hoffmann <maximilian.hoffmann@julumni.fz-juelich.de>
|
|
6
6
|
Maintainer-email: Julian Belina <j.belina@fz-juelich.de>
|
|
@@ -37,7 +37,7 @@ Classifier: Programming Language :: Python :: 2
|
|
|
37
37
|
Classifier: Programming Language :: Python :: 3
|
|
38
38
|
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
39
39
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
40
|
-
Requires-Python: <3.
|
|
40
|
+
Requires-Python: <3.14,>=3.9
|
|
41
41
|
Description-Content-Type: text/markdown
|
|
42
42
|
License-File: LICENSE.txt
|
|
43
43
|
Requires-Dist: scikit-learn>=0.0
|
|
@@ -53,8 +53,9 @@ Requires-Dist: pytest-cov; extra == "dev"
|
|
|
53
53
|
Requires-Dist: codecov; extra == "dev"
|
|
54
54
|
Requires-Dist: sphinx; extra == "dev"
|
|
55
55
|
Requires-Dist: sphinx-autobuild; extra == "dev"
|
|
56
|
-
Requires-Dist:
|
|
56
|
+
Requires-Dist: sphinx_book_theme; extra == "dev"
|
|
57
57
|
Requires-Dist: twine; extra == "dev"
|
|
58
|
+
Dynamic: license-file
|
|
58
59
|
|
|
59
60
|
[](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)
|
|
60
61
|
[](https://mybinder.org/v2/gh/FZJ-IEK3-VSA/voila-tsam/HEAD?urlpath=voila/render/Time-Series-Aggregation-Module.ipynb)
|
|
@@ -2,15 +2,15 @@ tsam/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
2
2
|
tsam/hyperparametertuning.py,sha256=eM7m7eY80uSlwnLRxmctnis2Jv66D15Z1QD9CCMzSXE,10349
|
|
3
3
|
tsam/periodAggregation.py,sha256=h9CC06jBLNyyaFTMRynGUMN87fOH3NdSEug6EcTsKGA,5471
|
|
4
4
|
tsam/representations.py,sha256=2NL1wanBhGreCeJ8jh0aNdIx05YXEyyMJmMAVFS5-T4,7133
|
|
5
|
-
tsam/timeseriesaggregation.py,sha256=
|
|
5
|
+
tsam/timeseriesaggregation.py,sha256=UdsjsP8RAwmdBHq0wJwB2HfUai538NYRQkK31TR9dBM,57125
|
|
6
6
|
tsam/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
-
tsam/utils/durationRepresentation.py,sha256=
|
|
7
|
+
tsam/utils/durationRepresentation.py,sha256=_Pu4Zzq5MlQuNz4fnjf7uBpsWqmdkOlw73WJBhAJC9c,10052
|
|
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.8.dist-info/licenses/LICENSE.txt,sha256=XEzEzumoCmdJzcp5gKT6UOtKrkH-SiGpxVbIfihkNK4,1224
|
|
13
|
+
tsam-2.3.8.dist-info/METADATA,sha256=Eyilk3PrVxLSS_6NMpfJO_ThQvIwusU4nmsJbRB87tk,15412
|
|
14
|
+
tsam-2.3.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
15
|
+
tsam-2.3.8.dist-info/top_level.txt,sha256=MFI15PnPuMv8F1hTAOXbjGu41z-l6dJbnK69WlIQNcM,5
|
|
16
|
+
tsam-2.3.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|