-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckers.py
137 lines (125 loc) · 4.61 KB
/
checkers.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
import numpy as np
import sys
from IPython.display import display, Markdown, Latex
def checker_df(value, discount_rate, years):
"""Checks if the values of the discount factor are correct based on the discount rate and years array as inputs.
Parameters
----------
value: np.ndarray
Array of discount factors over the years.
discount_rate: float
Discount rate as fraction.
years: np.ndarray
Array of years over the analysis period.
Returns
-------
str
Displays wheter the calculated value is correct or not.
"""
df = (1 + discount_rate) ** -years
if isinstance(value, np.ndarray):
if len(value) != len(years):
return print("The length of your array should be the same as the number of years.")
elif sum(df == value) == len(df):
return print("Your answer is correct!")
else:
return print("The values provided are not correct. They should be:\n{}".format(
df
))
else:
return display(Markdown("The argument `df` needs to be of type `np.array()`"))
def checker_lcoe(
value,
capital_costs,
operational_costs,
electricity_generation,
discount_rate,
technical_lifetime
):
"""Checks if the calculated lcoe value is correct based on the capital costs, operational costs, electricity generation, discount rate and technical lifetime of the project.
Parameters
----------
value: float
Calculated lcoe value to check.
capital_costs: float
Capital costs of the project.
operational_costs: np.ndarray
Array of operational costs over the analysis period.
electricity_generation: np.ndarray
Array of generated electricity over the analysis period.
discount_rate: float
Discount rate as fraction.
technical_lifetime: int
Years of the analysis period.
Returns
-------
str
Displays wheter the calculated value is correct or not.
"""
try:
if isinstance(value, float):
year = np.arange(technical_lifetime)
df = (1 + discount_rate) ** - year
lcoe = (capital_costs + sum(df * operational_costs)) / \
sum(df * electricity_generation)
if value == lcoe:
return print("Your answer is correct!")
else:
return print("That is not right, try again!")
else:
return display(Markdown("The argument `lcoe` needs to be of type `float`"))
except:
return print("Unexpected error: {}".format(sys.exc_info()[0]))
raise
def checker_parameters(
el_gen,
op_costs,
capacity,
load_factor,
fixed_om_cost,
fuel_price,
efficiency,
lifetime
):
"""Checks if the electricity calculations and the operational costs are calculated correctly.
Parameters
----------
el_gen: np.ndarray
Array of generated electricity over the analysis period.
op_costs: np.ndarray
Array of operational costs over the analysis period.
capacit: float
Installed capacity of the plant.
load_factor: float
The load factor describes the proportion of those 8760 hours the plant is operational.
fixed_om_cost: float
Fix costs of the power plant per kW of capacity.
fuel_price: float
Fuel price per kWh used.
efficiency: float
Energy convertion efficiency of the plant.
lifetime: int
Years of the analysis period.
Returns
-------
str
Displays wheter the calculated value is correct or not.
"""
electricity_generation = np.repeat(capacity * load_factor * 8760, lifetime) # in kWh
annual_fixed_om_cost = capacity * fixed_om_cost # in €
annual_variable_om_cost = fuel_price * electricity_generation / efficiency # in €
operational_costs = annual_fixed_om_cost + annual_variable_om_cost # in €
try:
if sum(el_gen) == sum(electricity_generation):
str_out = 'Your electricity generation is correct!\n'
else:
str_out = f'Your electricity generation is not right... it should be {electricity_generation}\n'
if sum(op_costs) == sum(operational_costs):
str_out += 'Your operational costs are correct!'
else:
str_out += f'Your operational costs are not right... they should be {operational_costs}'
return print(str_out)
except:
return print("Unexpected error: {}".format(sys.exc_info()[0]),
'Make sure your electricity generation and operational values are of type np.ndarray')
raise