-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_analysis.py
84 lines (72 loc) · 2.74 KB
/
test_analysis.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
79
80
81
82
83
84
import numpy as np
import pandas as pd
from enlopy.utils import make_timeseries
from enlopy.analysis import reshape_timeseries, get_LDC, get_load_stats
def test_reshape_timeseries():
a = np.random.rand(8760)
b = reshape_timeseries(a, x='dayofyear', y='hour')
assert b.shape == (24,365)
assert np.isclose(b.sum().sum(), a.sum())
def test_reshape_timeseries_week():
a = np.random.rand(8760)
b = reshape_timeseries(a, x='hour', y='week', aggfunc='mean')
assert b.shape == (52,24)
assert np.isclose(b.mean().mean(), a.mean(),0.001)
def test_reshape_multiannual():
a = np.random.rand(8760*2)
a = make_timeseries(a, year=2019, freq='h')
b = reshape_timeseries(a, x='dayofyear', y='hour', aggfunc='sum')
assert b.shape == (24,365)
assert np.isclose(b.sum().sum(), a.sum())
def test_reshape_multiannual_dataframe():
a = np.random.rand(8760*2)
a = pd.DataFrame(make_timeseries(a, year=2019, freq='h'))
b = reshape_timeseries(a, x='dayofyear', y='hour', aggfunc='sum')
assert b.shape == (24,365)
assert np.isclose(b.sum().sum(), a.sum())
def test_reshape_monthly_multiannual():
ind = pd.DatetimeIndex(pd.date_range(start='Jan-1990', end='Jan-2017', freq='M'))
a = pd.DataFrame(np.random.rand(324), index=ind)
b = reshape_timeseries(a, x='month', y='year', aggfunc='sum')
assert b.shape == (27, 12) # 27 years, 12 months
assert np.isclose(b.sum().sum(), a.sum())
def test_get_LDC():
a = np.random.rand(8760*2)
a = make_timeseries(a, freq='h')
b = get_LDC(a)
assert np.isclose(b[1].sum(), a.sum())
#check monotonicity
assert np.all(np.diff(b[1]) < 0)
def test_get_LDC_not_annual():
a = np.random.rand(10000)
a = make_timeseries(a, freq='h')
b = get_LDC(a)
assert np.isclose(b[1].sum(), a.sum())
#check monotonicity
assert np.all(np.diff(b[1]) < 0)
def test_get_LDC_not_annual_ndarray():
a = np.random.rand(10000)
b = get_LDC(a)
assert np.isclose(b[1].sum(), a.sum())
#check monotonicity
assert np.all(np.diff(b[1]) < 0)
def test_get_LDC_2d():
a = np.random.rand(8760, 4)
a = make_timeseries(a, freq='h')
b = get_LDC(a)
assert np.isclose(np.nansum(b[1]), np.nansum(a))
# check monotonicity
assert np.all(np.diff(b[1].sum(1)) < 0)
def test_get_stats():
a = np.ones(8760)
a = make_timeseries(a, freq='h')
b = get_load_stats(a)
assert a.sum() == b.loc['Sum'].squeeze()
assert np.asarray(b.loc['Ramps (98%)'])[0] == (0,0)
assert np.isclose(0, b.loc['Trend'].squeeze())
assert 1 == b.loc['Load Factor (peakiness)'].squeeze()
def test_get_stats_df():
a = np.ones(8760)
a = make_timeseries(a, freq='h').to_frame()
b = get_load_stats(a)
assert a.sum().sum() == b.loc['Sum'].squeeze()