forked from trynthink/scout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
final_mseg_converter_test.py
2374 lines (2312 loc) · 112 KB
/
final_mseg_converter_test.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
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
#!/usr/bin/env python3
"""Tests for the census division to climate zone conversion script.
"""
# Import code to be tested
import final_mseg_converter as fmc
# Import code with translation dicts
import com_mseg as cm
# Import needed packages
import unittest
import numpy as np
import copy
import itertools
class CommonUnitTest(unittest.TestCase):
""" Set up a common unittest.TestCase subclass with data and
functions common to the tests below """
def dict_check(self, dict1, dict2, msg=None):
"""Compare two dicts for equality, allowing for floating point error.
"""
# zip() and zip_longest() produce tuples for the items
# identified, where in the case of a dict, the first item
# in the tuple is the key and the second item is the value;
# in the case where the dicts are not of identical size,
# zip_longest() will use the fillvalue created below as a
# substitute in the dict that has missing content; this
# value is given as a tuple to be of comparable structure
# to the normal output from zip_longest()
fill_val = ('substituted entry', 5.2)
# In this structure, k and k2 are the keys that correspond to
# the dicts or unitary values that are found in i and i2,
# respectively, at the current level of the recursive
# exploration of dict1 and dict2, respectively
for (k, i), (k2, i2) in itertools.zip_longest(sorted(dict1.items()),
sorted(dict2.items()),
fillvalue=fill_val):
# Confirm that at the current location in the dict structure,
# the keys are equal; this should fail if one of the dicts
# is empty, is missing section(s), or has different key names
self.assertEqual(k, k2)
# If the recursion has not yet reached the terminal/leaf node
if isinstance(i, dict):
# Test that the dicts from the current keys are equal
self.assertCountEqual(i, i2)
# Continue to recursively traverse the dict
self.dict_check(i, i2)
# At the terminal/leaf node, if the value is a list
elif isinstance(i, list):
np.testing.assert_almost_equal(dict1[k], dict2[k2], decimal=3)
# At the terminal/leaf node
else:
# Compare the values, allowing for floating point inaccuracy
self.assertAlmostEqual(dict1[k], dict2[k2], places=3)
# Array of census division to climate zone conversion factors for
# energy, stock, and square footage data for residential buildings
# Derived from Res_Cdiv_Czone_ConvertTable_Final.txt
res_cd_cz_array = np.array([
(1, 0.2196, 0.7273, 0.0532, 0.0, 0.0),
(2, 0.0599, 0.3407, 0.5994, 0.0, 0.0),
(3, 0.1554, 0.6739, 0.1707, 0.0, 0.0),
(4, 0.3621, 0.206, 0.4274, 0.0045, 0.0),
(5, 0.0, 0.0096, 0.258, 0.3514, 0.3811),
(6, 0.0, 0.0, 0.287, 0.4393, 0.2736),
(7, 0.0, 0.0, 0.061, 0.1416, 0.7974),
(8, 0.1189, 0.3085, 0.1604, 0.0549, 0.3574),
(9, 0.0202, 0.0204, 0.2157, 0.6996, 0.0442)],
dtype=[('CDIV', '<i4'), ('AIA_CZ1', '<f8'), ('AIA_CZ2', '<f8'),
('AIA_CZ3', '<f8'), ('AIA_CZ4', '<f8'), ('AIA_CZ5', '<f8')])
# Array of census division to climate zone conversion factors for
# energy, stock, and square footage data for commercial buildings
# Derived from Com_Cdiv_Czone_ConvertTable_Final.txt
com_cd_cz_array = np.array([
(1, 0.2389, 0.7611, 0.0, 0.0, 0.0),
(2, 0.1546, 0.3568, 0.4886, 0.0, 0.0),
(3, 0.2668, 0.7332, 0.0, 0.0, 0.0),
(4, 0.4769, 0.2417, 0.2815, 0.0, 0.0),
(5, 0.0, 0.0, 0.2107, 0.515, 0.2743),
(6, 0.0, 0.0, 0.3102, 0.5726, 0.1172),
(7, 0.0, 0.0, 0.0616, 0.2638, 0.6746),
(8, 0.5681, 0.2986, 0.0, 0.0, 0.1332),
(9, 0.0701, 0.129, 0.0792, 0.708, 0.0137)],
dtype=[('CDIV', '<i4'), ('AIA_CZ1', '<f8'), ('AIA_CZ2', '<f8'),
('AIA_CZ3', '<f8'), ('AIA_CZ4', '<f8'), ('AIA_CZ5', '<f8')])
# Residential building census division to climate zone conversion
# factors for cost, performance, and lifetime data
# Derived from Res_Cdiv_Czone_ConvertTable_Rev_Final.txt
res_cd_cz_wtavg_array = np.array([
(1, 0.13296, 0.15477, 0.00997, 0, 0),
(2, 0.10044, 0.20077, 0.31107, 0, 0),
(3, 0.30485, 0.46459, 0.10366, 0, 0),
(4, 0.32086, 0.06415, 0.11721, 0.00146, 0),
(5, 0, 0.00822, 0.195, 0.31172, 0.35048),
(6, 0, 0, 0.06916, 0.12423, 0.08022),
(7, 0, 0, 0.0265, 0.07217, 0.42143),
(8, 0.10326, 0.09417, 0.04312, 0.01732, 0.11691),
(9, 0.03763, 0.01332, 0.1243, 0.4731, 0.03096)],
dtype=[('CDIV', '<i4'), ('AIA_CZ1', '<f8'), ('AIA_CZ2', '<f8'),
('AIA_CZ3', '<f8'), ('AIA_CZ4', '<f8'), ('AIA_CZ5', '<f8')])
# Commercial building census division to climate zone conversion
# factors for cost, performance, and lifetime data
# Derived from Com_Cdiv_Czone_ConvertTable_Rev_Final.txt
com_cd_cz_wtavg_array = np.array([
(1, 0.07044, 0.13487, 0, 0, 0),
(2, 0.13854, 0.19219, 0.41823, 0, 0),
(3, 0.28803, 0.47563, 0, 0, 0),
(4, 0.24615, 0.07497, 0.13876, 0, 0),
(5, 0, 0, 0.24293, 0.40379, 0.35346),
(6, 0, 0, 0.09947, 0.12486, 0.04198),
(7, 0, 0, 0.04431, 0.12909, 0.54244),
(8, 0.20464, 0.06465, 0, 0, 0.05122),
(9, 0.0522, 0.05769, 0.0563, 0.34226, 0.01089)],
dtype=[('CDIV', '<i4'), ('AIA_CZ1', '<f8'), ('AIA_CZ2', '<f8'),
('AIA_CZ3', '<f8'), ('AIA_CZ4', '<f8'), ('AIA_CZ5', '<f8')])
class DataRestructuringFunctionTest(CommonUnitTest):
""" Test the operation of the function that calculates the
contribution of each census division to each climate zone """
# Create a sample dict that takes the form of the data provided
# within each census division (each climate zone will have the
# same keys and structure, but different numbers)
orig_input = {
'single family home': {
'new homes': {'2009': 111, '2010': 111, '2011': 111},
'total homes': {'2009': 222, '2010': 222, '2011': 222},
'square footage': {'2009': 333, '2010': 333, '2011': 333},
'electricity (grid)': {
'lighting': {
'linear fluorescent': {
'stock': {'2009': 13, '2010': 14, '2011': 15},
'energy': {'2009': 16, '2010': 17, '2011': 18}}}}},
'mercantile/service': {
'total square footage': {'2009': 19, '2010': 21, '2011': 20},
'new square footage': {'2009': 6, '2010': 5, '2011': 4},
'electricity': {
'lighting': {
'F96T8 HO_HB': {'2009': 0.3, '2010': 0.6, '2011': 0.7}}},
'natural gas': {
'water heating': {'2009': 20, '2010': 22, '2011': 23}}}}
# Specify the census divisions to be tested; more than one census
# divisions is tested here because the mathematical treatment of
# the first census division (in the order in which it appears in
# the census division list 'cd_list') to be added to a climate
# zone is different than subsequent climate zones
census_divisions = [1, 2]
# Specify the climate zones to be tested with the census divisions
# specified by 'census_divisions'
climate_zones = [1, 1]
# Create an instance of the CommericalTranslationDicts object from
# com_mseg, which includes dictionaries for converting between
# descriptive string keys for e.g., census divisions and the
# corresponding integer numeric values for those strings
cd = cm.CommercialTranslationDicts()
# List of census divisions typically derived from the top-level
# keys in the input JSON database
cd_list = ['new england', 'mid atlantic', 'east north central']
# List the dicts that should be produced from the inputs to the
# merge_sum function in the order in which they should be tested
# (i.e., matching the order of 'census_divisions' and 'climate_zones')
loutput = [
{'single family home': {
'new homes': {
'2009': 117.6489, '2010': 117.6489, '2011': 117.6489},
'total homes': {
'2009': 235.2978, '2010': 235.2978, '2011': 235.2978},
'square footage': {
'2009': 352.9467, '2010': 352.9467, '2011': 352.9467},
'electricity (grid)': {
'lighting': {
'linear fluorescent': {
'energy': {
'2009': 16.9584,
'2010': 18.0183,
'2011': 19.0782},
'stock': {
'2009': 13.7787,
'2010': 14.8386,
'2011': 15.8985}}}}},
'mercantile/service': {
'total square footage': {
'2009': 21.9374, '2010': 24.2466, '2011': 23.092},
'new square footage': {
'2009': 6.9276, '2010': 5.773, '2011': 4.6184},
'electricity': {
'lighting': {
'F96T8 HO_HB': {
'2009': 0.3464, '2010': 0.6928, '2011': 0.8082}}},
'natural gas': {
'water heating': {
'2009': 23.092, '2010': 25.401, '2011': 26.556}}}},
{'single family home': {
'new homes': {
'2009': 128.2494, '2010': 128.2494, '2011': 128.2494},
'total homes': {
'2009': 256.4988, '2010': 256.4988, '2011': 256.4988},
'square footage': {
'2009': 384.7482, '2010': 384.7482, '2011': 384.7482},
'electricity (grid)': {
'lighting': {
'linear fluorescent': {
'energy': {
'2009': 18.4864,
'2010': 19.6418,
'2011': 20.7972},
'stock': {
'2009': 15.0202,
'2010': 16.1756,
'2011': 17.331}}}}},
'mercantile/service': {
'natural gas': {
'water heating': {
'2009': 25.336, '2010': 27.8696, '2011': 29.1363}},
'total square footage': {
'2009': 24.0692, '2010': 26.6028, '2011': 25.336},
'new square footage': {
'2009': 7.6008, '2010': 6.334, '2011': 5.0672},
'electricity': {
'lighting': {
'F96T8 HO_HB': {
'2009': 0.38, '2010': 0.7601, '2011': 0.8866}}}}}]
def test_conversion_calculation_for_individual_cz_cd_combinations(self):
for idx, _ in enumerate(self.census_divisions):
# Since the merge_sum function recursively operates on
# 'base_input', make the two required copies to serve as
# the inputs for testing purposes to ensure that all tests
# start with the same input data
base_input = copy.deepcopy(self.orig_input)
add_input = copy.deepcopy(self.orig_input)
# Call the function to be tested
result = fmc.merge_sum(base_input,
add_input,
self.census_divisions[idx],
self.climate_zones[idx],
self.cd.cdivdict,
self.cd_list,
self.res_cd_cz_array,
self.com_cd_cz_array)
self.dict_check(result, self.loutput[idx])
class ToClimateZoneConversionTest(CommonUnitTest):
""" Test the operation of the full climate conversion function
operating over multiple census divisions to convert the data to a
climate zone basis """
# Create a sample input dict of energy, square footage, and
# stock data in three census divisions
test_energy_stock_input = {
'new england': {
'single family home': {
'new homes': {
'2009': 1, '2010': 11, '2011': 1},
'total homes': {
'2009': 2, '2010': 22, '2011': 2},
'square footage': {
'2009': 3, '2010': 33, '2011': 3},
'electricity (grid)': {
'lighting': {
'linear fluorescent': {
'stock': {
'2009': 1,
'2010': 2,
'2011': 3},
'energy': {
'2009': 4,
'2010': 5,
'2011': 6}}},
'heating': {
'demand': {
'wall': {
'stock': 'NA',
'energy': {
'2009': 3.5,
'2010': 4,
'2011': 5}}}}}},
'mercantile/service': {
'total square footage': {
'2009': 12, '2010': 13, '2011': 14},
'new square footage': {
'2009': 2, '2010': 3, '2011': 4},
'electricity': {
'lighting': {
'F96T8 HO_HB': {
'2009': 0.1, '2010': 0.2, '2011': 0.3}}},
'natural gas': {
'water heating': {
'2009': 5, '2010': 6, '2011': 7}}}},
'mid atlantic': {
'single family home': {
'new homes': {
'2009': 11, '2010': 11, '2011': 11},
'total homes': {
'2009': 22, '2010': 22, '2011': 22},
'square footage': {
'2009': 33, '2010': 33, '2011': 33},
'electricity (grid)': {
'lighting': {
'linear fluorescent': {
'stock': {
'2009': 7,
'2010': 8,
'2011': 9},
'energy': {
'2009': 10,
'2010': 11,
'2011': 12}}},
'heating': {
'demand': {
'wall': {
'stock': 'NA',
'energy': {
'2009': 6,
'2010': 7,
'2011': 8}}}}}},
'mercantile/service': {
'total square footage': {
'2009': 6, '2010': 7, '2011': 8},
'new square footage': {
'2009': 2, '2010': 0, '2011': 1},
'electricity': {
'lighting': {
'F96T8 HO_HB': {
'2009': 0.5, '2010': 0.6, '2011': 0.7}}},
'natural gas': {
'water heating': {
'2009': 10, '2010': 11, '2011': 9}}}},
'east north central': {
'single family home': {
'new homes': {
'2009': 111, '2010': 111, '2011': 111},
'total homes': {
'2009': 222, '2010': 222, '2011': 222},
'square footage': {
'2009': 333, '2010': 333, '2011': 333},
'electricity (grid)': {
'lighting': {
'linear fluorescent': {
'stock': {
'2009': 13,
'2010': 14,
'2011': 15},
'energy': {
'2009': 16,
'2010': 17,
'2011': 18}}},
'heating': {
'demand': {
'wall': {
'stock': 'NA',
'energy': {
'2009': 2,
'2010': 3,
'2011': 4}}}}}},
'mercantile/service': {
'total square footage': {
'2009': 19, '2010': 21, '2011': 20},
'new square footage': {
'2009': 6, '2010': 5, '2011': 4},
'electricity': {
'lighting': {
'F96T8 HO_HB': {
'2009': 0.3, '2010': 0.6, '2011': 0.7}}},
'natural gas': {
'water heating': {
'2009': 20, '2010': 22, '2011': 23}}}}}
# Create a sample input dict of cost, performance, and lifetime
# data in three census divisions - note that including only a few
# census divisions is done to reduce the effort to set up these
# tests but will yield results that seem wrong because the
# contributions from the other census divisions are missing
test_cpl_input = {
'south atlantic': {
'mobile home': {
'new homes': 0,
'total homes': 0,
'square footage': 0,
'distillate': {
'heating': {
'supply': {
'boiler (distillate)': {
'installed cost': {
'typical': {
'2015': 20,
'2016': 30,
'2017': 40},
'best': {
'2015': 20,
'2016': 30,
'2017': 40},
'source': 'EIA AEO',
'units': '2013$/kBTU out/hr'},
'performance': {
'typical': {
'2015': 5,
'2016': 6,
'2017': 7},
'best': {
'2015': 5,
'2016': 6,
'2017': 7},
'source': 'EIA AEO',
'units': 'BTU out/BTU in'},
'lifetime': {
'average': {
'2015': 25,
'2016': 25,
'2017': 25},
'range': {
'2015': 25,
'2016': 25,
'2017': 25},
'source': 'EIA AEO',
'units': 'years'}}}}}},
'assembly': {
'total square footage': 0,
'new square footage': 0,
'electricity': {
'refrigeration': {
'consumer choice': {
'time preference': {
'2015': [0.1, 0.8, 1.2],
'2016': [0.1, 0.8, 1.2],
'2017': [0.1, 0.8, 1.2]},
'population fraction': {
'2015': [0.1, 0.3, 0.5],
'2016': [0.1, 0.3, 0.5],
'2017': [0.1, 0.3, 0.5]}},
'Supermkt_display_case': {
'installed cost': {
'typical': {
'2015': 3.5,
'2016': 4.5,
'2017': 5.5},
'best': {
'2015': 4.5,
'2016': 5.5,
'2017': 6.5},
'source': 'EIA AEO',
'units': '2013$/kBTU out/hr'},
'performance': {
'typical': {
'2015': 15,
'2016': 15,
'2017': 18},
'best': {
'2015': 15,
'2016': 15,
'2017': 20},
'source': 'EIA AEO',
'units': 'BTU out/BTU in'},
'lifetime': {
'average': {
'2015': 16,
'2016': 16,
'2017': 16},
'range': {
'2015': 24,
'2016': 24,
'2017': 24},
'source': 'EIA AEO',
'units': 'years'}}}},
'natural gas': {
'water heating': {
'consumer choice': {
'time preference': {
'2015': [0.1, 0.8, 1.2],
'2016': [0.1, 0.8, 1.2],
'2017': [0.1, 0.8, 1.2]},
'population fraction': {
'2015': [0.2, 0.4, 0.4],
'2016': [0.2, 0.4, 0.4],
'2017': [0.2, 0.4, 0.4]}},
'gas_water_heater': {
'installed cost': {
'typical': {
'2015': 6,
'2016': 6,
'2017': 6},
'best': {
'2015': 8,
'2016': 8,
'2017': 8},
'source': 'EIA AEO',
'units': '2013$/kBTU out/hr'},
'performance': {
'typical': {
'2015': 3.5,
'2016': 4.5,
'2017': 5.5},
'best': {
'2015': 4.5,
'2016': 5.5,
'2017': 6.5},
'source': 'EIA AEO',
'units': 'BTU out/BTU in'},
'lifetime': {
'average': {
'2015': 20,
'2016': 20,
'2017': 20},
'range': {
'2015': 30,
'2016': 30,
'2017': 30},
'source': 'EIA AEO',
'units': 'years'}}}}}},
'east south central': {
'mobile home': {
'new homes': 0,
'total homes': 0,
'square footage': 0,
'distillate': {
'heating': {
'supply': {
'boiler (distillate)': {
'installed cost': {
'typical': {
'2015': 7,
'2016': 8,
'2017': 9},
'best': {
'2015': 10,
'2016': 12,
'2017': 14},
'source': 'EIA AEO',
'units': '2013$/kBTU out/hr'},
'performance': {
'typical': {
'2015': 7,
'2016': 8,
'2017': 9},
'best': {
'2015': 10,
'2016': 12,
'2017': 14},
'source': 'EIA AEO',
'units': 'BTU out/BTU in'},
'lifetime': {
'average': {
'2015': 25,
'2016': 25,
'2017': 25},
'range': {
'2015': 25,
'2016': 25,
'2017': 25},
'source': 'EIA AEO',
'units': 'years'}}}}}},
'assembly': {
'total square footage': 0,
'new square footage': 0,
'electricity': {
'refrigeration': {
'consumer choice': {
'time preference': {
'2015': [0.1, 0.8, 1.2],
'2016': [0.1, 0.8, 1.2],
'2017': [0.1, 0.8, 1.2]},
'population fraction': {
'2015': [0.1, 0.3, 0.5],
'2016': [0.1, 0.3, 0.5],
'2017': [0.1, 0.3, 0.5]}},
'Supermkt_display_case': {
'installed cost': {
'typical': {
'2015': 28,
'2016': 35,
'2017': 57},
'best': {
'2015': 36,
'2016': 50,
'2017': 53.3},
'source': 'EIA AEO',
'units': '2013$/kBTU out/hr'},
'performance': {
'typical': {
'2015': 15,
'2016': 18,
'2017': 21},
'best': {
'2015': 16,
'2016': 19,
'2017': 22},
'source': 'EIA AEO',
'units': 'BTU out/BTU in'},
'lifetime': {
'average': {
'2015': 19,
'2016': 19,
'2017': 19},
'range': {
'2015': 28,
'2016': 28,
'2017': 28},
'source': 'EIA AEO',
'units': 'years'}}}},
'natural gas': {
'water heating': {
'consumer choice': {
'time preference': {
'2015': [0.1, 0.8, 1.2],
'2016': [0.1, 0.8, 1.2],
'2017': [0.1, 0.8, 1.2]},
'population fraction': {
'2015': [0.1, 0.3, 0.5],
'2016': [0.1, 0.3, 0.5],
'2017': [0.1, 0.3, 0.5]}},
'gas_water_heater': {
'installed cost': {
'typical': {
'2015': 10,
'2016': 15,
'2017': 20},
'best': {
'2015': 10,
'2016': 15,
'2017': 20},
'source': 'EIA AEO',
'units': '2013$/kBTU out/hr'},
'performance': {
'typical': {
'2015': 4,
'2016': 5,
'2017': 6},
'best': {
'2015': 4,
'2016': 5,
'2017': 6},
'source': 'EIA AEO',
'units': 'BTU out/BTU in'},
'lifetime': {
'average': {
'2015': 7,
'2016': 8,
'2017': 9},
'range': {
'2015': 10,
'2016': 11,
'2017': 12},
'source': 'EIA AEO',
'units': 'years'}}}}}},
'west south central': {
'mobile home': {
'new homes': 0,
'total homes': 0,
'square footage': 0,
'distillate': {
'heating': {
'supply': {
'boiler (distillate)': {
'installed cost': {
'typical': {
'2015': 2,
'2016': 3,
'2017': 4},
'best': {
'2015': 5,
'2016': 6,
'2017': 7},
'source': 'EIA AEO',
'units': '2013$/kBTU out/hr'},
'performance': {
'typical': {
'2015': 2,
'2016': 3,
'2017': 4},
'best': {
'2015': 5,
'2016': 6,
'2017': 7},
'source': 'EIA AEO',
'units': 'BTU out/BTU in'},
'lifetime': {
'average': {
'2015': 25,
'2016': 25,
'2017': 25},
'range': {
'2015': 25,
'2016': 25,
'2017': 25},
'source': 'EIA AEO',
'units': 'years'}}}}}},
'assembly': {
'total square footage': 0,
'new square footage': 0,
'electricity': {
'refrigeration': {
'consumer choice': {
'time preference': {
'2015': [0.1, 0.8, 1.2],
'2016': [0.1, 0.8, 1.2],
'2017': [0.1, 0.8, 1.2]},
'population fraction': {
'2015': [0.1, 0.4, 0.5],
'2016': [0.1, 0.4, 0.5],
'2017': [0.1, 0.4, 0.5]}},
'Supermkt_display_case': {
'installed cost': {
'typical': {
'2015': 11,
'2016': 12,
'2017': 14},
'best': {
'2015': 16,
'2016': 18,
'2017': 20},
'source': 'EIA AEO',
'units': '2013$/kBTU out/hr'},
'performance': {
'typical': {
'2015': 23,
'2016': 23,
'2017': 23},
'best': {
'2015': 27,
'2016': 27,
'2017': 27},
'source': 'EIA AEO',
'units': 'BTU out/BTU in'},
'lifetime': {
'average': {
'2015': 7,
'2016': 8,
'2017': 9},
'range': {
'2015': 10,
'2016': 11,
'2017': 12},
'source': 'EIA AEO',
'units': 'years'}}}},
'natural gas': {
'water heating': {
'consumer choice': {
'time preference': {
'2015': [0.1, 0.8, 1.2],
'2016': [0.1, 0.8, 1.2],
'2017': [0.1, 0.8, 1.2]},
'population fraction': {
'2015': [0.2, 0.3, 0.5],
'2016': [0.2, 0.3, 0.5],
'2017': [0.2, 0.3, 0.5]}},
'gas_water_heater': {
'installed cost': {
'typical': {
'2015': 3,
'2016': 5,
'2017': 7},
'best': {
'2015': 4,
'2016': 6,
'2017': 8},
'source': 'EIA AEO',
'units': '2013$/kBTU out/hr'},
'performance': {
'typical': {
'2015': 1.5,
'2016': 2.5,
'2017': 3.5},
'best': {
'2015': 2.5,
'2016': 3.5,
'2017': 4.5},
'source': 'EIA AEO',
'units': 'BTU out/BTU in'},
'lifetime': {
'average': {
'2015': 6,
'2016': 6,
'2017': 6},
'range': {
'2015': 6,
'2016': 6,
'2017': 6},
'source': 'EIA AEO',
'units': 'years'}}}}}}}
# Create a sample input dict that will trigger KeyError exceptions
# because it is not correctly structured
test_fail_input = {
'new england': {
'single family home': {
'electricity (grid)': {
'lighting': {
'linear fluorescent': {
'stock': {
'2009': 1,
'2010': 1,
'2011': 1},
'energy': {
'2009': 1,
'2010': 1,
'2011': 1}}}}}},
'middle atlantic': {
'single family home': {
'electricity (grid)': {
'lighting': {
'linear fluorescent': {
'stock': {
'2009': 2,
'2010': 2,
'2011': 2},
'energy': {
'2009': 2,
'2010': 2,
'2011': 2}}}}}},
'east north central': {
'single family home': {
'electricity (grid)': {
'lighting': {
'linear fluorescent': {
'stock': {
'2009': 3,
'2010': 3,
'2011': 3},
'energy': {
'2009': 3,
'2010': 3,
'2011': 3}}}}}}}
# Create an expected output dict of energy, square footage, and
# stock data structured by climate zone
test_energy_stock_output = {
'AIA_CZ1': {
'single family home': {
'new homes': {
'2009': 18.1279, '2010': 20.3239, '2011': 18.1279},
'total homes': {
'2009': 36.2558, '2010': 40.6478, '2011': 36.2558},
'square footage': {
'2009': 54.3837, '2010': 60.9717, '2011': 54.3837},
'electricity (grid)': {
'lighting': {
'linear fluorescent': {
"stock": {
"2009": 2.6591,
"2010": 3.0940,
"2011": 3.5289},
"energy": {
"2009": 3.9638,
"2010": 4.3987,
"2011": 4.8336}}},
'heating': {
'demand': {
'wall': {
'stock': 'NA',
'energy': {
'2009': 1.4388,
'2010': 1.7639,
'2011': 2.1988}}}}}},
'mercantile/service': {
'total square footage': {
'2009': 8.8636, '2010': 9.7907, '2011': 9.9174},
'new square footage': {
'2009': 2.3878, '2010': 2.0507, '2011': 2.1774},
'electricity': {
'lighting': {
'F96T8 HO_HB': {
'2009': 0.1812, '2010': 0.3006, '2011': 0.3667}}},
'natural gas': {
'water heating': {
'2009': 8.0765, '2010': 9.0036, '2011': 9.2001}}}},
'AIA_CZ2': {
'single family home': {
'new homes': {
'2009': 79.2779, '2010': 86.5509, '2011': 79.2779},
'total homes': {
'2009': 158.5558, '2010': 173.1018, '2011': 158.5558},
'square footage': {
'2009': 237.8337, '2010': 259.6527, '2011': 237.8337},
'electricity (grid)': {
'lighting': {
'linear fluorescent': {
"stock": {
"2009": 11.8729,
"2010": 13.6148,
"2011": 15.3567},
"energy": {
"2009": 17.0986,
"2010": 18.8405,
"2011": 20.5824}}},
'heating': {
'demand': {
'wall': {
'stock': 'NA',
'energy': {
'2009': 5.9376,
'2010': 7.3158,
'2011': 9.0578}}}}}},
'mercantile/service': {
'total square footage': {
'2009': 25.2048, '2010': 27.7891, '2011': 28.1738},
'new square footage': {
'2009': 6.635, '2010': 5.9493, '2011': 6.334},
'electricity': {
'lighting': {
'F96T8 HO_HB': {
'2009': 0.4745, '2010': 0.8062, '2011': 0.9913}}},
'natural gas': {
'water heating': {
'2009': 22.0375, '2010': 24.6218, '2011': 25.4025}}}},
'AIA_CZ3': {
'single family home': {
'new homes': {
'2009': 25.5943, '2010': 26.1263, '2011': 25.5943},
'total homes': {
'2009': 51.1886, '2010': 52.2526, '2011': 51.1886},
'square footage': {
'2009': 76.7829, '2010': 78.3789, '2011': 76.7829},
'electricity (grid)': {
'lighting': {
'linear fluorescent': {
"stock": {
"2009": 6.4681,
"2010": 7.2914,
"2011": 8.1147},
"energy": {
"2009": 8.9380,
"2010": 9.7613,
"2011": 10.5846}}},
'heating': {
'demand': {
'wall': {
'stock': 'NA',
'energy': {
'2009': 4.124,
'2010': 4.9207,
'2011': 5.744}}}}}},
'mercantile/service': {
'total square footage': {
'2009': 2.9316, '2010': 3.4202, '2011': 3.9088},
'new square footage': {
'2009': 0.9772, '2010': 0, '2011': 0.4886},
'electricity': {
'lighting': {
'F96T8 HO_HB': {
'2009': 0.2443, '2010': 0.2932, '2011': 0.3420}}},
'natural gas': {
'water heating': {
'2009': 4.886, '2010': 5.3746, '2011': 4.3974}}}},
'AIA_CZ4': {
'single family home': {
'new homes': {
'2009': 0, '2010': 0, '2011': 0},
'total homes': {
'2009': 0, '2010': 0, '2011': 0},
'square footage': {
'2009': 0, '2010': 0, '2011': 0},
'electricity (grid)': {
'lighting': {
'linear fluorescent': {
"stock": {
"2009": 0,
"2010": 0,
"2011": 0},
"energy": {
"2009": 0,
"2010": 0,
"2011": 0}}},
'heating': {
'demand': {
'wall': {
'stock': 'NA',
'energy': {
'2009': 0,
'2010': 0,
'2011': 0}}}}}},
'mercantile/service': {
'total square footage': {
'2009': 0, '2010': 0, '2011': 0},
'new square footage': {
'2009': 0, '2010': 0, '2011': 0},
'electricity': {
'lighting': {
'F96T8 HO_HB': {