-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFlipInput.py
118 lines (89 loc) · 4.92 KB
/
FlipInput.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
from pyecore.resources import ResourceSet, URI
from StringURI import StringURI
from esdl.esdl import *
import esdl
from xmlresource import XMLResource
import datetime
import uuid
import csv
import os
from datetime import date
today = date.today()
str_date = str(today)
def MakeESDL(RegioNaam, flipcsv, actions):
rset = ResourceSet()
rset.metamodel_registry[esdl.nsURI] = esdl
rset.resource_factory['esdl'] = lambda uri: XMLResource(uri) # we register the factory for '.esdl' extension and XML serialization
es_name = RegioNaam
# Create a new EnergySystem
es = EnergySystem(id=str(uuid.uuid4()), name=es_name)
instance = Instance(id=str(uuid.uuid4()), name='y2030')
# AbstractInstanceDate = InstanceDate.date(2020)
RawDate = '2030'
instance.date = InstanceDate(date=EDate.from_string(RawDate+"-01-01"))
instance.aggrType = AggrTypeEnum.PER_COMMODITY
es.instance.append(instance)
es.instance[0].area = Area(id=RegioNaam, name=RegioNaam)
esi = EnergySystemInformation(id=str(uuid.uuid4()))
qau = QuantityAndUnits(id=str(uuid.uuid4()))
es.energySystemInformation = esi
esi.quantityAndUnits = qau
s1a = Measures(id=str(uuid.uuid4()))
if not os.path.exists(flipcsv):
print("========= WARNING: {} does not exist! Skipping...".format(flipcsv))
else:
with open(flipcsv, newline='') as csvfile:
csvfile = (line.lower() for line in csvfile)
reader = csv.reader(csvfile, delimiter=';')
column_names = next(reader)
print(column_names)
for row in reader:
bu_code = row[column_names.index('bu_code')]
bu_code.replace('\'', '') # remove quotes from bu_code
area = Area(id=bu_code, scope="NEIGHBOURHOOD")
ce_buurtoptie = row[column_names.index('uitkomst_gecheckt')]
# measure = Measure(id=str(uuid.uuid4()),name=ce_buurtoptie)
if not ce_buurtoptie == '':
measures = Measures(id=str(uuid.uuid4()))
# measures.measure.append(ce_buurtoptie)
# ce_buurtoptie = row[column_names.index('uitkomst_gecheckt')]
# measure = Measure(id=str(uuid.uuid4()),name=ce_buurtoptie)
if ce_buurtoptie == 'all-electric':
measures.measure.append(MeasureReference(id=str(uuid.uuid4()),reference='S1a_B_LuchtWP'))
# measures.measure.append(MeasureReference(id=str(uuid.uuid4()),reference='s1b'))
if ce_buurtoptie == 'warmtenet':
measures.measure.append(MeasureReference(id=str(uuid.uuid4()),reference='S2a_B_Restwarmte'))
# measures.measure.append(MeasureReference(id=str(uuid.uuid4()),reference='s2b'))
# measures.measure.append(MeasureReference(id=str(uuid.uuid4()),reference='s3a'))
# measures.measure.append(MeasureReference(id=str(uuid.uuid4()),reference='s3b'))
# measures.measure.append(MeasureReference(id=str(uuid.uuid4()),reference='s3c'))
# measures.measure.append(MeasureReference(id=str(uuid.uuid4()),reference='s3d'))
measures.measure.append(MeasureReference(id=str(uuid.uuid4()),reference='S3e_B_TEO'))
if ce_buurtoptie == 'groengas':
measures.measure.append(MeasureReference(id=str(uuid.uuid4()),reference='S4a_GG_B_hWP'))
# measure.append(MeasureReference(id=str(uuid.uuid4()),reference='s4b'))
ed_app_sv.profileQuantityAndUnit = MeasureReference(reference=s1a)
ed_app_ip.profile.append(ed_app_sv)
area.measures = measures
es.instance[0].area.area.append(area)
# <measures xsi:type="esdl:Measures">
# <measure xsi:type="esdl:Measure" id="S1a_B_LuchtWP" name="S1a_B_LuchtWP"/>
# <measure xsi:type="esdl:Measure" id="S3a_B_LT30_30" name="S3a_B_LT30_30"/>
# <measure xsi:type="esdl:Measure" id="S0_Referentie" name="S0_Referentie"/>
# </measures>
if 'save_to_disk' in actions:
export_name = "FlipInput/%s.esdl" %(RegioNaam)
resource = rset.create_resource(URI(export_name))
resource.append(es)
resource.save()
def main():
# RegioNamen= ["Havenstad"]
RegioNamen= ["GooiEnVechtstreek"]
# RegioNamen= ["Havenstad","GooiEnVechtstreek","Hengelo"]
for RegioNaam in RegioNamen:
flipcsv = "flipinput/%s_voorkeursopties.csv" %(RegioNaam)
MakeESDL(RegioNaam, flipcsv, ['save_to_disk'])
print("ESDL-output generated for: ", RegioNaam)
print(" ")
if __name__ == '__main__':
main()