-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-ema-etm.py
171 lines (133 loc) · 4.65 KB
/
example-ema-etm.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
# ema_etm.py
from functools import cache
from ema_workbench import (
Model,
RealParameter,
ScalarOutcome,
Constant,
perform_experiments,
)
from ema_workbench.em_framework.parameters import Scenario
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# import ETM connection
from ETMeta import ETMapi
metrics = [
"dashboard_reduction_of_co2_emissions_versus_1990",
"dashboard_renewability",
"dashboard_share_of_renewable_electricity",
"dashboard_energy_import_netto",
"dashboard_total_costs",
"dashboard_energy_demand_primary_of_final_plus_export_losses",
"dashboard_blackout_hours",
"dashboard_total_number_of_excess_events",
"dashboard_security_of_supply",
"lv_net_capacity_delta_present_future",
"mv_net_capacity_delta_present_future",
"hv_net_capacity_delta_present_future",
]
def init_ETM(ref_scenario, metrics):
ETMa = ETMapi(scenario_id=ref_scenario)
ETMa.verbose = False
ETMa.create_new_scenario("EMA scenario", use_custom_values=False)
ETMa.gqueries = metrics
return ETMa
@cache
def ETMwrapper(
ETM_instance=None,
solarVSwind=None,
flh_of_energy_power_wind_turbine_inland=None,
flh_of_solar_pv_solar_radiation=None,
costs_co2=None,
total_supply=None,
):
if ETM_instance is None:
ETMi = ETMapi()
else:
ETMi = ETM_instance
constants = {
"flh_of_energy_power_wind_turbine_inland": flh_of_energy_power_wind_turbine_inland,
"flh_of_solar_pv_solar_radiation": flh_of_solar_pv_solar_radiation,
"costs_co2": costs_co2,
}
capacity_of_energy_power_wind_turbine_inland = (
solarVSwind * total_supply / flh_of_energy_power_wind_turbine_inland
)
capacity_of_energy_power_solar_pv_solar_radiation = (
(1 - solarVSwind) * total_supply / flh_of_solar_pv_solar_radiation
)
ETMi.user_values = {
"capacity_of_energy_power_wind_turbine_inland": capacity_of_energy_power_wind_turbine_inland,
"capacity_of_energy_power_solar_pv_solar_radiation": capacity_of_energy_power_solar_pv_solar_radiation,
}
ETMi.user_values.update(constants)
ETMi.update_inputs()
ETMi._update_metrics(output_format="dict")
getter = lambda m: ETMi.metrics.get(m, 0)["future"]
return {metric: getter(metric) for metric in metrics}
model = Model("ETMwrapper", function=ETMwrapper)
# set levers
model.levers = [RealParameter("solarVSwind", 0, 1)]
# specify outcomes
model.outcomes = [ScalarOutcome(metric) for metric in metrics]
# model.outcomes = [ScalarOutcome("hv_net_capacity_delta_present_future")]
# initiate ETM connection
ref_scenario = 769771
ETM = init_ETM(ref_scenario, metrics)
# override some of the defaults of the model
model.constants = [
# standard = 1920 hours / year
Constant("ETM_instance", ETM),
Constant("flh_of_energy_power_wind_turbine_inland", 3000),
Constant("flh_of_solar_pv_solar_radiation", 1000), # standard = 867 / year
Constant("costs_co2", 100), # standard = 8 €/tonne
Constant("total_supply", 55e6), # MWh 35e6 minimum, RES 1.0 55e6
]
results = perform_experiments(model, policies=25)
experiments, outcomes = results
policies = experiments["policy"]
for i, policy in enumerate(np.unique(policies)):
experiments.loc[policies == policy, "policy"] = str(i)
data = pd.DataFrame(outcomes)
data["solarVSwind"] = experiments["solarVSwind"]
#%% plotting section
colors = sns.color_palette("Set2", len(data.columns))
sns.set_style("whitegrid")
to_plot1 = [
"dashboard_reduction_of_co2_emissions_versus_1990",
"dashboard_share_of_renewable_electricity",
"dashboard_total_costs",
]
to_plot2 = [
"dashboard_total_number_of_excess_events",
"dashboard_security_of_supply",
]
def multi_scatter_stack(data, to_plot, title=None, save_fig=False):
fig, ax = plt.subplots(len(to_plot), 1, sharex=True, figsize=(10, 10))
for i, col in enumerate(to_plot):
sns.scatterplot(
data=data,
x="solarVSwind",
y=col,
palette=[colors[i]],
ax=ax[i],
)
ax[i].set_ylabel("")
ax[i].set_title(col)
sns.despine(left=True, bottom=True)
if title is not None:
plt.suptitle(title)
if save_fig:
plt.savefig(title + ".png")
multi_scatter_stack(data, to_plot1, title='Cost and renewability', save_fig=True)
multi_scatter_stack(data, to_plot2, title='Curtailment and underload', save_fig=True)
# %%
from ema_workbench.analysis import feature_scoring
x = experiments
y = outcomes
fs = feature_scoring.get_feature_scores_all(x, y)
sns.heatmap(fs, cmap='viridis', annot=True)
plt.show()
# %%