-
Notifications
You must be signed in to change notification settings - Fork 34
/
test_hierarchical.py
78 lines (58 loc) · 2 KB
/
test_hierarchical.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import time
import pandas as pd
import numpy as np
import tsam.timeseriesaggregation as tsam
def test_hierarchical():
raw = pd.read_csv(
os.path.join(os.path.dirname(__file__), "..", "examples", "testdata.csv"),
index_col=0,
)
orig_raw = pd.read_csv(
os.path.join(
os.path.dirname(__file__),
"..",
"examples",
"results",
"testperiods_hierarchical.csv",
),
index_col=[0, 1],
)
starttime = time.time()
aggregation = tsam.TimeSeriesAggregation(
raw,
noTypicalPeriods=8,
hoursPerPeriod=24,
clusterMethod="hierarchical",
extremePeriodMethod="new_cluster_center",
addPeakMin=["T"],
addPeakMax=["Load"],
)
typPeriods = aggregation.createTypicalPeriods()
print("Clustering took " + str(time.time() - starttime))
# sort the typical days in order to avoid error assertion due to different order
sortedDaysOrig = orig_raw.groupby(level=0).sum().sort_values("GHI").index
sortedDaysTest = typPeriods.groupby(level=0).sum().sort_values("GHI").index
# rearange their order
orig = orig_raw[typPeriods.columns].unstack().loc[sortedDaysOrig, :].stack()
test = typPeriods.unstack().loc[sortedDaysTest, :].stack()
np.testing.assert_array_almost_equal(orig.values, test.values, decimal=4)
def test_hierarchical_for_weeks():
raw = pd.read_csv(
os.path.join(os.path.dirname(__file__), "..", "examples", "testdata.csv"),
index_col=0,
)
starttime = time.time()
aggregation = tsam.TimeSeriesAggregation(
raw,
noTypicalPeriods=8,
hoursPerPeriod=24*7,
clusterMethod="hierarchical",
extremePeriodMethod="new_cluster_center",
addPeakMin=["T"],
addPeakMax=["Load"],
)
typPeriods = aggregation.createTypicalPeriods()
print("Clustering took " + str(time.time() - starttime))
if __name__ == "__main__":
test_hierarchical()