-
Notifications
You must be signed in to change notification settings - Fork 0
/
compute.py
52 lines (39 loc) · 1.43 KB
/
compute.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
"""
"""
from pathlib import Path
import os
from oemof.solph import EnergySystem, Model, processing
# DONT REMOVE THIS LINE!
from oemof.tabular import datapackage # noqa
from oemof.tabular.constraint_facades import CONSTRAINT_TYPE_MAP
#from oemof.tabular.examples.scripting.compute import results_path
from oemof.tabular.facades import TYPEMAP
from oemof.tabular.postprocessing import calculations
scenario_name="dispatch_tsam"
datapackage_path=Path(Path(__file__).parent,scenario_name)
results_path=Path(datapackage_path,'results')
if not results_path.exists():
Path.mkdir(results_path)
# create energy system object
es = EnergySystem.from_datapackage(
os.path.join(datapackage_path, "datapackage.json"),
attributemap={},
typemap=TYPEMAP,
)
# create model from energy system (this is just oemof.solph)
m = Model(es)
# add constraints from datapackage to the model
m.add_constraints_from_datapackage(
os.path.join(datapackage_path, "datapackage.json"),
constraint_type_map=CONSTRAINT_TYPE_MAP,
)
# if you want dual variables / shadow prices uncomment line below
# m.receive_duals()
# select solver 'gurobi', 'cplex', 'glpk' etc
m.solve('cbc')
es.params = processing.parameter_as_dict(es)
es.results = m.results()
# now we use the write results method to write the results in oemof-tabular
# format
postprocessed_results = calculations.run_postprocessing(es)
postprocessed_results.to_csv(os.path.join(results_path, "results.csv"))