-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsources.py
341 lines (278 loc) · 14.3 KB
/
sources.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
from source_meta import SolarMeta, WindMeta, GridMeta, \
GasGenMeta, HFOGenMeta, TriFuelGenMeta, BESSMeta, DGenMeta, PPAMeta, ExistingGasGenMeta
class Source:
def __init__(self, n, source_type, src_priority):
self.n = n
self.inputs = self.create_input_structure()
self.outputs = self.create_output_structure()
self.source_type = source_type
self.priority = src_priority
def create_input_structure(self):
return {
year: {
'count_prim_units': 0,
'rating_prim_units': 0
}
for year in range(0, self.n + 1)
}
def create_output_structure(self):
output = {}
for year in range(0, self.n + 1):
output[year] = {
'capital_cost': 0,
'depreciation_cost': 0,
}
for month in range(1, 13):
output[year][month] = {
'energy_output_prim_units': 0,
'fixed_opex': 0,
'num_pot_failures': 0,
'num_failures': 0,
'failure_duration': 0,
'co2_emissions': 0
}
for hour in range(1, 25):
output[year][month][hour] = {
'power_output_prim_units': 0,
'loading_prim_units': 0
}
return output
class SolarSource(Source):
def __init__(self, n, src_p):
super().__init__(n, 'Solar',src_p)
self.meta = SolarMeta()
def calc_output_power(self, current_year, month, hour):
# Calculate degradation for each year's capacity and then sum up
degraded_capacity_mw = 0
degradation_rate = self.meta.degradation if hasattr(self.meta, 'degradation') else 0
for year, yr_data in self.inputs.items():
if isinstance(year, int) and year <= current_year:
years_of_operation = current_year - year
degradation_factor = 1 - (degradation_rate * years_of_operation/100)
degraded_capacity_mw += yr_data['count_prim_units'] * yr_data['rating_prim_units'] * degradation_factor
return degraded_capacity_mw * self.meta.output_data[month][hour]['kw_pv_output_per_mw'] / 1000
def calc_output_energy(self, current_year, month):
# Calculate degradation for each year's capacity and then sum up
degraded_capacity_mw = 0
degradation_rate = self.meta.degradation if hasattr(self.meta, 'degradation') else 0
for year, yr_data in self.inputs.items():
if isinstance(year, int) and year <= current_year:
years_of_operation = current_year - year
degradation_factor = 1 - (degradation_rate * years_of_operation/100)
degraded_capacity_mw += yr_data['count_prim_units'] * yr_data['rating_prim_units'] * degradation_factor
if year == current_year:
break
return degraded_capacity_mw * self.meta.output_data[month]['mnth_ener_op_per_MW']
class BESSSource(Source):
def __init__(self, n, src_p):
super().__init__(n,'BESS',src_p)
self.meta = BESSMeta()
class WindSource(Source):
def __init__(self, n, src_p):
super().__init__(n,'Wind', src_p)
self.meta = WindMeta()
def calc_output_power(self, current_year, month, hour):
# Calculate degradation for each year's capacity and then sum up
degraded_capacity_mw = 0
degradation_rate = self.meta.degradation if hasattr(self.meta, 'degradation') else 0
for year, yr_data in self.inputs.items():
if isinstance(year, int) and year <= current_year:
years_of_operation = current_year - year
degradation_factor = 1 - (degradation_rate * years_of_operation/100)
degraded_capacity_mw += yr_data['count_prim_units'] * yr_data['rating_prim_units'] * degradation_factor
if year == current_year:
break
wind_speed = self.meta.output_data[month][hour]['windspeed_at_100m']
output_multiplier = 0
if wind_speed >= 7.5:
output_multiplier = 1
elif wind_speed >= 6:
output_multiplier = self.meta.output_multiplier_3
elif wind_speed >= 5:
output_multiplier = self.meta.output_multiplier_2
elif wind_speed >= 4:
output_multiplier = self.meta.output_multiplier_1
return degraded_capacity_mw * output_multiplier
def calc_output_energy(self, current_year, month):
return sum(self.calc_output_power(current_year,month, hour) for hour in range(1, 25))
class GridSource(Source):
def __init__(self, n, src_p):
super().__init__(n,'Grid', src_p)
self.meta = GridMeta()
#add output structure here to accomodate peak and off peak units
self.extend_output_structure()
def extend_output_structure(self):
# Extend output structure with Grid Source specific keys
for year in range(self.n + 1):
for month in range(1, 13):
self.outputs[year][month]['energy_output_peak'] = 0
self.outputs[year][month]['energy_output_offpeak'] = 0
self.outputs[year][month]['peak_enr_charges'] = 0
self.outputs[year][month]['offpeak_enr_charges'] = 0
self.outputs[year][month]['fixed_charges'] = 0
class PPASource(Source):
def __init__(self, n, src_p):
super().__init__(n,'PPA', src_p)
self.meta = PPAMeta()
#add output structure here to accomodate peak and off peak units
self.extend_output_structure()
def extend_output_structure(self):
# Extend output structure with Grid Source specific keys
for year in range(self.n + 1):
for month in range(1, 13):
self.outputs[year][month]['enr_charges'] = 0
self.outputs[year][month]['fixed_charges'] = 0
def calc_output_power(self, current_year, month, hour):
# Calculate degradation for each year's capacity and then sum up
degraded_capacity_mw = 0
degradation_rate = self.meta.degradation if hasattr(self.meta, 'degradation') else 0
for year, yr_data in self.inputs.items():
if isinstance(year, int) and year <= current_year:
years_of_operation = current_year - year
degradation_factor = 1 - (degradation_rate * years_of_operation/100)
degraded_capacity_mw += yr_data['count_prim_units'] * yr_data['rating_prim_units'] * degradation_factor
return degraded_capacity_mw * self.meta.output_data[month][hour]['kw_pv_output_per_mw'] / 1000
def calc_output_energy(self, current_year, month):
# Calculate degradation for each year's capacity and then sum up
degraded_capacity_mw = 0
degradation_rate = self.meta.degradation if hasattr(self.meta, 'degradation') else 0
for year, yr_data in self.inputs.items():
if isinstance(year, int) and year <= current_year:
years_of_operation = current_year - year
degradation_factor = 1 - (degradation_rate * years_of_operation/100)
degraded_capacity_mw += yr_data['count_prim_units'] * yr_data['rating_prim_units'] * degradation_factor
if year == current_year:
break
return degraded_capacity_mw * self.meta.output_data[month]['mnth_ener_op_per_MW']
class GasGenSource(Source):
def __init__(self, n, src_p):
super().__init__(n, 'Gas Generator', src_p)
self.meta = GasGenMeta()
self.extend_input_structure()
self.extend_output_structure()
def extend_input_structure(self):
# Extend input structure with GasGenSource specific keys
for year in range(self.n + 1): # Use range based on n to iterate over years
self.inputs[year]['rating_backup_units'] = 0
self.inputs[year]['count_backup_units'] = 0
self.inputs[year]['perc_rated_output'] = 0
self.inputs[year]['fuel_eff'] = 100
# These two keys are not associated with a specific year, so they remain the same
self.inputs['chp_operation'] = False
self.inputs['fuel_type'] = 'NG'
def extend_output_structure(self):
# Extend output structure with GasGenSource specific keys
for year in range(self.n + 1):
for month in range(1, 13): # Use range for months
self.outputs[year][month]['energy_output_backup_units'] = 0
self.outputs[year][month]['energy_free_cooling'] = 0
self.outputs[year][month]['var_opex'] = 0
self.outputs[year][month]['fuel_charges'] = 0
for hour in range(1, 25): # Use range for hours
self.outputs[year][month][hour]['power_output_backup_units'] = 0
self.outputs[year][month][hour]['loading_backup_units'] = 0
class ExistingGasGenSource(Source):
def __init__(self, n, src_p):
super().__init__(n, 'Existing Gas Generators', src_p)
self.meta = ExistingGasGenMeta()
self.extend_input_structure()
self.extend_output_structure()
def extend_input_structure(self):
# Extend input structure with GasGenSource specific keys
for year in range(self.n + 1): # Use range based on n to iterate over years
self.inputs[year]['rating_backup_units'] = 0
self.inputs[year]['count_backup_units'] = 0
self.inputs[year]['perc_rated_output'] = 0
self.inputs[year]['fuel_eff'] = 100
# These two keys are not associated with a specific year, so they remain the same
self.inputs['chp_operation'] = False
self.inputs['fuel_type'] = 'NG'
def extend_output_structure(self):
# Extend output structure with GasGenSource specific keys
for year in range(self.n + 1):
for month in range(1, 13): # Use range for months
self.outputs[year][month]['energy_output_backup_units'] = 0
self.outputs[year][month]['energy_free_cooling'] = 0
self.outputs[year][month]['var_opex'] = 0
self.outputs[year][month]['fuel_charges'] = 0
for hour in range(1, 25): # Use range for hours
self.outputs[year][month][hour]['power_output_backup_units'] = 0
self.outputs[year][month][hour]['loading_backup_units'] = 0
class HFOGenSource(Source):
def __init__(self, n, src_p):
super().__init__(n,'HFO Generator', src_p)
self.meta = HFOGenMeta()
self.extend_input_structure()
self.extend_output_structure()
def extend_input_structure(self):
# Extend input structure with GasGenSource specific keys
for year in range(self.n + 1):
self.inputs[year]['rating_backup_units'] = 0
self.inputs[year]['count_backup_units'] = 0
self.inputs[year]['perc_rated_output'] = 0
self.inputs[year]['fuel_eff'] = 100
self.inputs['chp_operation'] = False
self.inputs['fuel_type'] = 'HFO'
def extend_output_structure(self):
# Extend output structure with GasGenSource specific keys
for year in range(self.n + 1):
for month in range(1, 13):
self.outputs[year][month]['energy_output_backup_units'] = 0
self.outputs[year][month]['energy_free_cooling'] = 0
self.outputs[year][month]['var_opex'] = 0
self.outputs[year][month]['fuel_charges'] = 0
for hour in range(1, 25):
self.outputs[year][month][hour]['power_output_backup_units'] = 0
self.outputs[year][month][hour]['loading_backup_units'] = 0
class TrifuelGenSource(Source):
def __init__(self, n, src_p):
super().__init__(n,'HFO+Gas Generator', src_p)
self.meta = TriFuelGenMeta()
self.extend_input_structure()
self.extend_output_structure()
def extend_input_structure(self):
# Extend input structure with GasGenSource specific keys
for year in range(self.n + 1):
self.inputs[year]['rating_backup_units'] = 0
self.inputs[year]['count_backup_units'] = 0
self.inputs[year]['perc_rated_output'] = 0
self.inputs[year]['fuel_eff'] = 100
self.inputs['chp_operation'] = False
self.inputs['fuel_type'] = 'RLNG'
self.inputs['sec_fuel_type'] = 'HFO'
def extend_output_structure(self):
# Extend output structure with GasGenSource specific keys
for year in range(self.n + 1):
for month in range(1, 13):
self.outputs[year][month]['energy_output_prim_units_sec'] = 0
self.outputs[year][month]['energy_output_backup_units'] = 0
self.outputs[year][month]['energy_output_backup_units_sec'] = 0
self.outputs[year][month]['energy_free_cooling'] = 0
self.outputs[year][month]['var_opex'] = 0
self.outputs[year][month]['fuel_charges'] = 0
self.outputs[year][month]['fuel_charges_sec'] = 0
for hour in range(1, 25):
self.outputs[year][month][hour]['power_output_backup_units'] = 0
self.outputs[year][month][hour]['loading_backup_units'] = 0
def gas_hfo_enr_op(self, energy):
gas_enr = energy * self.meta.gas_op_prop/100
hfo_enr = energy - gas_enr
return gas_enr, hfo_enr
class DieselGenSource(Source):
def __init__(self, n, src_p):
super().__init__(n,'Diesel Generator', src_p)
self.meta = DGenMeta()
self.extend_input_structure()
self.extend_output_structure()
def extend_input_structure(self):
# Extend input structure with GasGenSource specific keys
for year in range(self.n + 1):
self.inputs[year]['perc_rated_output'] = 0
self.inputs[year]['fuel_eff'] = 100
self.inputs['fuel_type'] = 'Diesel'
def extend_output_structure(self):
# Extend output structure with Diesel Gen specific keys
for year in range(self.n + 1):
for month in range(1, 13): # Use range for months
self.outputs[year][month]['var_opex'] = 0
self.outputs[year][month]['fuel_charges'] = 0