-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpre_processing.py
More file actions
58 lines (41 loc) · 1.72 KB
/
pre_processing.py
File metadata and controls
58 lines (41 loc) · 1.72 KB
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
"""
Performs some final post-processing on aggregated data
Written by Ian David Elder for the CANOE model
"""
import sqlite3
from setup import config
def process():
conn = sqlite3.connect(config.database_file)
curs = conn.cursor()
"""
##############################################################
Fill basic tables
##############################################################
"""
# Add default global discount rate. No index on this table so clear it first.
# curs.execute(f"UPDATE MetaDataReal SET value = {config.params['global_discount_rate']} WHERE element == 'global_discount_rate'")
# Add future model periods
for i, period in enumerate([*config.model_periods, config.model_periods[-1] + config.params['period_step']]):
curs.execute(f"""REPLACE INTO
TimePeriod(sequence, period, flag)
VALUES({i}, {period}, "f")""")
# Add regions
for region in config.model_regions:
description = "outside model" if region == "EX" else config.regions.loc[region, 'description']
curs.execute(f"""REPLACE INTO
Region(region, notes)
VALUES("{region}", "{description}")""")
# Add seasons and times of day
curs.execute(f"DELETE FROM SeasonLabel")
curs.execute(f"DELETE FROM TimeOfDay")
for h, row in config.time.iterrows():
curs.execute(f"""INSERT OR IGNORE INTO
SeasonLabel(season)
VALUES("{row['season']}")""")
curs.execute(f"""INSERT OR IGNORE INTO
TimeOfDay(sequence, tod)
VALUES({h}, "{row['tod']}")""")
conn.commit()
conn.close()
if __name__ == "__main__":
process()