-
Notifications
You must be signed in to change notification settings - Fork 4
/
tests.py
159 lines (140 loc) · 6.59 KB
/
tests.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
"""Tests to check whether the models behave as required."""
import os
import logging
import numpy as np
import pandas as pd
import models
import main
# Install costs and generation costs. These should match the information
# provided in the model.yaml and techs.yaml files in the model definition
COSTS = pd.DataFrame(columns=['install', 'generation'])
# Heterogenised costs for 6 region model
COSTS.loc['baseload_region1'] = [300.1, 0.005001]
COSTS.loc['baseload_region3'] = [300.3, 0.005003]
COSTS.loc['baseload_region6'] = [300.6, 0.005006]
COSTS.loc['peaking_region1'] = [100.1, 0.035001]
COSTS.loc['peaking_region3'] = [100.3, 0.035003]
COSTS.loc['peaking_region6'] = [100.6, 0.035006]
COSTS.loc['wind_region2'] = [100.2, 0.000002]
COSTS.loc['wind_region5'] = [100.5, 0.000005]
COSTS.loc['wind_region6'] = [100.6, 0.000006]
COSTS.loc['unmet_region2'] = [ 0.0, 6.000002]
COSTS.loc['unmet_region4'] = [ 0.0, 6.000004]
COSTS.loc['unmet_region5'] = [ 0.0, 6.000005]
COSTS.loc['transmission_region1_region2'] = [100.12, 0]
COSTS.loc['transmission_region1_region5'] = [150.15, 0]
COSTS.loc['transmission_region1_region6'] = [100.16, 0]
COSTS.loc['transmission_region2_region3'] = [100.23, 0]
COSTS.loc['transmission_region3_region4'] = [100.34, 0]
COSTS.loc['transmission_region4_region5'] = [100.45, 0]
COSTS.loc['transmission_region5_region6'] = [100.56, 0]
# Topology of 6 region model. These should match the information provided
# in the locations.yaml files in the model definition
BASELOAD_TOP, PEAKING_TOP, WIND_TOP, UNMET_TOP, DEMAND_TOP = (
[('baseload', i) for i in ['region1', 'region3', 'region6']],
[('peaking', i) for i in ['region1', 'region3', 'region6']],
[('wind', i) for i in ['region2', 'region5', 'region6']],
[('unmet', i) for i in ['region2', 'region4', 'region5']],
[('demand', i) for i in ['region2', 'region4', 'region5']]
)
TRANSMISSION_TOP = [('transmission', *i)
for i in [('region1', 'region2'),
('region1', 'region5'),
('region1', 'region6'),
('region2', 'region3'),
('region3', 'region4'),
('region4', 'region5'),
('region5', 'region6')]]
def test_output_consistency_6_region(model, run_mode):
"""Check if model outputs are internally consistent for 6 region model.
Parameters:
-----------
model (calliope.Model) : instance of OneRegionModel or SixRegionModel
run_mode (str) : 'plan' or 'operate'
Returns:
--------
passing: True if test is passed, False otherwise
"""
passing = True
cost_total_method1 = 0
out = model.get_summary_outputs()
res = model.results
corrfac = 8760/model.num_timesteps # For annualisation
# Test if generation technology installation costs are consistent
if run_mode == 'plan':
for tech, region in BASELOAD_TOP + PEAKING_TOP + WIND_TOP:
cost_method1 = float(
COSTS.loc['{}_{}'.format(tech, region), 'install'] *
out.loc['cap_{}_{}'.format(tech, region)]
)
cost_method2 = corrfac * float(
res.cost_investment[0].loc['{}::{}_{}'.format(region,
tech,
region)]
)
if abs(cost_method1 - cost_method2) > 0.1:
logging.error('FAIL: %s install costs in %s do not match!\n'
' manual: %s, model: %s',
tech, region, cost_method1, cost_method2)
passing = False
cost_total_method1 += cost_method1
# Test if transmission installation costs are consistent
if run_mode == 'plan':
for tech, region_a, region_b in TRANSMISSION_TOP:
cost_method1 = float(
COSTS.loc[
'{}_{}_{}'.format(tech, region_a, region_b), 'install'
] * out.loc[
'cap_transmission_{}_{}'.format(region_a, region_b)
]
)
cost_method2 = 2 * corrfac * \
float(res.cost_investment[0].loc[
'{}::{}_{}_{}:{}'.format(region_a,
tech,
region_a,
region_b,
region_b)
])
if abs(cost_method1 - cost_method2) > 0.1:
logging.error('FAIL: %s install costs from %s to %s do '
'not match!\n manual: %s, model: %s',
tech, region_a, region_b,
cost_method1, cost_method2)
passing = False
cost_total_method1 += cost_method1
# Test if generation costs are consistent
for tech, region in BASELOAD_TOP + PEAKING_TOP + WIND_TOP + UNMET_TOP:
cost_method1 = float(
COSTS.loc['{}_{}'.format(tech, region), 'generation']
* out.loc['gen_{}_{}'.format(tech, region)]
)
cost_method2 = corrfac * float(
res.cost_var[0].loc['{}::{}_{}'.format(region, tech, region)].sum()
)
if abs(cost_method1 - cost_method2) > 0.1:
logging.error('FAIL: %s generation costs in %s do not match!\n'
' manual: %s, model: %s',
tech, region, cost_method1, cost_method2)
passing = False
cost_total_method1 += cost_method1
# Test if total costs are consistent
if run_mode == 'plan':
cost_total_method2 = corrfac * float(res.cost.sum())
if abs(cost_total_method1 - cost_total_method2) > 0.1:
logging.error('FAIL: total system costs do not match!\n'
' manual: %s, model: %s',
cost_total_method1, cost_total_method2)
passing = False
# Test if supply matches demand
generation_total = float(out.loc[['gen_baseload_total',
'gen_peaking_total',
'gen_wind_total',
'gen_unmet_total']].sum())
demand_total = float(out.loc['demand_total'])
if abs(generation_total - demand_total) > 0.1:
logging.error('FAIL: generation does not match demand!\n'
' generation: %s, demand: %s',
generation_total, demand_total)
passing = False
return passing