-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHumanReadableQueries.sql
More file actions
3325 lines (3263 loc) · 232 KB
/
HumanReadableQueries.sql
File metadata and controls
3325 lines (3263 loc) · 232 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
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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ***Human readable versions of "standard" queries analysing results from the UK TIMES [UKTM] model***
/*Developed against model ver = uktm_model_v1.2.3_d0.1.2_DNP
This file is a "human readable" (= formatted) version of key regularly re-used crosstabs in various DOS batch files (.BAT). As far as possible, these replicate
Veda BE tables (here reproduced as CTEs). There are several sections in the file, each corresponding to a different BAT. These are themed
(e.g. transport), and the final batch is a general set of model output metrics which are likely to be useful most of the time. This version of the code includes
comments which are not included in the BAT versions.
Requires: postgres 9.4 or higher, DOS. Works on plain text "VD" file outputs from Veda / UKTM
NB * If a particular model run doesn't build it, then there will be no entry in the VD file for it and hence no line in the results output —
with few exceptions lines which are completely zero are not reported
* Queries are "wrapped" with a "copy" statement. Destinations of these files ") TO... " are in BAT syntax. In interactive mode (if running these queries in a postgres browser),
you'll have to change these to a full path (e.g. C:\0\...csv) or else the q will not run. By default, headings are not output for all except the first q.
Can add these by adding the "HEADER" keyword after the "CSV" statement but before the ';'. Instead, and if you don't want CSV output, you can copy the q without the surrounding
"copy (... ) TO " statement. If taking this approach, may require a terminating ';' (When a q is wrapped with "copy", the last SQL statement _should_not_ be terminated
with a ";".)
* Filters are as specific as possible with wildcards removed. This means that the qs will have to be carefully revised if the structure of the model changes.
* There is Ruby code to build batch files from this file. It recognises what goes in which batch by looking for headings with 2 asterisks together and
"BAT" in capitals, + no "End of". It looks for these things + "End of" to figure out where a set of batch queries ends. Be careful not to change these and to set up any other batch entries in the same way.
General comment: order of headings in output is:
id [= concatenation of all other fields]
analysis
tablename
attribute
commodity
process
...followed by years to 2060
Fernley Symons, 2015 ff
Original version:
FS 7:12 PM 20-Nov-15
Revisions section placed at end of file.
*/
/* ******List of completed queries*******/
/* **Miscellaneous queries (not included in batch files): ** */
/* ----------------------------------------------------------*/
/* *Total fuel consumption by fuel for other industry (industry sub-sector)* */ --line 80
/* **Electricity Batch File: ** */ --line 181
/* ------------------------------------------*/
/* *Annual timesliced elec storage output (techs grouped)* */ --line 183
/* **For agriculture / LULUCF batch file: ** */ --line 227
/* ------------------------------------------*/
/* *Landfill CH4 emission mitigation and residual emissions* */ --line 229
/* *Land use and crop / livestock mitigation (MACC) measures* */ --line 266
/* *Afforestation rate* */ --line 307
/* **For transport batch file: ** */ --line 334
/* -------------------------------*/
/* *Whole stock vehicle kms, emissions and emission intensity for 29 vehicle types* */ --line 337
/* *New stock vehicle kms, emissions and emission intensity for 29 vehicle types* */ --line 505
/* *Whole stock capacity for vehicles for 29 vehicle types* */ --line 660
/* *New build capacity for vehicles for 29 vehicle types* */ --line 714
/* *TRA_Fuel_by_mode* */ --line 769
/* *Road transport fuel by mode and fuel* */ --line 859
/* **Main "key outputs" crosstabs** */ --line 909
/* -------------------------------*/
/* *Dummy imports by table* */ --line 911
/* *All GHG emissions* */ --line 941
/* *GHG emissions by sector* */ --line 972
/* *GHG and sequestered emissions by industry sub-sector* */ --line 1036
/* *Electricity generation by source* */ --line 1130
/* *Electricity storage by type* */ --line 1674
/* *Electricity capacity by process* */ --line 1708
/* *Costs by sector and type* */ --line 1790
/* *Marginal prices for emissions* */ --line 1843
/* *Whole stock heat output by process for residential* */ --line 1873
/* *New build residential heat output by source* */ --line 1946
/* *Whole stock heat output for services* */ --line 2012
/* *New build services heat output by source* */ --line 2100
/* *End user final energy demand by sector* */ --line 2160
/* *Primary energy demand and biomass, imports exports and domestic production* */ --line 2778
/* *Total fuel consumption by fuel for other industry (industry sub-sector)* */
with ind_oi_chp as (
-- I.e. the Veda BE table of the same name
select comm_set,tablename, period,pv
from (
select tablename, period,pv,
case
when commodity in('INDBENZ','INDBFG','INDCOK','INDCOG') then 'IND MANFUELS' --Filter 278
when commodity in('INDCOACOK','INDCOA') then 'IND COALS' --Filter 257
when commodity in('INDELC','INDDISTELC') then 'IND ELEC' --Filter 242
when commodity in('INDHFO','INDLFO','INDLPG','INDKER') then 'IND OIL' --Filter 360
when commodity in('INDMAINSGAS','INDNGA') then 'IND GAS' --Filter 313
when commodity in('INDMAINSHYG','INDHYG') then 'IND HYDROGEN' --Filter 268
when commodity in('INDMSWORG','INDMSWINO','INDWOD','INDPELH','INDPOLWST','INDBIOLFO','INDPELL','INDMAINSBOM',
'INDBIOOIL','INDWODWST','INDBOG-AD','INDBIOLPG','INDGRASS','INDBOG-LF') then 'IND BIO' --Filter 376
else null
end as comm_set
from vedastore
where attribute='VAR_FIn' and
process in('IOICHPBIOS01','IOICHPCCGT01','IOICHPBIOS00','IOICHPCCGTH01','IOICHPNGA00','IOICHPHFO00','IOICHPGT01','IOICHPBIOG01','IOICHPFCH01','IOICHPCOA01')
) a
where comm_set is not null
), ind_oi_prd as (
-- I.e. the Veda BE table of the same name
select comm_set,tablename, period,pv
from (
select tablename, period,pv,
case
when commodity in('INDBENZ','INDBFG','INDCOK','INDCOG') then 'IND MANFUELS' --Filter 278
when commodity in('INDCOA','INDCOACOK') then 'IND COALS' --Filter 257
when commodity in('INDELC','INDDISTELC') then 'IND ELEC' --Filter 242
when commodity in('INDHFO','INDLFO','INDLPG','INDKER') then 'IND OIL' --Filter 360
when commodity in('INDMAINSGAS','INDNGA') then 'IND GAS' --Filter 313
when commodity in('INDMAINSHYG','INDHYG') then 'IND HYDROGEN' --Filter 268
when commodity in('INDMSWORG','INDMSWINO','INDWOD','INDPELH','INDPOLWST','INDBIOLFO','INDPELL','INDMAINSBOM',
'INDBIOOIL','INDWODWST','INDBOG-AD','INDBIOLPG','INDGRASS','INDBOG-LF') then 'IND BIO' --Filter 376
else null
end as comm_set
from vedastore
where attribute='VAR_FIn' and
process in('IOIDRYBIOL01','IOILTHBIOS02','IOIDRYCOK00','IOIDRYELC00','IOILTHELC02','IOIOTHLFO00','IOIHTHLFO01','IOILTHHCO01','IOIHTHHFO01','IOIOTHNGA01','IOILTHLPG02','IOILTHKER00'
,'IOIDRYHDG02','IOILTHCOK00','IOILTHHFO00','IOIMOTELC00','IOILTHCOK01','IOIDRYNGA01','IOIDRYSTM01','IOIDRYKER00','IOILTHHCO02','IOIHTHKER01','IOIOTHBIOS01','IOIREFEHFC00'
,'IOIDRYCOK01','IOIOTHCOK01','IOIOTHHFO00','IOIOTHLFO01','IOIOTHBENZ00','IOIDRYBIOS00','IOIREFEHFO01','IOIHTHBIOG01','IOIHTHLPG00','IOIDRYHCO02','IOIOTHKER00','IOIOTHNGA00'
,'IOIDRYBIOG02','IOIDRYHFO02','IOIHTHBIOS00','IOIHTHCOK00','IOILTHLPG01','IOIDRYCOK02','IOILTHHCO00','IOIHTHBIOS01','IOIDRYHDG01','IOIDRYLFO01','IOILTHBIOG02','IOIOTHSTM01'
,'IOILTHNGA01','IOIOTHBIOS00','IOIDRYBIOS02','IOIDRYLPG00','IOIDRYBENZ02','IOILTHCOK02','IOIHTHHCO01','IOILTHSTM01','IOIREFEHFC01','IOIHTHCOK01','IOIHTHLFO00','IOIHTHBIOL01'
,'IOILTHBIOG01','IOIMOTELC02','IOIDRYNGA00','IOILTHBIOS00','IOILTHELC00','IOIOTHKER01','IOIDRYHFO00','IOIDRYKER02','IOIDRYLPG01','IOIHTHNGA00','IOIOTHELC01','IOIDRYKER01'
,'IOIDRYSTM00','IOIHTHBENZ00','IOILTHBIOL02','IOIHTHELC01','IOIHTHLPG01','IOIOTHELC00','IOILTHSTM00','IOIHTHBIOG00','IOILTHLPG00','IOIDRYBIOG01','IOILTHHDG02','IOILTHKER01'
,'IOIOTHSTM00','IOIDRYBIOG00','IOILTHLFO00','IOIOTHBIOL01','IOIDRYHCO00','IOIOTHHCO01','IOIDRYELC01','IOIOTHHCO00','IOIOTHLPG01','IOILTHELC01','IOIHTHBENZ01','IOILTHNGA00'
,'IOIDRYBENZ01','IOIDRYHCO01','IOILTHNGA02','IOIOTHBIOG01','IOIHTHELC00','IOIDRYELC02','IOILTHLFO01','IOIDRYBENZ00','IOIDRYLFO00','IOIHTHHFO00','IOILTHBENZ02','IOILTHBIOG00'
,'IOIOTHCOK00','IOIHTHKER00','IOIOTHHFO01','IOILTHLFO02','IOIHTHNGA01','IOIHTHHCO00','IOILTHBIOL01','IOIMOTELC01','IOIDRYBIOS01','IOIDRYHFO01','IOIDRYLFO02','IOIOTHBIOG00'
,'IOIDRYNGA02','IOILTHBENZ01','IOIOTHBENZ01','IOILTHHDG01','IOIOTHHDG01','IOIDRYBIOL02','IOIHTHHDG01','IOILTHBENZ00','IOILTHBIOS01','IOIOTHLPG00','IOIDRYLPG02','IOILTHHFO02'
,'IOILTHKER02','IOILTHHFO01')
) a
where comm_set is not null
)
select 'fin-en-other-ind_'|| comm_set ||'|' || tablename || '|' || 'VAR_FIn' || '|' || 'various' || '|various'::varchar(300) "id",
'fin-en-other-ind_' || comm_set::varchar(300) "analysis", tablename, 'VAR_FIn'::varchar(50) "attribute",
'various'::varchar(50) "commodity",
'various'::varchar(50) "process",
sum(pv)::numeric "all",
sum(case when period='2010' then pv else 0 end)::numeric "2010",
sum(case when period='2011' then pv else 0 end)::numeric "2011",
sum(case when period='2012' then pv else 0 end)::numeric "2012",
sum(case when period='2015' then pv else 0 end)::numeric "2015",
sum(case when period='2020' then pv else 0 end)::numeric "2020",
sum(case when period='2025' then pv else 0 end)::numeric "2025",
sum(case when period='2030' then pv else 0 end)::numeric "2030",
sum(case when period='2035' then pv else 0 end)::numeric "2035",
sum(case when period='2040' then pv else 0 end)::numeric "2040",
sum(case when period='2045' then pv else 0 end)::numeric "2045",
sum(case when period='2050' then pv else 0 end)::numeric "2050",
sum(case when period='2055' then pv else 0 end)::numeric "2055",
sum(case when period='2060' then pv else 0 end)::numeric "2060"
from (
select case
when comm_set='IND COALS' then 'coa'
when comm_set='IND HYDROGEN' then 'hyd'
when comm_set='IND MANFUELS' then 'man'
when comm_set='IND GAS' then 'gas'
when comm_set='IND ELEC' then 'elc'
when comm_set='IND BIO' then 'bio'
when comm_set='IND OIL' then 'oil'
end as comm_set,
tablename,period,pv
from ind_oi_chp
union all
select case
when comm_set='IND COALS' then 'coa'
when comm_set='IND HYDROGEN' then 'hyd'
when comm_set='IND MANFUELS' then 'man'
when comm_set='IND GAS' then 'gas'
when comm_set='IND ELEC' then 'elc'
when comm_set='IND BIO' then 'bio'
when comm_set='IND OIL' then 'oil'
end as comm_set,
tablename,period,pv
from ind_oi_prd
) a
group by tablename, comm_set
order by tablename, comm_set
/* **Electricity BAT (ElecBatchUpload.bat): ** */
/* ------------------------------------------*/
/* *Annual timesliced elec storage output (techs grouped)* */
COPY (
select analysis || '|' || tablename || '|Var_FOut|ELC|various'::varchar(300) "id",
analysis::varchar(50),
tablename,
'VAR_FOut'::varchar "attribute",
'ELC'::varchar "commodity",
'various'::varchar(50) "process",
sum(pv)::numeric "all",
sum(case when period='2010' then pv else 0 end)::numeric "2010",
sum(case when period='2011' then pv else 0 end)::numeric "2011",
sum(case when period='2012' then pv else 0 end)::numeric "2012",
sum(case when period='2015' then pv else 0 end)::numeric "2015",
sum(case when period='2020' then pv else 0 end)::numeric "2020",
sum(case when period='2025' then pv else 0 end)::numeric "2025",
sum(case when period='2030' then pv else 0 end)::numeric "2030",
sum(case when period='2035' then pv else 0 end)::numeric "2035",
sum(case when period='2040' then pv else 0 end)::numeric "2040",
sum(case when period='2045' then pv else 0 end)::numeric "2045",
sum(case when period='2050' then pv else 0 end)::numeric "2050",
sum(case when period='2055' then pv else 0 end)::numeric "2055",
sum(case when period='2060' then pv else 0 end)::numeric "2060"
from (
select process,period,pv,
case
when attribute='VAR_FOut' then 'elec-stor-out_'
when attribute='VAR_FIn' then 'elec-stor-in_'
end ||
case
when process in('EHYDPMP00','EHYDPMP01') then 'hyd' --Filter 394
when process in ('ECAESCON01','ESTGCAES01','ECAESTUR01','ESTGAACAES01') then 'caes' --Filter 395
when process in ('ESTGBNAS01','ESTGBALA01','ESTGBRF01') then 'batt' --Filter 396
end || '-' ||
TimeSlice "analysis",
tablename, attribute, TimeSlice
from vedastore
where attribute in('VAR_FOut','VAR_FIn') and commodity = 'ELC'
) a
where analysis is not null
group by id, analysis,tablename, attribute, TimeSlice
order by tablename, analysis, attribute, commodity
) TO '%~dp0elecstortime.csv' delimiter ',' CSV HEADER;
/* **End of Electricity BAT (ElecBatchUpload.bat): ** */
/* **For agriculture / LULUCF BAT (AgBatchUpload.bat): ** */
/* ------------------------------------------------------*/
/* *Landfill CH4 emission mitigation and residual emissions* */
-- Note that the mitigation measures take CH4 in
COPY (
select 'landfill-ghg_'|| proc_set || '|' || tablename || '|' || attribute || '|' || commodity || '|various'::varchar(300) "id",
'landfill-ghg_' || proc_set "analysis", tablename, attribute,
commodity,'various'::varchar "process",
sum(pv) "all",
sum(case when period='2010' then pv else 0 end)::numeric "2010",
sum(case when period='2011' then pv else 0 end)::numeric "2011",
sum(case when period='2012' then pv else 0 end)::numeric "2012",
sum(case when period='2015' then pv else 0 end)::numeric "2015",
sum(case when period='2020' then pv else 0 end)::numeric "2020",
sum(case when period='2025' then pv else 0 end)::numeric "2025",
sum(case when period='2030' then pv else 0 end)::numeric "2030",
sum(case when period='2035' then pv else 0 end)::numeric "2035",
sum(case when period='2040' then pv else 0 end)::numeric "2040",
sum(case when period='2045' then pv else 0 end)::numeric "2045",
sum(case when period='2050' then pv else 0 end)::numeric "2050",
sum(case when period='2055' then pv else 0 end)::numeric "2055",
sum(case when period='2060' then pv else 0 end)::numeric "2060"
from (
select tablename, attribute, period,pv,
case
when process='PWLFWM00' and commodity='PRCN2OP' then 'landfill-unab-N2O' --Filter 411
when process='PWLFWM00' and commodity='PRCCH4P' then 'landfill-unab-CH4' --Filter 412
when process in ('PWLFWMM01','PWLFWMM02','PWLFWMM03','PWLFWMM04') then 'landfill-mit-CH4' --Filter 413
end as proc_set
,commodity
from vedastore
where attribute in('VAR_FIn','VAR_FOut') and commodity in('PRCCH4P','PRCN2OP') --Filter 414
) a
where proc_set is not null
group by tablename, attribute, proc_set, commodity
order by tablename, attribute, proc_set, commodity
) TO '%~dp0landfillemiss.csv' delimiter ',' CSV HEADER;
/* *Land use and crop / livestock mitigation (MACC) measures* */
-- Gives breakdown for "agr-GHG-land","agr-GHG-livestock-mitigation","agr-GHG-crop-mitigation","agr-GHG-afforestation","agr-GHG-energy" by table.
-- This is GHG emissions and so some measures are not included here (biomass / h2 boilers, reduced cultivation, elc/heat energy efficiency options) as they don't produce GHG
COPY (
select 'ag-lulucf-meas-ghg_'|| proc_set || '|' || tablename || '|' || attribute || '|' || 'various' || '|various'::varchar(300) "id",
'ag-lulucf-meas-ghg_' || proc_set "analysis", tablename, attribute,
'various'::varchar(50) "commodity",'various'::varchar "process",
sum(pv) "all",
sum(case when period='2010' then pv else 0 end)::numeric "2010",
sum(case when period='2011' then pv else 0 end)::numeric "2011",
sum(case when period='2012' then pv else 0 end)::numeric "2012",
sum(case when period='2015' then pv else 0 end)::numeric "2015",
sum(case when period='2020' then pv else 0 end)::numeric "2020",
sum(case when period='2025' then pv else 0 end)::numeric "2025",
sum(case when period='2030' then pv else 0 end)::numeric "2030",
sum(case when period='2035' then pv else 0 end)::numeric "2035",
sum(case when period='2040' then pv else 0 end)::numeric "2040",
sum(case when period='2045' then pv else 0 end)::numeric "2045",
sum(case when period='2050' then pv else 0 end)::numeric "2050",
sum(case when period='2055' then pv else 0 end)::numeric "2055",
sum(case when period='2060' then pv else 0 end)::numeric "2060"
from (
select tablename, attribute, period,pv,
case
when process in ('ALUFOR01','ALUFOR02','ALUFOR03','ALUFOR04A','ALUFOR04B') then 'affor' --Filter 210
when process in ('AGCRP01','AGCRP02','AGCRP04','AGCRP05','AGCRP06','AGCRP07','AGCRP08','AGCRP09') then 'crops' --Filter 211
when process in ('AHTBLRC00','AHTBLRG00','AHTBLRG01','AHTBLRO00','AHTBLRO01','ATRA00','ATRA01','AATRA01') then 'agr-en' --Filter 212
when process in ('AGSOI01','AGSOI02','AGSOI03','AGSOI04') then 'soils' --Filter 417
when process in ('ALU00') then 'lulucf' --Filter 213
when process in ('AGLIV03','AGLIV04','AGLIV05','AGLIV06','AGLIV07','AGLIV09') then 'livestock' --Filter 214
when process in('AGRCUL00','MINBSLURRY1') then 'bau-livestock' --Filter 416
end as proc_set
from vedastore
where attribute='VAR_FOut' and commodity in ('GHG-LULUCF','GHG-AGR-NO-LULUCF') --Filter 1
) a
where proc_set is not null
group by tablename, attribute, proc_set
order by tablename, attribute, proc_set
) TO '%~dp0lulucfout.csv' delimiter ',' CSV;
/* *Afforestation rate* */
-- This is the amount of afforestation over the BAU level (in current model formulation)
-- Note that only ALUFOR04A "creates" ALAND
COPY (
select 'ag-lulucf-meas_aff_level' || '|' || tablename || '|' || attribute || '|' || commodity || '|' || process::varchar(300) "id",
'ag-lulucf-meas_aff_level'::varchar(50) "analysis",
tablename, attribute,
commodity,process,
sum(pv) "all",
sum(case when period='2010' then pv else 0 end)::numeric "2010",
sum(case when period='2011' then pv else 0 end)::numeric "2011",
sum(case when period='2012' then pv else 0 end)::numeric "2012",
sum(case when period='2015' then pv else 0 end)::numeric "2015",
sum(case when period='2020' then pv else 0 end)::numeric "2020",
sum(case when period='2025' then pv else 0 end)::numeric "2025",
sum(case when period='2030' then pv else 0 end)::numeric "2030",
sum(case when period='2035' then pv else 0 end)::numeric "2035",
sum(case when period='2040' then pv else 0 end)::numeric "2040",
sum(case when period='2045' then pv else 0 end)::numeric "2045",
sum(case when period='2050' then pv else 0 end)::numeric "2050",
sum(case when period='2055' then pv else 0 end)::numeric "2055",
sum(case when period='2060' then pv else 0 end)::numeric "2060"
from vedastore
where attribute='VAR_FOut' and commodity='ALAND' and process in('ALUFOR01','ALUFOR02','ALUFOR03','ALUFOR04A') --Filter 2
group by tablename, attribute,commodity,process
) TO '%~dp0afforestout.csv' delimiter ',' CSV;
/* **End of For agriculture / LULUCF BAT (AgBatchUpload.bat): ** */
/* **Transport BAT (TraBatchUpload.bat): ** */
/* -------------------------------------*/
/* *Whole stock vehicle kms, emissions and emission intensity for 29 vehicle types* */
-- Includes estimates of CNG-in by vehicle types and associated emissions- This requires apportioning
-- emissions from the process converting mains gas to CNG (=different process for lgv/hgv/car vs bus) according to CNG input
-- In the model there seem to be cases where there is no CNG used by any of the vehicles (lgv,hgv,car or bus) and no CNG is created
-- but there are still emissions from the process which turns mains gas into CNG-
-- NB following codes for 'cars_h2+hybrid' doesn't seem to exist in the online acronym list:
-- TCHBHYL01
-- This code exists in the acronym list but not in the test dataset:
-- TCHBE8501 New hybrid flexible-fuel car (for E85) (seems not to be read in according to the XL model def sheet)
-- Uses the postgres 9-4+ "specific filter(where---" construction so won't work with other DBs
copy(
with base_cng_emissions as(
select tablename, period,'cars-emis_lpg-and-cng-fueled'::varchar(50) "analysis",
'VAR_FOut'::varchar(50) "attribute",
'GHG-TRA-NON-ETS-NO-AS'::varchar(50) "commodity",
0::numeric "pv"
from vedastore group by tablename, period
union
select tablename, period,'hgv-emis_lpg-and-cng-fueled'::varchar(50) "analysis",
'VAR_FOut'::varchar(50) "attribute",
'GHG-TRA-NON-ETS-NO-AS'::varchar(50) "commodity",
0::numeric "pv"
from vedastore group by tablename, period
union
select tablename, period,'lgv-emis_lpg-and-cng-fueled'::varchar(50) "analysis",
'VAR_FOut'::varchar(50) "attribute",
'GHG-TRA-NON-ETS-NO-AS'::varchar(50) "commodity",
0::numeric "pv"
from vedastore group by tablename, period
)
, cng_emis_shares as(
select tablename,period,
sum(case when proc_set='cars-cng-in' then pv else 0 end) "cars-cng-in",
sum(case when proc_set='lgv-cng-in' then pv else 0 end) "lgv-cng-in",
sum(case when proc_set='hgv-cng-in' then pv else 0 end) "hgv-cng-in",
sum(case when proc_set in('cars-cng-in','lgv-cng-in','hgv-cng-in') then pv else 0 end) "total_cng_in",
sum(case when proc_set='cng-conv-emis' then pv else 0 end) "cng-conv-emis"
from (
select
tablename,process,period,pv,
case
when process = 'TFSSCNG01' and attribute ='VAR_FOut' and commodity in('GHG-TRA-NON-ETS-NO-AS') then 'cng-conv-emis' --Filter 18
when attribute = 'VAR_FIn' and commodity in('TRACNGS','TRACNGL') then
case
when process like 'TC%' then 'cars-cng-in' --Filter 4
when process like 'TL%' then 'lgv-cng-in' --Filter 5
when process like 'TH%' then 'hgv-cng-in' --Filter 6
end
end as "proc_set"
from vedastore
where (attribute = 'VAR_FIn' or attribute ='VAR_FOut') and commodity in('TRACNGS','TRACNGL','GHG-AGR-NO-LULUCF',
'GHG-ELC','GHG-ELC-CAPTURED','GHG-ETS-NET',
'GHG-ETS-NO-IAS-NET','GHG-ETS-NO-IAS-TER','GHG-ETS-TER','GHG-ETS-YES-IAS-NET',
'GHG-ETS-YES-IAS-TER','GHG-IAS-ETS','GHG-IAS-NON-ETS','GHG-IND-ETS',
'GHG-IND-ETS-CAPTURED','GHG-IND-NON-ETS','GHG-IND-NON-ETS-CAPTURED','GHG-LULUCF',
'GHG-NO-IAS-NO-LULUCF-NET','GHG-NO-IAS-NO-LULUCF-TER',
'GHG-NO-IAS-YES-LULUCF-NET','GHG-NO-IAS-YES-LULUCF-TER',
'GHG-NON-ETS-NO-LULUCF-NET','GHG-NON-ETS-NO-LULUCF-TER',
'GHG-NON-ETS-YES-LULUCF-NET','GHG-NON-ETS-YES-LULUCF-TER','GHG-OTHER-ETS',
'GHG-OTHER-ETS-CAPTURED','GHG-OTHER-NON-ETS','GHG-RES-ETS','GHG-RES-NON-ETS',
'GHG-SER-ETS','GHG-SER-NON-ETS','GHG-TRA-NON-ETS-NO-AS',
'GHG-YES-IAS-NO-LULUCF-NET','GHG-YES-IAS-NO-LULUCF-TER',
'GHG-YES-IAS-YES-LULUCF-NET','GHG-YES-IAS-YES-LULUCF-TER') and
(process = 'TFSSCNG01' or process like any(array['TC%','TL%','TH%','TB%'])) --Filter 7
order by process
) a
where proc_set <>''
group by tablename,period
)
, main_crosstab as(
select analysis::varchar(50), tablename,attribute,commodity,period,sum(pv) "pv"
from (
select a.tablename, a.analysis, a.period,a.attribute,a.commodity,
case
when analysis='cars-emis_lpg-and-cng-fueled' then
case when "total_cng_in" > 0 then "cars-cng-in"/"total_cng_in"*"cng-conv-emis" + pv else pv end
when analysis='lgv-emis_lpg-and-cng-fueled' then
case when "total_cng_in" > 0 then "lgv-cng-in"/"total_cng_in"*"cng-conv-emis" + pv else pv end
when analysis='hgv-emis_lpg-and-cng-fueled' then
case when "total_cng_in" > 0 then "hgv-cng-in"/"total_cng_in"*"cng-conv-emis" + pv else pv end
else pv
end "pv"
from (
select tablename, period, analysis, attribute, commodity,sum(pv) "pv"
from (
select tablename, process, period,pv,attribute,commodity,
case
when process like 'TC%' then 'cars-'
when process like 'TL%' then 'lgv-'
when process like 'TH%' then 'hgv-'
when process like 'TB%' or process='TFSLCNG01' then 'bus-'
when process like 'TW%' then 'bike-'
end ||
case
when commodity in('TC','TL','TH1','TH2','TH3','TB','TW') then 'km_'
when commodity in('GHG-TRA-NON-ETS-NO-AS') then 'emis_'
end ||
case
when process in('TBDST00','TBDST01','TCDST00','TCDST01','TH1DST00','TH2DST00','TH3DST00','TH1DST01',
'TH2DST01','TH3DST01','TLDST00','TLDST01') then 'diesel' --Filter 8
when process in('TCE8501','TLE8501') then 'E85' --Filter 9
when process in('TBELC01','TCELC01','TLELC01','TH3ELC01','TWELC01') then 'electric' --Filter 10
when process in('TBFCHBHYG01','TCFCHBHYG01','TCFCHYG01','TCHBE8501','TCHBHYL01','TH1FCHBHYG01',
'TH2FCHBHYG01','TH3FCHBHYG01','TLFCHBHYG01','TLFCHYG01','TLHBHYL01','TWFCHYG01') then 'h2+hybrid' --Filter 11
when process in('TCFCPHBHYG01') then 'h2-plug-in-hybrid' --Filter 12
when process in('TBHBDST01','TCHBDST01','TCHBPET00','TCHBPET01','TH1HBDST01','TH2HBDST01',
'TH3HBDST01','TLHBDST01','TLHBPET01') then 'hybrid' --Filter 13
when process in('TBCNG01','TCCNG01','TCLPG00','TCLPG01','TH1CNG01','TH2CNG01',
'TH3CNG01','TLCNG01','TLLPG01','TFSLCNG01') then 'lpg-and-cng-fueled' --Filter 14
-- NB Includes the bus mains gas => CNG conversion process 'TFSLCNG01'. This is because emissions are counted at this point here but the demand is counted at "TBCNG01"
when process in('TCPET00','TCPET01','TLPET00','TLPET01','TWPET00','TWPET01') then 'petrol' --Filter 15
when process in('TCPHBDST01','TCPHBPET01','TLPHBDST01','TLPHBPET01') then 'plug-in-hybrid' --Filter 16
when process in('TH2CNGDST01','TH3CNGDST01') then 'Dual fuel diesel-CNG' --Filter 221
end as "analysis"
from vedastore
where attribute = 'VAR_FOut' and commodity in('GHG-TRA-NON-ETS-NO-AS','TB','TC','TH1','TH2','TH3','TL','TW')
and (process like any(array['TC%','TL%','TB%','TW%']) or process ~'^TH[^Y]' or process='TFSLCNG01') --Filter 17
) a
where analysis <>''
group by tablename, period, analysis, attribute, commodity
union
select * from base_cng_emissions
) a
left join cng_emis_shares b on a.tablename=b.tablename and a.period=b.period
) b
group by analysis, tablename,attribute,commodity,period
order by tablename, analysis
)
select analysis || '|' || tablename || '|' || attribute || '|' || commodity || '|various'::varchar(300) "id", analysis::varchar(50), tablename,attribute,
commodity,
'various'::varchar(50) "process",
case when analysis like '%-inten%' then avg(pv)::numeric else sum(pv)::numeric end "all",
-- I.e is the average emission intensity of each year for the emission intensity rather than the sum- This is _not_ (sum emissions) / (sum kms)
sum(case when period='2010' then pv else 0 end)::numeric "2010",
sum(case when period='2011' then pv else 0 end)::numeric "2011",
sum(case when period='2012' then pv else 0 end)::numeric "2012",
sum(case when period='2015' then pv else 0 end)::numeric "2015",
sum(case when period='2020' then pv else 0 end)::numeric "2020",
sum(case when period='2025' then pv else 0 end)::numeric "2025",
sum(case when period='2030' then pv else 0 end)::numeric "2030",
sum(case when period='2035' then pv else 0 end)::numeric "2035",
sum(case when period='2040' then pv else 0 end)::numeric "2040",
sum(case when period='2045' then pv else 0 end)::numeric "2045",
sum(case when period='2050' then pv else 0 end)::numeric "2050",
sum(case when period='2055' then pv else 0 end)::numeric "2055",
sum(case when period='2060' then pv else 0 end)::numeric "2060"
from (
-- NB This following uses a postgres 9-4 specific syntax ( filter(where--- ) and won't work with earlier vers
select a.* from main_crosstab a
where period<>'-'
union
select left(analysis, position('_' in analysis)) ||'all' "analysis", tablename, 'VAR_FOut' "attribute", commodity, period,sum(pv) "pv" from main_crosstab
where period<>'-'
group by left(analysis, position('_' in analysis)), tablename,commodity,period
union
select left(analysis, position('-' in analysis))||'emis-inten_all' "analysis", tablename, 'VAR_FOut' "attribute", '-' "commodity", period,
sum(pv) filter(where analysis like '%-emis%')/sum(pv) filter(where analysis like '%-km%') "pv"
from main_crosstab
where period<>'-' and period<>'2200'
group by left(analysis, position('-' in analysis)), tablename,period
order by tablename, period, analysis
) a
group by analysis, tablename,attribute,commodity
order by tablename, analysis
) TO '%~dp0vehKms.csv' delimiter ',' CSV HEADER;
/* *New stock vehicle kms, emissions and emission intensity for 29 vehicle types* */
-- This script only includes new vehicles in the year of introduction- Apportions emissions from conversion of mains gas to CNG according to CNG-in for each vehicle type
-- Uses the postgres 9-4+ "specific filter(where---" construction so won't work with other DBs
COPY (
with base_cng_emissions as(
select tablename, period,'cars-new-emis_lpg-and-cng-fueled'::varchar "analysis",
'VAR_FOut'::varchar "atttribute", 'GHG-TRA-NON-ETS-NO-AS'::varchar "commodity",
0::numeric "pv"
from vedastore group by tablename, period
union
select tablename, period,'hgv-new-emis_lpg-and-cng-fueled'::varchar "analysis",
'VAR_FOut'::varchar "atttribute", 'GHG-TRA-NON-ETS-NO-AS'::varchar "commodity",
0::numeric "pv"
from vedastore group by tablename, period
union
select tablename, period,'lgv-new-emis_lpg-and-cng-fueled'::varchar "analysis",
'VAR_FOut'::varchar "atttribute", 'GHG-TRA-NON-ETS-NO-AS'::varchar "commodity",
0::numeric "pv"
from vedastore group by tablename, period
union
select tablename, period,'bus-new-emis_lpg-and-cng-fueled'::varchar "analysis",
'VAR_FOut'::varchar "atttribute", 'GHG-TRA-NON-ETS-NO-AS'::varchar "commodity",
0::numeric "pv"
from vedastore group by tablename, period
)
, cng_emis_shares as(
select tablename,period,
sum(case when proc_set='cars-new-cng-in' then pv else 0 end) "cars-new-cng-in",
sum(case when proc_set='lgv-new-cng-in' then pv else 0 end) "lgv-new-cng-in",
sum(case when proc_set='hgv-new-cng-in' then pv else 0 end) "hgv-new-cng-in",
sum(case when proc_set in('cars-new-cng-in','lgv-new-cng-in','hgv-new-cng-in','older-veh-cng-in') then pv else 0 end) "total_cng_in",
sum(case when proc_set='cng-conv-emis' then pv else 0 end) "cng-conv-emis",
sum(case when proc_set='bus-new-cng-in' then pv else 0 end) "bus-new-cng-in",
sum(case when proc_set in('bus-new-cng-in','older-bus-cng-in') then pv else 0 end) "total_bus_cng_in",
sum(case when proc_set='bus-cng-conv-emis' then pv else 0 end) "bus-cng-conv-emis"
from (
select tablename,process,period,pv,
case
when process = 'TFSSCNG01' and attribute ='VAR_FOut' and
commodity in('GHG-TRA-NON-ETS-NO-AS') then 'cng-conv-emis' --Filter 18
when process = 'TFSLCNG01' and attribute ='VAR_FOut' and commodity='GHG-TRA-NON-ETS-NO-AS' then 'bus-cng-conv-emis' --Filter 19
when attribute = 'VAR_FIn' and commodity in('TRACNGS','TRACNGL') then
case
when process like 'TC%' and vintage=period then 'cars-new-cng-in' --Filter 20
when process like 'TL%' and vintage=period then 'lgv-new-cng-in' --Filter 21
when process like 'TH%' and vintage=period then 'hgv-new-cng-in' --Filter 22
when process like any(array['TC%','TL%','TH%']) and vintage<>period then 'older-veh-cng-in' --Filter 23
when process like 'TB%' and vintage=period then 'bus-new-cng-in' --Filter 24
when process like 'TB%' and vintage<>period then 'older-bus-cng-in' --Filter 25
end
end as "proc_set"
from vedastore
order by process
) a
where proc_set <>''
group by tablename,period
)
, main_crosstab as(
select analysis, tablename,attribute,commodity,period,sum(pv) "pv" from (
select a.tablename, a.analysis, a.period,a.attribute,a.commodity,
case
when analysis='cars-new-emis_lpg-and-cng-fueled' then
case when "total_cng_in" > 0 then "cars-new-cng-in"/"total_cng_in"*"cng-conv-emis" + pv else pv end
when analysis='lgv-new-emis_lpg-and-cng-fueled' then
case when "total_cng_in" > 0 then "lgv-new-cng-in"/"total_cng_in"*"cng-conv-emis" + pv else pv end
when analysis='hgv-new-emis_lpg-and-cng-fueled' then
case when "total_cng_in" > 0 then "hgv-new-cng-in"/"total_cng_in"*"cng-conv-emis" + pv else pv end
when analysis='bus-new-emis_lpg-and-cng-fueled' then
case when "total_bus_cng_in" > 0 then "bus-new-cng-in"/"total_bus_cng_in"*"bus-cng-conv-emis" + pv else pv end
else pv
end "pv"
from (
select tablename, period, analysis, attribute, commodity,sum(pv) "pv"
from (
select tablename, process, period,pv,attribute,commodity,
case
when process like 'TC%' then 'cars-new-'
when process like 'TL%' then 'lgv-new-'
when process like 'TH%' then 'hgv-new-'
when process like 'TB%' then 'bus-new-'
when process like 'TW%' then 'bike-new-'
end ||
case
when commodity in('TC','TL','TH1','TH2','TH3','TB','TW') then 'km_'
when commodity in('GHG-TRA-NON-ETS-NO-AS') then 'emis_'
end ||
case
when process in('TBDST00','TBDST01','TCDST00','TCDST01','TH1DST00','TH2DST00','TH3DST00','TH1DST01','TH2DST01',
'TH3DST01','TLDST00','TLDST01') then 'diesel' --Filter 8
when process in('TCE8501','TLE8501') then 'E85' --Filter 9
when process in('TBELC01','TCELC01','TLELC01','TH3ELC01','TWELC01') then 'electric' --Filter 10
when process in('TBFCHBHYG01','TCFCHBHYG01','TCFCHYG01','TCHBE8501','TCHBHYL01','TH1FCHBHYG01','TH2FCHBHYG01',
'TH3FCHBHYG01','TLFCHBHYG01','TLFCHYG01','TLHBHYL01','TWFCHYG01') then 'h2+hybrid' --Filter 11
when process in('TCFCPHBHYG01') then 'h2-plug-in-hybrid' --Filter 12
when process in('TBHBDST01','TCHBDST01','TCHBPET00','TCHBPET01','TH1HBDST01','TH2HBDST01',
'TH3HBDST01','TLHBDST01','TLHBPET01') then 'hybrid' --Filter 13
when process in('TBCNG01','TCCNG01','TCLPG00','TCLPG01','TH1CNG01','TH2CNG01',
'TH3CNG01','TLCNG01','TLLPG01') then 'lpg-and-cng-fueled' --Filter 220
when process in('TCPET00','TCPET01','TLPET00','TLPET01','TWPET00','TWPET01') then 'petrol' --Filter 15
when process in('TCPHBDST01','TCPHBPET01','TLPHBDST01','TLPHBPET01') then 'plug-in-hybrid' --Filter 16
when process in('TH2CNGDST01','TH3CNGDST01') then 'Dual fuel diesel-CNG' --Filter 221
end as "analysis"
from vedastore
where attribute = 'VAR_FOut' and commodity in('TC','TL','TH1','TH2','TH3','TW','TB','GHG-TRA-NON-ETS-NO-AS')
and (process like any(array['TC%','TL%','TB%','TW%']) or process ~'^TH[^Y]') and vintage=period and process like '%01' --Filter 35
) a
where analysis <>''
group by tablename, period, analysis, attribute, commodity
union
select * from base_cng_emissions
) a
left join cng_emis_shares b on a.tablename=b.tablename and a.period=b.period
) b
group by analysis, tablename,attribute,commodity,period
order by tablename, analysis
)
select analysis || '|' || tablename || '|' || attribute || '|' || commodity || '|various'::varchar(300) "id", analysis::varchar(50), tablename,attribute,
commodity,
'various'::varchar(50) "process",
case when analysis like '%-inten%' then avg(pv)::numeric else sum(pv)::numeric end "all",
-- I.e is the average emission intensity of each year for the emission intensity rather than the sum- This is _not_ (sum emissions) / (sum kms)
sum(case when period='2010' then pv else 0 end)::numeric "2010",
sum(case when period='2011' then pv else 0 end)::numeric "2011",
sum(case when period='2012' then pv else 0 end)::numeric "2012",
sum(case when period='2015' then pv else 0 end)::numeric "2015",
sum(case when period='2020' then pv else 0 end)::numeric "2020",
sum(case when period='2025' then pv else 0 end)::numeric "2025",
sum(case when period='2030' then pv else 0 end)::numeric "2030",
sum(case when period='2035' then pv else 0 end)::numeric "2035",
sum(case when period='2040' then pv else 0 end)::numeric "2040",
sum(case when period='2045' then pv else 0 end)::numeric "2045",
sum(case when period='2050' then pv else 0 end)::numeric "2050",
sum(case when period='2055' then pv else 0 end)::numeric "2055",
sum(case when period='2060' then pv else 0 end)::numeric "2060"
from (
-- NB This following uses a postgres 9-4 specific syntax ( filter(where... ) and won't work with earlier vers
select a.* from main_crosstab a
where period<>'-'
union
select left(analysis, position('_' in analysis)) ||'all' "analysis", tablename, 'VAR_FOut' "attribute", commodity, period,sum(pv) "pv" from main_crosstab
where period<>'-'
group by left(analysis, position('_' in analysis)), tablename,commodity,period
union
select left(analysis, position('-' in analysis))||'new-emis-inten_all' "analysis", tablename, 'VAR_FOut' "attribute", '-' "commodity", period,
sum(pv) filter(where analysis like '%-emis%')/sum(pv) filter(where analysis like '%-km%') "pv"
from main_crosstab
where period<>'-' and period<>'2200'
group by left(analysis, position('-' in analysis)), tablename,period
order by tablename, period, analysis
) a
group by analysis, tablename,attribute,commodity
order by tablename, analysis
) TO '%~dp0newVehKms.csv' delimiter ',' CSV;
/* *Whole stock capacity for vehicles for 29 vehicle types* */
COPY (
select analysis || '|' || tablename || '|' || attribute || '|' || commodity || '|various'::varchar(300) "id", analysis, tablename,attribute,
commodity,
'various'::varchar(50) "process",
sum(pv)::numeric "all",
sum(case when period='2010' then pv else 0 end)::numeric "2010",
sum(case when period='2011' then pv else 0 end)::numeric "2011",
sum(case when period='2012' then pv else 0 end)::numeric "2012",
sum(case when period='2015' then pv else 0 end)::numeric "2015",
sum(case when period='2020' then pv else 0 end)::numeric "2020",
sum(case when period='2025' then pv else 0 end)::numeric "2025",
sum(case when period='2030' then pv else 0 end)::numeric "2030",
sum(case when period='2035' then pv else 0 end)::numeric "2035",
sum(case when period='2040' then pv else 0 end)::numeric "2040",
sum(case when period='2045' then pv else 0 end)::numeric "2045",
sum(case when period='2050' then pv else 0 end)::numeric "2050",
sum(case when period='2055' then pv else 0 end)::numeric "2055",
sum(case when period='2060' then pv else 0 end)::numeric "2060"
from (
select process,period,pv,
case
when process like 'TC%' then 'cars-cap_'
when process like 'TL%' then 'lgv-cap_'
when process like 'TH%' then 'hgv-cap_'
when process like 'TB%' then 'bus-cap_'
when process like 'TW%' then 'bike-cap_'
end ||
case
when process in('TBDST00','TBDST01','TCDST00','TCDST01','TH1DST00','TH2DST00','TH3DST00','TH1DST01',
'TH2DST01','TH3DST01','TLDST00','TLDST01') then 'diesel' --Filter 8
when process in('TCE8501','TLE8501') then 'E85' --Filter 9
when process in('TBELC01','TCELC01','TLELC01','TH3ELC01','TWELC01') then 'electric' --Filter 10
when process in('TBFCHBHYG01','TCFCHBHYG01','TCFCHYG01','TCHBE8501','TCHBHYL01','TH1FCHBHYG01',
'TH2FCHBHYG01','TH3FCHBHYG01','TLFCHBHYG01','TLFCHYG01','TLHBHYL01','TWFCHYG01') then 'h2+hybrid' --Filter 11
when process in('TCFCPHBHYG01') then 'h2-plug-in-hybrid' --Filter 12
when process in('TBHBDST01','TCHBDST01','TCHBPET00','TCHBPET01','TH1HBDST01','TH2HBDST01',
'TH3HBDST01','TLHBDST01','TLHBPET01') then 'hybrid' --Filter 13
when process in('TBCNG01','TCCNG01','TCLPG00','TCLPG01','TH1CNG01','TH2CNG01','TH3CNG01',
'TLCNG01','TLLPG01') then 'lpg-and-cng-fueled' --Filter 220
when process in('TCPET00','TCPET01','TLPET00','TLPET01','TWPET00','TWPET01') then 'petrol' --Filter 15
when process in('TCPHBDST01','TCPHBPET01','TLPHBDST01','TLPHBPET01') then 'plug-in-hybrid' --Filter 16
when process in('TH2CNGDST01','TH3CNGDST01') then 'Dual fuel diesel-CNG' --Filter 221
end as "analysis",
tablename, attribute,commodity
from vedastore
where attribute = 'VAR_Cap' and process like any(array['TC%','TL%','TH%','TB%','TW%']) --Filter 45
) a
where analysis <>''
group by id, analysis,tablename, attribute, commodity
order by tablename, analysis, attribute, commodity
) TO '%~dp0VehCapOut.csv' delimiter ',' CSV;
/* *New build capacity for vehicles for 29 vehicle types* */
-- NB are no commodities associated with new build, only processes - commodity='-'
COPY (
select analysis || '|' || tablename || '|' || attribute || '|' || commodity || '|various'::varchar(300) "id", analysis::varchar(50), tablename,attribute,
commodity,
'various'::varchar(50) "process",
sum(pv)::numeric "all",
sum(case when period='2010' then pv else 0 end)::numeric "2010",
sum(case when period='2011' then pv else 0 end)::numeric "2011",
sum(case when period='2012' then pv else 0 end)::numeric "2012",
sum(case when period='2015' then pv else 0 end)::numeric "2015",
sum(case when period='2020' then pv else 0 end)::numeric "2020",
sum(case when period='2025' then pv else 0 end)::numeric "2025",
sum(case when period='2030' then pv else 0 end)::numeric "2030",
sum(case when period='2035' then pv else 0 end)::numeric "2035",
sum(case when period='2040' then pv else 0 end)::numeric "2040",
sum(case when period='2045' then pv else 0 end)::numeric "2045",
sum(case when period='2050' then pv else 0 end)::numeric "2050",
sum(case when period='2055' then pv else 0 end)::numeric "2055",
sum(case when period='2060' then pv else 0 end)::numeric "2060"
from (
select process,period,pv,
case
when process like 'TC%' then 'cars-new-cap_'
when process like 'TL%' then 'lgv-new-cap_'
when process like 'TH%' then 'hgv-new-cap_'
when process like 'TB%' then 'bus-new-cap_'
when process like 'TW%' then 'bike-new-cap_'
end ||
case
when process in('TBDST00','TBDST01','TCDST00','TCDST01','TH1DST00','TH2DST00','TH3DST00','TH1DST01',
'TH2DST01','TH3DST01','TLDST00','TLDST01') then 'diesel' --Filter 8
when process in('TCE8501','TLE8501') then 'E85' --Filter 9
when process in('TBELC01','TCELC01','TLELC01','TH3ELC01','TWELC01') then 'electric' --Filter 10
when process in('TBFCHBHYG01','TCFCHBHYG01','TCFCHYG01','TCHBE8501','TCHBHYL01','TH1FCHBHYG01',
'TH2FCHBHYG01','TH3FCHBHYG01','TLFCHBHYG01','TLFCHYG01','TLHBHYL01','TWFCHYG01') then 'h2+hybrid' --Filter 11
when process in('TCFCPHBHYG01') then 'h2-plug-in-hybrid' --Filter 12
when process in('TBHBDST01','TCHBDST01','TCHBPET00','TCHBPET01','TH1HBDST01','TH2HBDST01',
'TH3HBDST01','TLHBDST01','TLHBPET01') then 'hybrid' --Filter 13
when process in('TBCNG01','TCCNG01','TCLPG00','TCLPG01','TH1CNG01','TH2CNG01','TH3CNG01',
'TLCNG01','TLLPG01') then 'lpg-and-cng-fueled' --Filter 220
when process in('TCPET00','TCPET01','TLPET00','TLPET01','TWPET00','TWPET01') then 'petrol' --Filter 15
when process in('TCPHBDST01','TCPHBPET01','TLPHBDST01','TLPHBPET01') then 'plug-in-hybrid' --Filter 16
when process in('TH2CNGDST01','TH3CNGDST01') then 'Dual fuel diesel-CNG' --Filter 221
end as "analysis",
tablename, attribute,commodity
from vedastore
where attribute = 'VAR_Ncap' and process like any(array['TC%','TL%','TH%','TB%','TW%']) --Filter 55
) a
where analysis <>''
group by id, analysis,tablename, attribute, commodity
order by tablename, analysis, attribute, commodity
) TO '%~dp0newVehCapOut.csv' delimiter ',' CSV;
/* *TRA_Fuel_by_mode* */
-- A version of the above Veda table with just international shipping and aviation
-- Added as a temporary measure to be able to remove international shipping / aviation from the main final energy and primary energy queries
COPY (
with fuels_in as (
-- Add this sub-query for compatibility with the other instances of these fuel filters / processes. Not strictly needed...
-- These fuels are only those which are used or have been used for these modes (not all fuels)
select process,period,pv,
case
when process in('TAIJETE00','TAIJETE01','TAIJETN00','TAIJETN01','TAIJET02','TAIHYLE01','TAIHYLN01') then 'TRA-AVI-INT' --Filter 386
--last 3 of these might not be real processes
when process in('TSIHYG01','TSIOIL00','TSIOIL01') then 'TRA-SHIP-INT' --Filter 364
end as proc,
case
when commodity in('AGRBIODST','AGRBIOLPG','AGRBOM','AGRGRASS','AGRMAINSBOM','AGRPOLWST','BGRASS','BIODST','BIODST-FT','BIOJET-FT','BIOKER-FT','BIOLFO'
,'BIOLPG','BIOOIL','BOG-AD','BOG-G','BOG-LF','BOM','BPELH','BPELL','BRSEED','BSEWSLG','BSLURRY','BSTARCH'
,'BSTWWST','BSUGAR','BTREATSTW','BTREATWOD','BVOIL','BWOD','BWODLOG','BWODWST','ELCBIOCOA','ELCBIOCOA2','ELCBIOLFO','ELCBIOOIL'
,'ELCBOG-AD','ELCBOG-LF','ELCBOG-SW','ELCBOM','ELCMAINSBOM','ELCMSWINO','ELCMSWORG','ELCPELH','ELCPELL','ELCPOLWST','ELCSTWWST','ELCTRANSBOM'
,'ETH','HYGBIOO','HYGBPEL','HYGMSWINO','HYGMSWORG','INDBIOLFO','INDBIOLPG','INDBIOOIL','INDBOG-AD','INDBOG-LF','INDBOM','INDGRASS'
,'INDMAINSBOM','INDMSWINO','INDMSWORG','INDPELH','INDPELL','INDPOLWST','INDWOD','INDWODWST','METH','MSWBIO','MSWINO','MSWORG'
,'PWASTEDUM','RESBIOLFO','RESBOM','RESHOUSEBOM','RESMSWINO','RESMSWORG','RESMAINSBOM','RESPELH','RESWOD','RESWODL','SERBIOLFO','SERBOG','SERBOM','SERBUILDBOM'
,'SERMAINSBOM','SERMSWBIO','SERMSWINO','SERMSWORG','SERPELH','SERWOD','TRABIODST','TRABIODST-FT','TRABIODST-FTL','TRABIODST-FTS','TRABIODSTL','TRABIODSTS'
,'TRABIOJET-FTDA','TRABIOJET-FTDAL','TRABIOJET-FTIA','TRABIOJET-FTIAL','TRABIOLFO','TRABIOLFODS','TRABIOLFODSL','TRABIOLFOL','TRABIOOILIS','TRABIOOILISL','TRABOM','TRAETH'
,'TRAETHL','TRAETHS','TRAMAINSBOM','TRAMETH') then 'ALL BIO' --Filter 287
when commodity in('AGRDISTELC','AGRELC','ELC','ELC-E-EU','ELC-E-IRE','ELC-I-EU','ELC-I-IRE','ELCGEN','ELCSURPLUS','HYGELC','HYGELCSURP','HYGLELC'
,'HYGSELC','INDDISTELC','INDELC','PRCELC','RESDISTELC','RESELC','RESELCSURPLUS','RESHOUSEELC','SERBUILDELC','SERDISTELC','SERELC','TRACELC'
,'TRACPHB','TRADISTELC','TRAELC','UPSELC') then 'ALL ELECTRICITY' --Filter 235
when commodity in('AGRNGA','ELCNGA','HYGLNGA','HYGSNGA','IISNGAB','IISNGAC','IISNGAE','INDNEUNGA','INDNGA','LNG','NGA','NGA-E'
,'NGA-E-EU','NGA-E-IRE','NGA-I-EU','NGA-I-N','NGAPTR','PRCNGA','RESNGA','SERNGA','TRACNGL','TRACNGS','TRALNG','TRALNGDS'
,'TRALNGDSL','TRALNGIS','TRALNGISL','TRANGA','UPSNGA') then 'ALL GAS' --Filter 354
when commodity in('AGRCOA','COA','COACOK','COA-E','ELCCOA','HYGCOA','INDCOA','INDCOACOK','INDSYNCOA','PRCCOA','PRCCOACOK','RESCOA'
,'SERCOA','SYNCOA','TRACOA') then 'ALL COALS' --Filter 246
when commodity in('SERHFO','SERLFO','TRAPETL','OILLFO','TRAJETDA','TRALFO','TRALPGS','ELCMSC','INDLFO','AGRHFO','TRAHFOIS','TRADSTS'
,'SERKER','TRAJETIANL','RESLFO','RESLPG','TRAHFODSL','TRALFOL','TRAJETIA','TRAJETL','TRAPETS','TRAHFODS','OILJET','OILDST'
,'AGRLPG','OILCRDRAW-E','UPSLFO','ELCLFO','INDNEULFO','ELCHFO','TRAJETDAEL','SYNOIL','TRADSTL','INDLPG','OILMSC','OILPET'
,'PRCHFO','OILCRDRAW','TRALFODSL','INDNEULPG','ELCLPG','TRADST','TRALFODS','OILKER','OILHFO','OILCRD','TRALPGL','SERLPG'
,'INDNEUMSC','PRCOILCRD','INDKER','INDHFO','OILLPG','TRALPG','RESKER','TRAJETIAEL','TRAHFOISL','IISHFOB','TRAPET','INDSYNOIL'
,'TRAHFO','AGRLFO') then 'ALL OIL PRODUCTS' --Filter 302
when commodity in('AGRHYG','ELCHYG','ELCHYGIGCC','HYGL','HYGL-IGCC','HYGLHPD','HYGLHPT','HYL','HYLTK','INDHYG','INDMAINSHYG','RESHOUSEHYG'
,'RESHYG','RESHYGREF-EA','RESHYGREF-NA','RESMAINSHYG','SERBUILDHYG','SERHYG','SERMAINSHYG','TRAHYG','TRAHYGDCN','TRAHYGL','TRAHYGS','TRAHYL'
,'UPSHYG','UPSMAINSHYG') then 'ALL HYDROGEN' --Filter 371
when commodity in('WNDONS','GEO','ELCWAV','RESSOL','HYDROR','ELCTID','SERSOL','HYDDAM','TID','ELCSOL','WNDOFF','WAV'
,'SOL','ELCWNDOFS','ELCGEO','ELCWNDONS','ELCHYDDAM','SERGEO') then 'ALL OTHER RNW' --Filter 226
end as "analysis",
tablename, attribute
from vedastore
where attribute = 'VAR_FIn'
)
select analysis || '|' || tablename || '|' || attribute || '|' || 'various' || '|various'::varchar(300) "id", analysis::varchar(50), tablename,'VAR_FIn' "attribute",
'various'::varchar(50) "commodity",
'various'::varchar(50) "process",
sum(pv)::numeric "all",
sum(case when period='2010' then pv else 0 end)::numeric "2010",
sum(case when period='2011' then pv else 0 end)::numeric "2011",
sum(case when period='2012' then pv else 0 end)::numeric "2012",
sum(case when period='2015' then pv else 0 end)::numeric "2015",
sum(case when period='2020' then pv else 0 end)::numeric "2020",
sum(case when period='2025' then pv else 0 end)::numeric "2025",
sum(case when period='2030' then pv else 0 end)::numeric "2030",
sum(case when period='2035' then pv else 0 end)::numeric "2035",
sum(case when period='2040' then pv else 0 end)::numeric "2040",
sum(case when period='2045' then pv else 0 end)::numeric "2045",
sum(case when period='2050' then pv else 0 end)::numeric "2050",
sum(case when period='2055' then pv else 0 end)::numeric "2055",
sum(case when period='2060' then pv else 0 end)::numeric "2060"
from (
select process,period,pv,
case
when proc='TRA-AVI-INT' then 'int-air-fuel_'
when proc='TRA-SHIP-INT' then 'int-ship-fuel_'
end
||
case
when analysis='ALL BIO' then 'bio'
when analysis='ALL ELECTRICITY' then 'elc'
when analysis='ALL GAS' then 'gas'
when analysis='ALL COALS' then 'coa'
when analysis='ALL OIL PRODUCTS' then 'oil'
when analysis='ALL HYDROGEN' then 'hyd'
when analysis='ALL OTHER RNW' then 'orens'
end as "analysis",
tablename, attribute
from fuels_in
where analysis <>'' and proc <>''
) a
group by id, analysis,tablename
order by tablename, analysis
) TO '%~dp0fuelByModeOut.csv' delimiter ',' CSV;
/* *Road transport fuel by mode and fuel* */
-- Breakdown of input fuels by road transport modes
COPY (
select analysis || '|' || tablename || '|' || attribute || '|various' || '|various'::varchar(300) "id", analysis, tablename,attribute,
'various'::varchar(50) "commodity",
'various'::varchar(50) "process",
sum(pv)::numeric "all",
sum(case when period='2010' then pv else 0 end)::numeric "2010",
sum(case when period='2011' then pv else 0 end)::numeric "2011",
sum(case when period='2012' then pv else 0 end)::numeric "2012",
sum(case when period='2015' then pv else 0 end)::numeric "2015",
sum(case when period='2020' then pv else 0 end)::numeric "2020",
sum(case when period='2025' then pv else 0 end)::numeric "2025",
sum(case when period='2030' then pv else 0 end)::numeric "2030",
sum(case when period='2035' then pv else 0 end)::numeric "2035",
sum(case when period='2040' then pv else 0 end)::numeric "2040",
sum(case when period='2045' then pv else 0 end)::numeric "2045",
sum(case when period='2050' then pv else 0 end)::numeric "2050",
sum(case when period='2055' then pv else 0 end)::numeric "2055",
sum(case when period='2060' then pv else 0 end)::numeric "2060"
from (
select process,period,pv,
case
when process like 'TC%' then 'cars-fuel_'
when process like 'TL%' then 'lgv-fuel_'
when process like 'TH%' then 'hgv-fuel_'
when process like 'TB%' then 'bus-fuel_'
when process like 'TW%' then 'bike-fuel_'
end ||
case
when commodity in('TRABIODST-FTL','TRABIODST-FTS') then 'sec-gen-biodiesel' --Filter 400
when commodity in('TRABIODSTL','TRABIODSTS') then 'biodiesel' --Filter 401
when commodity in('TRACNGL','TRACNGS') then 'cng' --Filter 402
when commodity in('TRADSTL','TRADSTS') then 'diesel' --Filter 403
when commodity in('TRACELC','TRACPHB') then 'elc' --Filter 404
when commodity in('TRAETHS') then 'ethanol' --Filter 405
when commodity in('TRAHYGL','TRAHYGS') then 'hydrogen' --Filter 406
when commodity in('TRALPGS') then 'lpg' --Filter 407
when commodity in('TRAPETS') then 'petrol' --Filter 408
end as "analysis",
tablename, attribute,commodity
from vedastore
where attribute = 'VAR_FIn' and process like any(array['TC%','TL%','TH%','TB%','TW%']) --Filter 45
) a
where analysis <>''
group by id, analysis,tablename, attribute
order by tablename, analysis, attribute
) TO '%~dp0rdTransFuel.csv' delimiter ',' CSV;
/* **End of Transport BAT (TraBatchUpload.bat): ** */
/* **Main "key outputs" BAT (MainBatchUpload.bat)** */
/* ------------------------------------------------*/
/* *Dummy imports by table* */
-- NB this only sums Cost_Act to see impact on the objective function- Filter was previously:
-- "where process like 'IMP%Z'" [not clear how these processes are created
-- as are not defined explicitly as part of the model topology]
COPY (
select 'dummies' || '|' || tablename || '|' || 'Cost_Act' || '|' || 'various' || '|various'::varchar(300) "id",
'dummies'::varchar(300) "analysis", tablename, 'Cost_Act'::varchar(50) "attribute",
'various'::varchar(50) "commodity",
'various'::varchar(50) "process",
sum(pv)::numeric "all",
sum(case when period='2010' then pv else 0 end)::numeric "2010",
sum(case when period='2011' then pv else 0 end)::numeric "2011",
sum(case when period='2012' then pv else 0 end)::numeric "2012",
sum(case when period='2015' then pv else 0 end)::numeric "2015",
sum(case when period='2020' then pv else 0 end)::numeric "2020",
sum(case when period='2025' then pv else 0 end)::numeric "2025",
sum(case when period='2030' then pv else 0 end)::numeric "2030",
sum(case when period='2035' then pv else 0 end)::numeric "2035",
sum(case when period='2040' then pv else 0 end)::numeric "2040",
sum(case when period='2045' then pv else 0 end)::numeric "2045",
sum(case when period='2050' then pv else 0 end)::numeric "2050",
sum(case when period='2055' then pv else 0 end)::numeric "2055",
sum(case when period='2060' then pv else 0 end)::numeric "2060"
from vedastore
where process in('IMPDEMZ','IMPMATZ','IMPNRGZ') and attribute = 'Cost_Act' --Filter 56
group by tablename
order by tablename, analysis
) TO '%~dp0dummiesout.csv' delimiter ',' CSV HEADER;
/* *All GHG emissions* */
-- Was ghg; now ghg_all- These are DECC categories
COPY (
select 'ghg_all|' || tablename || '|Var_FOut|' || commodity || '|all'::varchar(300) "id",
'ghg_all'::varchar(50) "analysis",
tablename,
'Var_FOut'::varchar(50) "attribute",
commodity,
'all'::varchar(50) "process",
sum(pv)::numeric "all",
sum(case when period='2010' then pv else 0 end)::numeric "2010",
sum(case when period='2011' then pv else 0 end)::numeric "2011",
sum(case when period='2012' then pv else 0 end)::numeric "2012",
sum(case when period='2015' then pv else 0 end)::numeric "2015",
sum(case when period='2020' then pv else 0 end)::numeric "2020",
sum(case when period='2025' then pv else 0 end)::numeric "2025",
sum(case when period='2030' then pv else 0 end)::numeric "2030",
sum(case when period='2035' then pv else 0 end)::numeric "2035",
sum(case when period='2040' then pv else 0 end)::numeric "2040",
sum(case when period='2045' then pv else 0 end)::numeric "2045",
sum(case when period='2050' then pv else 0 end)::numeric "2050",
sum(case when period='2055' then pv else 0 end)::numeric "2055",
sum(case when period='2060' then pv else 0 end)::numeric "2060"
from vedastore
where attribute='VAR_FOut' and commodity in('GHG-ETS-NO-IAS-NET','GHG-ETS-NO-IAS-TER','GHG-ETS-YES-IAS-NET','GHG-ETS-YES-IAS-TER',
'GHG-NO-IAS-YES-LULUCF-NET','GHG-NO-IAS-YES-LULUCF-TER','GHG-NON-ETS-YES-LULUCF-NET','GHG-NON-ETS-YES-LULUCF-TER',
'GHG-YES-IAS-YES-LULUCF-NET','GHG-YES-IAS-YES-LULUCF-TER','GHG-NO-AS-YES-LULUCF-NET') --Filter 57
group by tablename, commodity
order by tablename, commodity
) TO '%~dp0GHGOut.csv' delimiter ',' CSV;
/* *GHG emissions by sector* */
-- Energy-related process CO2 is reported separately- Non-energy process CO2, CH4, N20 etc are lumped- Separate line
-- for ETS traded emissions- Otherwise, broken down by commodities- Analysis field entries:
-- 'ghg_sec-main-secs' main sector breakdown
-- 'ghg_sec-prc-ets' energy-related CO2 process emissions from ETS
-- 'ghg_sec-prc-non-ets' Other non-ETS (process-related) emissions like CH4,N2O
-- 'ghg_sec-traded-emis-ets' traded ETS emissions
COPY (
select analysis || '|' || tablename || '|' || attribute || '|' || commodity || '|' || process::varchar(300) "id", analysis, tablename,attribute,
commodity, process,
sum(pv)::numeric "all",
sum(case when period='2010' then pv else 0 end)::numeric "2010",
sum(case when period='2011' then pv else 0 end)::numeric "2011",
sum(case when period='2012' then pv else 0 end)::numeric "2012",
sum(case when period='2015' then pv else 0 end)::numeric "2015",
sum(case when period='2020' then pv else 0 end)::numeric "2020",
sum(case when period='2025' then pv else 0 end)::numeric "2025",
sum(case when period='2030' then pv else 0 end)::numeric "2030",
sum(case when period='2035' then pv else 0 end)::numeric "2035",
sum(case when period='2040' then pv else 0 end)::numeric "2040",
sum(case when period='2045' then pv else 0 end)::numeric "2045",
sum(case when period='2050' then pv else 0 end)::numeric "2050",
sum(case when period='2055' then pv else 0 end)::numeric "2055",