-
Notifications
You must be signed in to change notification settings - Fork 4
/
temoa_schema.sql
463 lines (381 loc) · 13.3 KB
/
temoa_schema.sql
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
BEGIN TRANSACTION;
/*
-------------------------------------------------------
Tables in this section correspond to Sets
-------------------------------------------------------
*/
-- User-defined flags to split set elements into proper subsets
CREATE TABLE time_period_labels (
t_period_labels text primary key,
t_period_labels_desc text);
INSERT INTO "time_period_labels" VALUES('e', 'existing vintages');
INSERT INTO "time_period_labels" VALUES('f', 'future');
CREATE TABLE technology_labels (
tech_labels text primary key,
tech_labels_desc text);
INSERT INTO "technology_labels" VALUES('r', 'resource technology');
INSERT INTO "technology_labels" VALUES('p', 'production technology');
INSERT INTO "technology_labels" VALUES('pb', 'baseload production technology');
INSERT INTO "technology_labels" VALUES('ps', 'storage production technology');
CREATE TABLE commodity_labels (
comm_labels text primary key,
comm_labels_desc text);
INSERT INTO "commodity_labels" VALUES('p', 'physical commodity');
INSERT INTO "commodity_labels" VALUES('e', 'emissions commodity');
INSERT INTO "commodity_labels" VALUES('d', 'demand commodity');
CREATE TABLE sector_labels (
sector text primary key);
INSERT INTO "sector_labels" VALUES('supply');
INSERT INTO "sector_labels" VALUES('electric');
INSERT INTO "sector_labels" VALUES('transport');
INSERT INTO "sector_labels" VALUES('commercial');
INSERT INTO "sector_labels" VALUES('residential');
INSERT INTO "sector_labels" VALUES('industrial');
--Tables below correspond to Temoa sets
CREATE TABLE time_periods (
t_periods integer primary key,
flag text,
FOREIGN KEY(flag) REFERENCES time_period_labels(t_period_labels));
CREATE TABLE time_season (
t_season text primary key );
CREATE TABLE time_of_day (
t_day text primary key );
CREATE TABLE technologies (
tech text primary key,
flag text,
sector text,
tech_desc text,
tech_category text,
FOREIGN KEY(flag) REFERENCES technology_labels(tech_labels),
FOREIGN KEY(sector) REFERENCES sector_labels(sector));
CREATE TABLE commodities (
comm_name text primary key,
flag text,
comm_desc text,
FOREIGN KEY(flag) REFERENCES commodity_labels(comm_labels));
/*
-------------------------------------------------------
Tables in this section correspond to Parameters
-------------------------------------------------------
*/
CREATE TABLE SegFrac (
season_name text,
time_of_day_name text,
segfrac real check (segfrac>=0 AND segfrac<=1),
segfrac_notes text,
PRIMARY KEY(season_name, time_of_day_name), --here's where I define primary key as a combo of columns
FOREIGN KEY(season_name) REFERENCES time_season(t_season),
FOREIGN KEY(time_of_day_name) REFERENCES time_of_day(t_day) );
CREATE TABLE DemandSpecificDistribution (
season_name text,
time_of_day_name text,
demand_name text,
dds real check (dds>=0 AND dds<=1),
dds_notes text,
PRIMARY KEY(season_name, time_of_day_name, demand_name),
FOREIGN KEY(season_name) REFERENCES time_season(t_season),
FOREIGN KEY(time_of_day_name) REFERENCES time_of_day(t_day),
FOREIGN KEY(demand_name) REFERENCES commodities(comm_name) );
CREATE TABLE CapacityToActivity (
tech text primary key,
c2a real,
c2a_notes,
FOREIGN KEY(tech) REFERENCES technologies(tech) );
CREATE TABLE GlobalDiscountRate (
rate real );
CREATE TABLE DiscountRate (
tech text,
vintage integer,
tech_rate real,
tech_rate_notes text,
PRIMARY KEY(tech, vintage),
FOREIGN KEY(tech) REFERENCES technologies(tech),
FOREIGN KEY(vintage) REFERENCES time_periods(t_periods));
CREATE TABLE EmissionActivity (
emis_comm text,
input_comm text,
tech text,
vintage integer,
output_comm text,
emis_act real,
emis_act_units text,
emis_act_notes text,
PRIMARY KEY(emis_comm, input_comm, tech, vintage, output_comm),
FOREIGN KEY(emis_comm) REFERENCES commodities(comm_name),
FOREIGN KEY(input_comm) REFERENCES commodities(comm_name),
FOREIGN KEY(tech) REFERENCES technologies(tech),
FOREIGN KEY(vintage) REFERENCES time_periods(t_periods),
FOREIGN KEY(output_comm) REFERENCES commodities(comm_name) );
CREATE TABLE EmissionLimit (
periods integer,
emis_comm text,
emis_limit real,
emis_limit_units text,
emis_limit_notes text,
PRIMARY KEY(periods, emis_comm),
FOREIGN KEY(periods) REFERENCES time_periods(t_periods),
FOREIGN KEY(emis_comm) REFERENCES commodities(comm_name) );
CREATE TABLE Demand (
periods integer,
demand_comm text,
demand real,
demand_units text,
demand_notes text,
PRIMARY KEY(periods, demand_comm),
FOREIGN KEY(periods) REFERENCES time_periods(t_periods),
FOREIGN KEY(demand_comm) REFERENCES commodities(comm_name) );
CREATE TABLE TechInputSplit (
periods integer,
input_comm text,
tech text,
ti_split real,
ti_split_notes text,
PRIMARY KEY(periods, input_comm, tech),
FOREIGN KEY(periods) REFERENCES time_periods(t_periods),
FOREIGN KEY(input_comm) REFERENCES commodities(comm_name),
FOREIGN KEY(tech) REFERENCES technologies(tech) );
CREATE TABLE TechOutputSplit (
periods integer,
tech text,
output_comm text,
to_split real,
to_split_notes text,
PRIMARY KEY(periods, tech, output_comm),
FOREIGN KEY(periods) REFERENCES time_periods(t_periods),
FOREIGN KEY(tech) REFERENCES technologies(tech),
FOREIGN KEY(output_comm) REFERENCES commodities(comm_name) );
CREATE TABLE MinCapacity (
periods integer,
tech text,
mincap real,
mincap_units text,
mincap_notes text,
PRIMARY KEY(periods, tech),
FOREIGN KEY(periods) REFERENCES time_periods(t_periods),
FOREIGN KEY(tech) REFERENCES technologies(tech) );
CREATE TABLE MaxCapacity (
periods integer,
tech text,
maxcap real,
maxcap_units text,
maxcap_notes text,
PRIMARY KEY(periods, tech),
FOREIGN KEY(periods) REFERENCES time_periods(t_periods),
FOREIGN KEY(tech) REFERENCES technologies(tech) );
CREATE TABLE MinActivity (
periods integer,
tech text,
minact real,
minact_units text,
minact_notes text,
PRIMARY KEY(periods, tech),
FOREIGN KEY(periods) REFERENCES time_periods(t_periods),
FOREIGN KEY(tech) REFERENCES technologies(tech) );
CREATE TABLE MaxActivity (
periods integer,
tech text,
maxact real,
maxact_units text,
maxact_notes text,
PRIMARY KEY(periods, tech),
FOREIGN KEY(periods) REFERENCES time_periods(t_periods),
FOREIGN KEY(tech) REFERENCES technologies(tech) );
CREATE TABLE GrowthRateMax (
tech text,
growthrate_max real,
growthrate_max_notes text,
FOREIGN KEY(tech) REFERENCES technologies(tech) );
CREATE TABLE GrowthRateSeed (
tech text,
growthrate_seed real,
growthrate_seed_units text,
growthrate_seed_notes text,
FOREIGN KEY(tech) REFERENCES technologies(tech) );
CREATE TABLE LifetimeTech (
tech text,
life real,
life_notes text,
PRIMARY KEY(tech),
FOREIGN KEY(tech) REFERENCES technologies(tech) );
CREATE TABLE LifetimeProcess (
tech text,
vintage integer,
life_process real,
life_process_notes text,
PRIMARY KEY(tech, vintage),
FOREIGN KEY(tech) REFERENCES technologies(tech),
FOREIGN KEY(vintage) REFERENCES time_periods(t_periods) );
CREATE TABLE LifetimeLoanTech (
tech text,
loan real,
loan_notes text,
PRIMARY KEY(tech),
FOREIGN KEY(tech) REFERENCES technologies(tech) );
CREATE TABLE CapacityFactorTech (
season_name text,
time_of_day_name text,
tech text,
cf_tech real check (cf_tech >=0 AND cf_tech <=1),
cf_tech_notes text,
PRIMARY KEY(season_name, time_of_day_name, tech),
FOREIGN KEY(season_name) REFERENCES time_season(t_season),
FOREIGN KEY(time_of_day_name) REFERENCES time_of_day(t_day),
FOREIGN KEY(tech) REFERENCES technologies(tech) );
CREATE TABLE CapacityFactorProcess (
season_name text,
time_of_day_name text,
tech text,
vintage integer,
cf_process real check (cf_process >=0 AND cf_process <=1),
cf_process_notes text,
PRIMARY KEY(season_name, time_of_day_name, tech, vintage),
FOREIGN KEY(season_name) REFERENCES time_season(t_season),
FOREIGN KEY(time_of_day_name) REFERENCES time_of_day(t_day),
FOREIGN KEY(tech) REFERENCES technologies(tech) );
CREATE TABLE Efficiency (
input_comm text,
tech text,
vintage integer,
output_comm text,
efficiency real check (efficiency>0),
eff_notes text,
PRIMARY KEY(input_comm, tech, vintage, output_comm),
FOREIGN KEY(input_comm) REFERENCES commodities(comm_name),
FOREIGN KEY(tech) REFERENCES technologies(tech),
FOREIGN KEY(vintage) REFERENCES time_periods(t_periods),
FOREIGN KEY(output_comm) REFERENCES commodities(comm_name) );
CREATE TABLE ExistingCapacity (
tech text,
vintage integer,
exist_cap real,
exist_cap_units text,
exist_cap_notes text,
PRIMARY KEY(tech, vintage),
FOREIGN KEY(tech) REFERENCES technologies(tech),
FOREIGN KEY(vintage) REFERENCES time_periods(t_periods) );
CREATE TABLE CostInvest (
tech text,
vintage integer,
cost_invest real,
cost_invest_units text,
cost_invest_notes text,
PRIMARY KEY(tech, vintage),
FOREIGN KEY(tech) REFERENCES technologies(tech),
FOREIGN KEY(vintage) REFERENCES time_periods(t_periods) );
CREATE TABLE CostFixed (
periods integer NOT NULL,
tech text NOT NULL,
vintage integer NOT NULL,
cost_fixed real,
cost_fixed_units text,
cost_fixed_notes text,
PRIMARY KEY(periods, tech, vintage),
FOREIGN KEY(periods) REFERENCES time_periods(t_periods),
FOREIGN KEY(tech) REFERENCES technologies(tech),
FOREIGN KEY(vintage) REFERENCES time_periods(t_periods) );
CREATE TABLE CostVariable (
periods integer NOT NULL,
tech text NOT NULL,
vintage integer NOT NULL,
cost_variable real,
cost_variable_units text,
cost_variable_notes text,
PRIMARY KEY(periods, tech, vintage),
FOREIGN KEY(periods) REFERENCES time_periods(t_periods),
FOREIGN KEY(tech) REFERENCES technologies(tech),
FOREIGN KEY(vintage) REFERENCES time_periods(t_periods) );
/*
-------------------------------------------------------
Tables in this section store model outputs
-------------------------------------------------------
*/
CREATE TABLE Output_VFlow_Out (
scenario text,
sector text,
t_periods integer,
t_season text,
t_day text,
input_comm text,
tech text,
vintage integer,
output_comm text,
vflow_out real,
PRIMARY KEY(scenario, t_periods, t_season, t_day, input_comm, tech, vintage, output_comm),
FOREIGN KEY(sector) REFERENCES sector_labels(sector),
FOREIGN KEY(t_periods) REFERENCES time_periods(t_periods),
FOREIGN KEY(t_season) REFERENCES time_periods(t_periods),
FOREIGN KEY(t_day) REFERENCES time_of_day(t_day),
FOREIGN KEY(input_comm) REFERENCES commodities(comm_name),
FOREIGN KEY(tech) REFERENCES technologies(tech),
FOREIGN KEY(vintage) REFERENCES time_periods(t_periods),
FOREIGN KEY(output_comm) REFERENCES commodities(comm_name));
CREATE TABLE Output_VFlow_In (
scenario text,
sector text,
t_periods integer,
t_season text,
t_day text,
input_comm text,
tech text,
vintage integer,
output_comm text,
vflow_in real,
PRIMARY KEY(scenario, t_periods, t_season, t_day, input_comm, tech, vintage, output_comm),
FOREIGN KEY(sector) REFERENCES sector_labels(sector),
FOREIGN KEY(t_periods) REFERENCES time_periods(t_periods),
FOREIGN KEY(t_season) REFERENCES time_periods(t_periods),
FOREIGN KEY(t_day) REFERENCES time_of_day(t_day),
FOREIGN KEY(input_comm) REFERENCES commodities(comm_name),
FOREIGN KEY(tech) REFERENCES technologies(tech),
FOREIGN KEY(vintage) REFERENCES time_periods(t_periods),
FOREIGN KEY(output_comm) REFERENCES commodities(comm_name));
CREATE TABLE Output_V_Capacity (
scenario text,
sector text,
tech text,
vintage integer,
capacity real,
PRIMARY KEY(scenario, tech, vintage),
FOREIGN KEY(sector) REFERENCES sector_labels(sector),
FOREIGN KEY(tech) REFERENCES technologies(tech),
FOREIGN KEY(vintage) REFERENCES time_periods(t_periods));
CREATE TABLE Output_CapacityByPeriodAndTech (
scenario text,
sector text,
t_periods integer,
tech text,
capacity real,
PRIMARY KEY(scenario, t_periods, tech),
FOREIGN KEY(sector) REFERENCES sector_labels(sector),
FOREIGN KEY(t_periods) REFERENCES time_periods(t_periods),
FOREIGN KEY(tech) REFERENCES technologies(tech));
CREATE TABLE Output_Emissions (
scenario text,
sector text,
t_periods integer,
emissions_comm text,
tech text,
vintage integer,
emissions real,
PRIMARY KEY(scenario, t_periods, emissions_comm, tech, vintage),
FOREIGN KEY(sector) REFERENCES sector_labels(sector),
FOREIGN KEY(emissions_comm) REFERENCES EmissionActivity(emis_comm),
FOREIGN KEY(t_periods) REFERENCES time_periods(t_periods),
FOREIGN KEY(tech) REFERENCES technologies(tech)
FOREIGN KEY(vintage) REFERENCES time_periods(t_periods));
CREATE TABLE Output_Costs (
scenario text,
sector text,
output_name text,
tech text,
vintage integer,
output_cost real,
PRIMARY KEY(scenario, output_name, tech, vintage),
FOREIGN KEY(sector) REFERENCES sector_labels(sector),
FOREIGN KEY(tech) REFERENCES technologies(tech),
FOREIGN KEY(vintage) REFERENCES time_periods(t_periods));
CREATE TABLE Output_Objective (
scenario text,
objective_name text,
total_system_cost real );
COMMIT;