forked from trynthink/scout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mseg_techdata_test.py
993 lines (930 loc) · 50.3 KB
/
mseg_techdata_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
#!/usr/bin/env python3
""" Tests for processing microsegment cost, performance, and lifetime data """
# Import code to be tested
import mseg_techdata
# Import needed packages
import unittest
import numpy
import itertools
class SimpleWalkTest(unittest.TestCase):
""" Test operation of a simpler version of the walk_techdata function, which
is used to walk through all the levels of the microsegments dictionary
structure and update the values at the end of each terminal leaf node """
# Define a test dict to walk through
in_dict = {
"cdiv 1": {"bldg 1": {"total square footage": None, "fuel 1": {
"end use 1": {"tech 1": None}}}},
"cdiv 2": {"bldg 2": {"total square footage": None, "fuel 2": {
"end use 2": {"tech 2": None}},
"fuel 3": {
"end use 3": {"tech 3": None}}}},
"cdiv 3": {"bldg 3": {"total square footage": None, "fuel 3": {
"end use 3": {"tech 4": None}}},
"bldg 4": {"fuel 4": {
"end use 4": {"tech 5": None}}}},
"cdiv 4": {"bldg 4": {"total square footage": None, "fuel 5": {
"end use 5": {"tech 6": {"sub tech 1": None,
"sub tech 2": None}}}}}}
# Define an output dict that should be yielded via the walk routine. As
# an additional check, the key chains leading to each terminal leaf node
# are set to be the values for those leaf nodes.
out_dict = {
"cdiv 1": {"bldg 1": {
"total square footage": None,
"fuel 1": {"end use 1": {
"tech 1":
["cdiv 1", "bldg 1", "fuel 1", "end use 1", "tech 1"]}}}},
"cdiv 2": {"bldg 2": {
"total square footage": None,
"fuel 2": {"end use 2": {
"tech 2":
["cdiv 2", "bldg 2", "fuel 2", "end use 2", "tech 2"]}},
"fuel 3": {"end use 3": {
"tech 3":
["cdiv 2", "bldg 2", "fuel 3", "end use 3", "tech 3"]}}}},
"cdiv 3": {
"bldg 3": {
"total square footage": None,
"fuel 3": {"end use 3": {
"tech 4":
["cdiv 3", "bldg 3", "fuel 3", "end use 3", "tech 4"]}}},
"bldg 4": {
"fuel 4": {"end use 4": {
"tech 5":
["cdiv 3", "bldg 4", "fuel 4", "end use 4", "tech 5"]}}}},
"cdiv 4": {
"bldg 4": {
"total square footage": None,
"fuel 5": {"end use 5": {
"tech 6": {
"sub tech 1":
["cdiv 4", "bldg 4", "fuel 5", "end use 5", "tech 6",
"sub tech 1"],
"sub tech 2": ["cdiv 4", "bldg 4", "fuel 5",
"end use 5", "tech 6", "sub tech 2"]
}}}}}}
def simple_walk(self, in_dict, key_list=[]):
""" This function represents a simpler version of the walk_techdata
function in mseg_techdata_test.py where terminal leaf node values are
assigned as the key chain that leads to the given leaf node """
for key, item in sorted(in_dict.items()):
# If there are additional levels in the dict, call the function
# again to advance another level deeper into the data structure
if isinstance(item, dict):
self.simple_walk(item, key_list + [key])
# If a leaf node has been reached, finish constructing the key
# list for the current location and update the data in the dict
else:
# Update key chain
leaf_node_keys = key_list + [key]
# Avoid updating a "total square footage" leaf node in
# the input dict; square footage is not relevant to the
# cost, performance, and lifetime data
if leaf_node_keys[-1] != "total square footage":
# Update dict key value to the updated key chain
in_dict[key] = leaf_node_keys
# Return updated dict
return in_dict
# Create a routine for checking equality of a dict
def dict_check(self, dict1, dict2, msg=None):
# Check that both dicts are populated (if not, the loop below
# will not start and thus the tests will not be run and the
# tests will appear to pass when in fact they were never run)
self.assertTrue(dict1, msg='dict1 is empty')
self.assertTrue(dict2, msg='dict2 is empty')
for (k, i), (k2, i2) in zip(sorted(dict1.items()),
sorted(dict2.items())):
# Confirm that at the current location in the dict structure,
# the keys are equal
self.assertEqual(k, k2)
if isinstance(i, dict):
self.assertCountEqual(i, i2)
self.dict_check(i, i2)
else:
self.assertEqual(dict1[k], dict2[k2])
# Test that a walk through the in_dict above updates its terminal
# leaf nodes to the correct values in the out_dict above
def test_walk_ok(self):
dict1 = self.simple_walk(self.in_dict)
dict2 = self.out_dict
self.dict_check(dict1, dict2)
class ListGeneratorTest(unittest.TestCase):
""" Test that the list_generator_techdata function correctly updates the
terminal leaf node values for an input dictionary with input technology
performance, cost, lifetime, and consumer choice information """
# Define a test input array in the format of EIA performance, cost, and
# consumer choice data on non-lighting technologies
eia_nlt_cp = numpy.array([(1, 2005, 2040, 3, 4.5, 3000, 2, 3, b"ELEC_RAD"),
(1, 2010, 2011, 1, 2.65, 1200, 1, 2,
b"ELEC_HP1"),
(1, 2011, 2012, 1, 3.1, 1250, 1, 2, b"ELEC_HP1"),
(1, 2012, 2014, 1, 4.5, 1450, 1, 2, b"ELEC_HP1"),
(1, 2014, 2040, 1, 5, 2000, 1, 2, b"ELEC_HP1"),
(1, 2010, 2011, 2, 3.65, 1200, 5, 6,
b"ELEC_HP1"),
(1, 2011, 2012, 2, 4.1, 1250, 5, 6, b"ELEC_HP1"),
(1, 2012, 2014, 2, 5.5, 1450, 5, 6, b"ELEC_HP1"),
(1, 2014, 2040, 2, 6, 2000, 5, 6, b"ELEC_HP1"),
(1, 2014, 2040, 2, 5, 2000, 5, 6, b"ELEC_HP1"),
(2, 2010, 2013, 3, 4.65, 1400, 3, 4,
b"ELEC_HP1"),
(2, 2013, 2040, 3, 5.1, 1450, 3, 4, b"ELEC_HP1"),
(1, 2005, 2010, 1, 2.75, 1200, 1, 2,
b"ELEC_HP2"),
(1, 2010, 2011, 1, 2.75, 1250, 1, 2,
b"ELEC_HP2"),
(1, 2011, 2012, 1, 3.2, 1270, 1, 2, b"ELEC_HP2"),
(1, 2012, 2014, 1, 4.6, 1800, 1, 2, b"ELEC_HP2"),
(1, 2014, 2040, 1, 5.1, 1900, 1, 2, b"ELEC_HP2"),
(1, 2005, 2010, 1, 2.8, 1000, 1, 2, b"ELEC_HP4"),
(1, 2010, 2011, 1, 2.9, 1300, 1, 2, b"ELEC_HP4"),
(1, 2011, 2012, 1, 3.3, 1400, 1, 2, b"ELEC_HP4"),
(1, 2012, 2014, 1, 4.8, 1500, 1, 2, b"ELEC_HP4"),
(1, 2014, 2040, 1, 6, 2000, 1, 2, b"ELEC_HP4"),
(5, 2007, 2040, 4, 3, 1000, 7, 8, b"ELEC_WH1"),
(5, 2005, 2009, 4, 2.8, 1000, 7, 8, b"NG_WH#1"),
(5, 2009, 2040, 4, 2.9, 1300, 7, 8, b"NG_WH#1"),
(5, 2005, 2009, 4, 2.9, 1000, 7, 8, b"NG_WH#2"),
(5, 2009, 2040, 4, 3.2, 1300, 7, 8, b"NG_WH#2"),
(5, 2005, 2009, 4, 3.2, 2000, 7, 8, b"NG_WH#4"),
(5, 2009, 2040, 4, 3.5, 1500, 7, 8, b"NG_WH#4"),
(5, 2005, 2009, 5, 2.8, 1000, 7, 8, b"NG_WH#1"),
(5, 2009, 2040, 5, 2.9, 1300, 7, 8, b"NG_WH#1"),
(5, 2005, 2009, 5, 2.9, 1000, 7, 8, b"NG_WH#2"),
(5, 2009, 2040, 5, 3.2, 1300, 7, 8, b"NG_WH#2"),
(5, 2005, 2009, 5, 3.2, 2000, 7, 8, b"NG_WH#4"),
(5, 2009, 2040, 5, 3.5, 1500, 7, 8, b"NG_WH#4"),
(6, 2010, 2011, 2, 28, 100, 6, 7, b"ELEC_STV1"),
(6, 2012, 2040, 2, 29, 130, 6, 7, b"ELEC_STV1"),
(6, 2010, 2011, 2, 29, 150, 6, 7, b"NG_STV1"),
(6, 2012, 2040, 2, 32, 160, 6, 7, b"NG_STV1"),
(6, 2010, 2011, 2, 31, 200, 6, 7, b"NG_STV2"),
(6, 2012, 2040, 2, 33, 170, 6, 7, b"NG_STV2"),
(6, 2010, 2011, 2, 32, 200, 6, 7, b"LPG_STV2"),
(6, 2012, 2040, 2, 35, 175, 6, 7, b"LPG_STV2"),
(6, 2010, 2011, 2, 33, 300, 6, 7, b"ELEC_STV2"),
(6, 2012, 2040, 2, 36, 250, 6, 7, b"ELEC_STV2"),
(7, 2010, 2011, 2, 128, 1010, 0, 1,
b"ELEC_DRY1"),
(7, 2012, 2040, 2, 129, 1310, 0, 1,
b"ELEC_DRY1"),
(7, 2010, 2011, 2, 129, 1510, 0, 1, b"NG_DRY1"),
(7, 2012, 2040, 2, 132, 1610, 0, 1, b"NG_DRY1"),
(7, 2010, 2011, 2, 131, 2010, 0, 1, b"NG_DRY2"),
(7, 2012, 2040, 2, 133, 1710, 0, 1, b"NG_DRY2"),
(7, 2010, 2011, 2, 133, 3010, 0, 1,
b"ELEC_DRY2"),
(7, 2012, 2040, 2, 136, 2510, 0, 1,
b"ELEC_DRY2"),
(3, 2010, 2040, 3, 15, 150, 4, 5, b"CW#1"),
(3, 2010, 2040, 3, 12, 175, 4, 5, b"CW#2"),
(3, 2010, 2040, 3, 10, 300, 4, 5, b"CW#3"),
(8, 2005, 2009, 3, 200, 300, 6, 6, b"RefSF#1"),
(8, 2009, 2013, 3, 300, 250, 6, 6, b"RefSF#1"),
(8, 2013, 2040, 3, 400, 200, 6, 6, b"RefSF#1"),
(8, 2005, 2009, 3, 300, 400, 7, 7, b"RefBF#1"),
(8, 2009, 2013, 3, 400, 300, 7, 7, b"RefBF#1"),
(8, 2013, 2040, 3, 500, 200, 7, 7, b"RefBF#1"),
(8, 2005, 2009, 3, 500, 500, 8, 8, b"RefTF#1"),
(8, 2009, 2013, 3, 600, 400, 8, 8, b"RefTF#1"),
(8, 2013, 2040, 3, 700, 300, 8, 8, b"RefTF#1"),
(8, 2005, 2009, 3, 800, 800, 6, 6, b"RefSF#2"),
(8, 2009, 2013, 3, 900, 700, 6, 6, b"RefSF#2"),
(8, 2013, 2040, 3, 1000, 600, 6, 6, b"RefSF#2"),
(8, 2005, 2009, 3, 900, 200, 6, 6, b"RefBF#2"),
(8, 2009, 2013, 3, 1000, 100, 6, 6, b"RefBF#2"),
(8, 2013, 2040, 3, 1100, 50, 6, 6, b"RefBF#2"),
(8, 2005, 2009, 3, 900, 1400, 6, 6, b"RefTF#3"),
(8, 2009, 2013, 3, 950, 1200, 6, 6, b"RefTF#3"),
(8, 2013, 2040, 3, 1000, 1100, 6, 6, b"RefTF#3"),
(8, 2005, 2009, 3, 1500, 700, 6, 6, b"RefTF#2"),
(8, 2009, 2013, 3, 1600, 650, 6, 6, b"RefTF#2"),
(8, 2013, 2040, 3, 1700, 550, 6, 6, b"RefTF#2"),
(8, 2005, 2009, 1, 1500, 700, 6, 6, b"RefTF#2"),
(8, 2009, 2013, 1, 1600, 650, 6, 6, b"RefTF#2"),
(8, 2013, 2040, 1, 1700, 550, 6, 6, b"RefTF#2"),
(2, 2005, 2009, 4, 2.75, 500, 6, 6, b"NG_HP"),
(2, 2009, 2011, 4, 2.95, 550, 6, 6, b"NG_HP"),
(2, 2011, 2050, 4, 3.15, 575, 6, 6, b"NG_HP"),
(1, 2009, 2050, 3, 3.15, 575, 6, 6, b"NG_RAD")
],
dtype=[("ENDUSE", "<i8"),
("START_EQUIP_YR", "<i8"),
("END_EQUIP_YR", "<f8"),
("CDIV", "<i8"),
("BASE_EFF", "<f8"),
("INST_COST", "<f8"),
("EFF_CHOICE_P1", "<f8"),
("EFF_CHOICE_P2", "<f8"),
("NAME", "S10")])
# Define a test input array in the format of EIA lifetime
# data on non-lighting technologies
eia_nlt_l = numpy.array([(1, 3.5, 19.5, b"ELEC_RAD"),
(1, 15, 20.1, b"ELEC_HP"),
(1, 15.6, 20.6, b"NG_FA"),
(2, 18.6, 19.1, b"CENT_AIR"),
(2, 18, 25, b"ELEC_HP"),
(5, 10, 20.5, b"ELEC_WH"),
(5, 8.5, 15.0, b"NG_WH"),
(6, 10.5, 12.4, b"ELEC_STV"),
(6, 17.9, 25, b"NG_STV"),
(6, 14.7, 27, b"LPG_STV"),
(7, 13.2, 21.6, b"ELEC_DRY"),
(7, 10, 17, b"NG_DRY"),
(3, 8.9, 16.7, b"CL_WASH"),
(8, 6.5, 11.1, b"REFR"),
(9, 5, 10.1, b"FREZ"),
(2, 2, 10, b"NG_HP"),
(1, 2, 20, b"NG_FA")],
dtype=[("ENDUSE", "<i8"),
("LIFE_MIN", "<f8"),
("LIFE_MAX", "<f8"),
("NAME", "S10")])
# Define a test input array in the format of EIA performance, cost, and
# lifetime data on lighting technologies
eia_lt = numpy.array([(2008, 2012, 0.33, 10000, 55, b"GSL", b"Inc"),
(2012, 2013, 1.03, 20000, 60, b"GSL", b"Inc"),
(2013, 2017, 1.53, 35000, 61.2, b"GSL", b"Inc"),
(2017, 2020, 2.75, 40000, 80.3, b"GSL", b"Inc"),
(2020, 2040, 3.45, 50000, 90, b"GSL", b"Inc"),
(2005, 2008, 0.35, 10000, 60, b"GSL", b"LED"),
(2008, 2010, 1.13, 30000, 65, b"GSL", b"LED"),
(2010, 2012, 1.55, 37000, 63.2, b"GSL", b"LED"),
(2012, 2040, 2.78, 42000, 90.3, b"GSL", b"LED"),
(2010, 2040, 3.71, 8000, 100.3, b"REF", b"LED")],
dtype=[("START_EQUIP_YR", "<i8"),
("END_EQUIP_YR", "<f8"),
("BASE_EFF", "<f8"),
("LIFE_HRS", "<f8"),
("INST_COST", "<f8"),
("NAME", "S3"),
("BULB_TYPE", "S3")])
# Define a test dict in the format of BTO-defined performance, cost
# and lifetime data on all technologies not covered by EIA data
# *** FOR NOW *** do not update any technologies in this routine for which
# there are no EIA cost, performance, and lifetime characteristics
tech_non_eia = {}
# tech_non_eia = {"secondary heating (electric)": [[5, 2, "Source 1"],
# [2, 3, "Source 2"],
# [50, 70, "Source 3"],
# "COP"],
# "secondary heating (natural gas)": [[4, 1, "Source 4"],
# [87, 92, "Source 5"],
# [60, 80, "Source 6"],
# "AFUE"],
# "secondary heating (kerosene)": [[1.1, 2.2, "Source 7"],
# [85, 99, "Source 8"],
# [100, 200, "Source 9"],
# "AFUE"],
# "secondary heating (wood)": [[10, 5, "Source 10"],
# [70, 85, "Source 11"],
# [45, 50, "Source 12"],
# "AFUE"],
# "secondary heating (LPG)": [[5, 5, "Source 13"],
# [90, 95, "Source 14"],
# [150, 175, "Source 15"],
# "AFUE"],
# "secondary heating (coal)": [[15, 10, "Source 16"],
# [77, 82, "Source 17"],
# [35, 55, "Source 17"],
# "AFUE"],
# "TV": [[1, 0.5, "Source 18"], [10.1, 20.4, "Source 18"],
# [500, 605, "Source 19"], "W"],
# "set top box": [[25, 2, "Source 20"],
# [100, 50, "Source 20"],
# [60, 43, "Source 20"], "W"],
# "DVD": [[7, 4, "Source 21"],
# [70, 60, "Source 21"], [20, 30, "Source 21"],
# "W"],
# "other MELs": [[0, 0, "NA"], [0, 0, "NA"],
# [0, 0, "NA"], "NA"],
# "windows conduction": [[25, 5, "RS Means"],
# [7, 10, "NREL Efficiency DB"],
# [20, 30, "RS Means"], "R Value"],
# "windows solar": [[20, 2, "RS Means"],
# [0.4, 0.3, "NREL Efficiency DB"],
# [20, 30, "RS Means"], "SHGC"],
# "wall": [[25, 7, "RS Means"], [6, 7, "EnergyStar"],
# [35, 40, "RS Means"], "R Value/sq.in."]}
# Define the modeling time horizon to test (2009:2013)
years = [str(i) for i in range(2009, 2013 + 1)]
project_dict = dict.fromkeys(years)
# Define sample technology choice parameters for residential lighting
# technologies (technology choice information is not included in 'eia_lt'
# above)
eia_lt_choice = {"b1": {k: -0.95
for k in project_dict.keys()},
"b2": {k: -0.10
for k in project_dict.keys()}}
# # Define sample technology choice parameters for residential envelope
# # component technologies (technology choice information is not included
# # for envelope component technologies in 'tech_non_eia' above)
# non_eia_env_choice = {"b1": {k: -0.003
# for k in project_dict.keys()},
# "b2": {k: -0.012
# for k in project_dict.keys()}}
# Define a sample list of full dictionary key chains that are defined
# while running through the microsegments JSON structure and which will
# be used to determine what performance, cost, lifetime, and consumer
# choice data to look for
tech_ok_keys = [["new england", "single family home",
"electricity", "heating", "supply", "ASHP"],
["east north central", "multi family home",
"electricity", "refrigeration"],
["east north central", "multi family home",
"electricity", "other",
"clothes washing"],
["mid atlantic", "single family home",
"natural gas", "cooking"],
["mid atlantic", "single family home",
"natural gas", "drying"],
["west north central", "mobile home",
"natural gas", "water heating"],
["west north central", "mobile home",
"electricity", "lighting",
"general service (LED)"],
["mid atlantic", "single family home",
"electricity", "secondary heating",
"supply", "secondary heater"],
["mid atlantic", "single family home",
"electricity", "secondary heating",
"demand", "windows conduction"],
["west north central", "multi family home",
"electricity", "cooling",
"supply", "NGHP"]]
# Define an output dict with leaf node values that should be yielded
# by the walk_techdata function given the valid inputs above. Output dict
# information for a given technology is organized by performance,
# installed cost, lifetime, and consumer choice. Within the performance
# and cost categories, a "typical" and "best" level are provided. For
# performance, cost, and lifetime categories, the units of the information
# are provided. For all categories, source information is provided.
ok_datadict_out = [{
"performance": {
"typical": {"2009": 2.65, "2010": 2.65, "2011": 3.1, "2012": 4.5,
"2013": 4.5},
"best": {"2009": 2.9, "2010": 2.9, "2011": 3.3, "2012": 4.8,
"2013": 4.8},
"units": "COP",
"source": "EIA AEO"},
"installed cost": {
"typical": {"2009": 1200, "2010": 1200, "2011": 1250, "2012": 1450,
"2013": 1450},
"best": {"2009": 1300, "2010": 1300, "2011": 1400, "2012": 1500,
"2013": 1500},
"units": "2013$/unit",
"source": "EIA AEO"},
"lifetime": {
"average": {"2009": 17.55, "2010": 17.55, "2011": 17.55,
"2012": 17.55, "2013": 17.55},
"range": {"2009": 2.55, "2010": 2.55, "2011": 2.55, "2012": 2.55,
"2013": 2.55},
"units": "years",
"source": "EIA AEO"},
"consumer choice": {
"competed market share":
{"model type": "logistic regression",
"parameters":
{"b1":
{"2009": 1, "2010": 1, "2011": 1,
"2012": 1, "2013": 1},
"b2":
{"2009": 2, "2010": 2, "2011": 2,
"2012": 2, "2013": 2}},
"source": "EIA AEO"}}},
{"performance": {
"typical": {"2009": 433.33, "2010": 433.33, "2011": 433.33,
"2012": 433.33, "2013": 533.33},
"best": {"2009": 1166.67, "2010": 1166.67, "2011": 1166.67,
"2012": 1166.67, "2013": 1266.67},
"units": "kWh/yr",
"source": "EIA AEO"},
"installed cost": {
"typical": {"2009": 316.67, "2010": 316.67, "2011": 316.67,
"2012": 316.67, "2013": 233.33},
"best": {"2009": 483.33, "2010": 483.33, "2011": 483.33,
"2012": 483.33, "2013": 400},
"units": "2013$/unit",
"source": "EIA AEO"},
"lifetime": {
"average": {"2009": 8.8, "2010": 8.8, "2011": 8.8, "2012": 8.8,
"2013": 8.8},
"range": {"2009": 2.3, "2010": 2.3, "2011": 2.3, "2012": 2.3,
"2013": 2.3},
"units": "years",
"source": "EIA AEO"},
"consumer choice": {
"competed market share":
{"model type": "logistic regression",
"parameters":
{"b1":
{"2009": 7, "2010": 7, "2011": 7,
"2012": 7, "2013": 7},
"b2":
{"2009": 7, "2010": 7, "2011": 7,
"2012": 7, "2013": 7}},
"source": "EIA AEO"}}},
{"performance": {
"typical": {"2009": 15, "2010": 15, "2011": 15, "2012": 15,
"2013": 15},
"best": {"2009": 10, "2010": 10, "2011": 10, "2012": 10,
"2013": 10},
"units": "kWh/cycle",
"source": "EIA AEO"},
"installed cost": {
"typical": {"2009": 150, "2010": 150, "2011": 150, "2012": 150,
"2013": 150},
"best": {"2009": 300, "2010": 300, "2011": 300, "2012": 300,
"2013": 300},
"units": "2013$/unit",
"source": "EIA AEO"},
"lifetime": {
"average": {"2009": 12.8, "2010": 12.8, "2011": 12.8, "2012": 12.8,
"2013": 12.8},
"range": {"2009": 3.9, "2010": 3.9, "2011": 3.9, "2012": 3.9,
"2013": 3.9},
"units": "years",
"source": "EIA AEO"},
"consumer choice": {
"competed market share":
{"model type": "logistic regression",
"parameters":
{"b1":
{"2009": 4, "2010": 4, "2011": 4,
"2012": 4, "2013": 4},
"b2":
{"2009": 5, "2010": 5, "2011": 5,
"2012": 5, "2013": 5}},
"source": "EIA AEO"}}},
{"performance": {
"typical": {"2009": 29, "2010": 29, "2011": 29, "2012": 32,
"2013": 32},
"best": {"2009": 31, "2010": 31, "2011": 31, "2012": 33,
"2013": 33},
"units": "TEff",
"source": "EIA AEO"},
"installed cost": {
"typical": {"2009": 150, "2010": 150, "2011": 150, "2012": 160,
"2013": 160},
"best": {"2009": 200, "2010": 200, "2011": 200, "2012": 170,
"2013": 170},
"units": "2013$/unit",
"source": "EIA AEO"},
"lifetime": {
"average": {"2009": 21.45, "2010": 21.45, "2011": 21.45,
"2012": 21.45, "2013": 21.45},
"range": {"2009": 3.55, "2010": 3.55, "2011": 3.55, "2012": 3.55,
"2013": 3.55},
"units": "years",
"source": "EIA AEO"},
"consumer choice": {
"competed market share":
{"model type": "logistic regression",
"parameters":
{"b1":
{"2009": 6, "2010": 6, "2011": 6,
"2012": 6, "2013": 6},
"b2":
{"2009": 7, "2010": 7, "2011": 7,
"2012": 7, "2013": 7}},
"source": "EIA AEO"}}},
{"performance": {
"typical": {"2009": 129, "2010": 129, "2011": 129, "2012": 132,
"2013": 132},
"best": {"2009": 131, "2010": 131, "2011": 131, "2012": 133,
"2013": 133},
"units": "EF",
"source": "EIA AEO"},
"installed cost": {
"typical": {"2009": 1510, "2010": 1510, "2011": 1510, "2012": 1610,
"2013": 1610},
"best": {"2009": 2010, "2010": 2010, "2011": 2010, "2012": 1710,
"2013": 1710},
"units": "2013$/unit",
"source": "EIA AEO"},
"lifetime": {
"average": {"2009": 13.5, "2010": 13.5, "2011": 13.5, "2012": 13.5,
"2013": 13.5},
"range": {"2009": 3.5, "2010": 3.5, "2011": 3.5, "2012": 3.5,
"2013": 3.5},
"units": "years",
"source": "EIA AEO"},
"consumer choice": {
"competed market share":
{"model type": "logistic regression",
"parameters":
{"b1":
{"2009": 0, "2010": 0, "2011": 0,
"2012": 0, "2013": 0},
"b2":
{"2009": 1, "2010": 1, "2011": 1,
"2012": 1, "2013": 1}},
"source": "EIA AEO"}}},
{"performance": {
"typical": {"2009": 2.9, "2010": 2.9, "2011": 2.9, "2012": 2.9,
"2013": 2.9},
"best": {"2009": 3.5, "2010": 3.5, "2011": 3.5, "2012": 3.5,
"2013": 3.5},
"units": "EF",
"source": "EIA AEO"},
"installed cost": {
"typical": {"2009": 1300, "2010": 1300, "2011": 1300, "2012": 1300,
"2013": 1300},
"best": {"2009": 1500, "2010": 1500, "2011": 1500, "2012": 1500,
"2013": 1500},
"units": "2013$/unit",
"source": "EIA AEO"},
"lifetime": {
"average": {"2009": 11.75, "2010": 11.75, "2011": 11.75,
"2012": 11.75, "2013": 11.75},
"range": {"2009": 3.25, "2010": 3.25, "2011": 3.25, "2012": 3.25,
"2013": 3.25},
"units": "years",
"source": "EIA AEO"},
"consumer choice": {
"competed market share":
{"model type": "logistic regression",
"parameters":
{"b1":
{"2009": 7, "2010": 7, "2011": 7,
"2012": 7, "2013": 7},
"b2":
{"2009": 8, "2010": 8, "2011": 8,
"2012": 8, "2013": 8}},
"source": "EIA AEO"}}},
{"performance": {
"typical": {"2009": 1.13, "2010": 1.55, "2011": 1.55, "2012": 2.78,
"2013": 2.78},
"best": 0,
"units": "lm/W",
"source": "EIA AEO"},
"installed cost": {
"typical": {"2009": 65, "2010": 63.2, "2011": 63.2, "2012": 90.3,
"2013": 90.3},
"best": 0,
"units": "2013$/unit",
"source": "EIA AEO"},
"lifetime": {
"average": {"2009": 3.42, "2010": 4.22, "2011": 4.22, "2012": 4.79,
"2013": 4.79},
"range": 0,
"units": "years",
"source": "EIA AEO"},
"consumer choice": {
"competed market share":
{"model type": "logistic regression",
"parameters":
{"b1":
{"2009": -0.95, "2010": -0.95, "2011": -0.95,
"2012": -0.95, "2013": -0.95},
"b2":
{"2009": -0.1, "2010": -0.1, "2011": -0.1,
"2012": -0.1, "2013": -0.1}},
"source": "EIA AEO"}}},
0,
0,
{"performance": {
"typical": {"2009": 2.95, "2010": 2.95, "2011": 3.15, "2012": 3.15,
"2013": 3.15},
"best": {"2009": 2.95, "2010": 2.95, "2011": 3.15, "2012": 3.15,
"2013": 3.15},
"units": "COP",
"source": "EIA AEO"},
"installed cost": {
"typical": {"2009": 550, "2010": 550, "2011": 575, "2012": 575,
"2013": 575},
"best": {"2009": 550, "2010": 550, "2011": 575, "2012": 575,
"2013": 575},
"units": "2013$/unit",
"source": "EIA AEO"},
"lifetime": {
"average": {"2009": 6, "2010": 6, "2011": 6, "2012": 6,
"2013": 6},
"range": {"2009": 4, "2010": 4, "2011": 4, "2012": 4,
"2013": 4},
"units": "years",
"source": "EIA AEO"},
"consumer choice": {
"competed market share":
{"model type": "logistic regression",
"parameters":
{"b1":
{"2009": 6, "2010": 6, "2011": 6,
"2012": 6, "2013": 6},
"b2":
{"2009": 6, "2010": 6, "2011": 6,
"2012": 6, "2013": 6}},
"source": "EIA AEO"}}}]
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 string
elif isinstance(i, str):
self.assertEqual(dict1[k], dict2[k2])
# At the terminal/leaf node
else:
# Compare the values, allowing for floating point inaccuracy
self.assertAlmostEqual(dict1[k], dict2[k2], places=2)
# Test that the walk_techdata function yields a correct output dict
# given the valid key chain input along with the other sample inputs
# defined above
def test_listgen_ok(self):
for (idx, tk) in enumerate(self.tech_ok_keys):
dict1 = mseg_techdata.list_generator_techdata(
self.eia_nlt_cp, self.eia_nlt_l, self.eia_lt,
self.eia_lt_choice,
mseg_techdata.tech_eia_nonlt, mseg_techdata.tech_eia_lt,
self.tech_non_eia, tk, self.project_dict)
dict2 = self.ok_datadict_out[idx]
if isinstance(dict2, dict):
self.dict_check(dict1, dict2)
else:
self.assertEqual(dict1, dict2)
class FillYrsTest(unittest.TestCase):
""" Test that both the fill_years_nlt and fill_years_lt functions yield
the correct non-lighting and lighting tech. cost, performance, lifetime,
and consumer choice info. given an input array with these data broken out
across various time periods. * Note: only the fill_years_nlt function
accesses consumer choice info. as this is not broken out by census divison,
building type, or year for lighting technologies; moreover, only the
fill_years_lt function accesses lifetime info. as lifetime is not broken
out by year for non-lighting technologies """
# Define a list of test input arrays with valid EIA data on the cost,
# performance, and consumer choice parameters for non-lighting technologies
# to be stitched together into a list of cost, performance, and choice
# output dicts that each cover the modeling time horizon. * Note: the
# second element in this list tests the special case of a freezer
# technology, which has data on multiple configurations that must be
# consolidated into a single "average" configuration for proper handling
# by the stitch function.
in_nonlt = [numpy.array([(2005, 2010, 2.5, 1000, 1, 2, b"ELEC_HP1"),
(2010, 2011, 2.65, 1200, 3, 4, b"ELEC_HP1"),
(2011, 2012, 3.1, 1250, 4.4, 5.5, b"ELEC_HP1"),
(2012, 2014, 4.5, 1450, 6.7, 8, b"ELEC_HP1"),
(2014, 2040, 5, 2000, 9, 9.1, b"ELEC_HP1")],
dtype=[("START_EQUIP_YR", "<i8"),
("END_EQUIP_YR", "<f8"),
("BASE_EFF", "<f8"),
("INST_COST", "<f8"),
("EFF_CHOICE_P1", "<f8"),
("EFF_CHOICE_P2", "<f8"),
("NAME", "S10")]),
numpy.array([(2005, 2010, 2.5, 1000, 10.1, 11, b"FrzrC#1"),
(2010, 2011, 2.65, 1200, 12, 13.2, b"FrzrC#1"),
(2011, 2012, 3.1, 1250, 14, 14.5, b"FrzrC#1"),
(2012, 2014, 4.5, 1450, 15, 16, b"FrzrC#1"),
(2014, 2040, 5, 2000, 17, 18.4, b"FrzrC#1"),
(2005, 2010, 3, 2000, 19.1, 20, b"FrzrU#1"),
(2010, 2011, 3.1, 1500, 21, 22, b"FrzrU#1"),
(2011, 2012, 3.7, 1500, 23.6, 23.7, b"FrzrU#1"),
(2012, 2014, 3.7, 1600, 24, 25, b"FrzrU#1"),
(2014, 2040, 6, 1900, 25.6, 25.7, b"FrzrU#1")],
dtype=[("START_EQUIP_YR", "<i8"),
("END_EQUIP_YR", "<f8"),
("BASE_EFF", "<f8"),
("INST_COST", "<f8"),
("EFF_CHOICE_P1", "<f8"),
("EFF_CHOICE_P2", "<f8"),
("NAME", "S10")])]
# Define a test input array with valid EIA data on the cost, performance,
# and lifetime of lighting technologies to be stitched together into
# a list of cost, performance, and lifetime output dicts that each covers
# the modeling time horizon
in_lt = numpy.array([(2008, 2012, 0.33, 10000, 55, b"GSL", b"Inc"),
(2012, 2013, 1.03, 20000, 60, b"GSL", b"Inc"),
(2013, 2017, 1.53, 35000, 61.2, b"GSL", b"Inc"),
(2017, 2020, 2.75, 40000, 80.3, b"GSL", b"Inc"),
(2020, 2040, 3.45, 50000, 90, b"GSL", b"Inc")],
dtype=[("START_EQUIP_YR", "<i8"),
("END_EQUIP_YR", "<f8"),
("BASE_EFF", "<f8"),
("LIFE_HRS", "<f8"),
("INST_COST", "<f8"),
("NAME", "S3"),
("BULB_TYPE", "S3")])
# Define a test input array with faulty EIA data that should yield an
# error in the fill_years_nlt and fill_years_lt function executions
# when paired with the tech_fail_keys below (multiple rows with same
# starting year and not a special technology case (refrigerators, freezers)
# or refrigerator/freezer case with inconsistent year bins
in_fail = [numpy.array([(2005, 2010, 2.5, 1000, b"Fail_Test1"),
(2010, 2011, 2.65, 1200, b"Fail_Test1"),
(2011, 2012, 3.1, 1250, b"Fail_Test1"),
(2012, 2014, 4.5, 1450, b"Fail_Test1"),
(2014, 2040, 5, 2000, b"Fail_Test1"),
(2005, 2010, 3, 2000, b"Fail_Test1"),
(2010, 2011, 3.1, 1500, b"Fail_Test1"),
(2011, 2012, 3.7, 1500, b"Fail_Test1"),
(2012, 2014, 3.7, 1600, b"Fail_Test1"),
(2014, 2040, 6, 1900, b"Fail_Test1")],
dtype=[("START_EQUIP_YR", "<i8"),
("END_EQUIP_YR", "<f8"),
("BASE_EFF", "<f8"),
("INST_COST", "<f8"),
("NAME", "S10")]),
numpy.array([(2009, 2013, 1, 500, b"FrzrU#1"),
(2013, 2040, 2, 600, b"FrzrU#1"),
(2009, 2011, 1, 500, b"FrzrC#1"),
(2011, 2013, 1, 500, b"FrzrC#1"),
(2013, 2040, 2, 600, b"FrzrC#1")],
dtype=[("START_EQUIP_YR", "<i8"),
("END_EQUIP_YR", "<f8"),
("BASE_EFF", "<f8"),
("INST_COST", "<f8"),
("NAME", "S10")])]
# Define a sample list of the technology-level keys that are defined while
# running through the microsegments JSON structure; these keys are used to
# flag non-lighting technologies that require special handling to update
# with EIA data because of their unique definitions in these data
# (i.e. refrigerators, freezers)
tech_ok_key = ["ASHP", "freezers"]
# Define a sample list of dictionary keys as above that should cause the
# fill_years_nonlt function to fail when paired with an input array that
# includes multiple rows with the same "START_EQUIP_YR" value (this is
# only allowed when "refrigerators" or "freezers" is in the key list)
tech_fail_keys = ["ASHP", "freezers"]
# Define the modeling time horizon to test (2009:2015)
years = [str(i) for i in range(2009, 2015 + 1)]
project_dict = dict.fromkeys(years)
# Define a list of output dicts that should be generated by the
# fill_years_nlt function for each year of the modeling time horizon
# based on the in_nonlt array input above
out_nonlt = [[{"2009": 2.65, "2010": 2.65, "2011": 3.1, "2012": 4.5,
"2013": 4.5, "2014": 5, "2015": 5},
{"2009": 1200, "2010": 1200, "2011": 1250, "2012": 1450,
"2013": 1450, "2014": 2000, "2015": 2000},
{"2009": 3, "2010": 3, "2011": 4.4, "2012": 6.7,
"2013": 6.7, "2014": 9, "2015": 9},
{"2009": 4, "2010": 4, "2011": 5.5, "2012": 8,
"2013": 8, "2014": 9.1, "2015": 9.1}],
[{"2009": 2.88, "2010": 2.88, "2011": 3.4, "2012": 4.1,
"2013": 4.1, "2014": 5.5, "2015": 5.5},
{"2009": 1350, "2010": 1350, "2011": 1375, "2012": 1525,
"2013": 1525, "2014": 1950, "2015": 1950},
{"2009": 16.5, "2010": 16.5, "2011": 18.8, "2012": 19.5,
"2013": 19.5, "2014": 21.3, "2015": 21.3},
{"2009": 17.6, "2010": 17.6, "2011": 19.1, "2012": 20.5,
"2013": 20.5, "2014": 22.05, "2015": 22.05}]]
# Define a list of output dicts that should be generated by the
# fill_years_lt function for each year of the modeling time horizon
# based on the in_lt array input above
out_lt = [{"2009": 0.33, "2010": 0.33, "2011": 0.33, "2012": 1.03,
"2013": 1.53, "2014": 1.53, "2015": 1.53},
{"2009": 55, "2010": 55, "2011": 55, "2012": 60,
"2013": 61.2, "2014": 61.2, "2015": 61.2},
{"2009": 1.14, "2010": 1.14, "2011": 1.14, "2012": 2.28,
"2013": 4.00, "2014": 4.00, "2015": 4.00}]
# Create a routine for checking equality of a dict
def dict_check(self, dict1, dict2, msg=None):
for (k, i), (k2, i2) in zip(sorted(dict1.items()),
sorted(dict2.items())):
if isinstance(i, dict):
self.assertCountEqual(i, i2)
self.dict_check(i, i2)
else:
self.assertAlmostEqual(dict1[k], dict2[k2], places=2)
# Test that the fill_years_nlt function yields a correct output list
# given the in_nlt numpy array, modeling time horizon, and tech_ok_keys
# inputs defined above
def test_fill_nlt(self):
for (idx, tk) in enumerate(self.tech_ok_key):
list1 = mseg_techdata.fill_years_nlt(
self.in_nonlt[idx], self.project_dict, tk)
list2 = self.out_nonlt[idx]
for (el1, el2) in zip(list1, list2):
dict1 = el1
dict2 = el2
self.dict_check(dict1, dict2)
# Test that the fill_years_lt function yields a correct output list given
# the in_lt numpy array and modeling time horizon inputs defined above
def test_fill_lt(self):
list1 = mseg_techdata.fill_years_lt(
self.in_lt, self.project_dict)
list2 = self.out_lt
for (el1, el2) in zip(list1, list2):
dict1 = el1
dict2 = el2
self.dict_check(dict1, dict2)
# Test that both the fill_years nlt and fill_years_lt functions yield a
# ValueError when provided a numpy array input that has multiple rows
# with the same "START_EQUIP_YR" value or a special case with multiple
# sub-types of a technology that have inconsistent year bins
def test_fail(self):
for idx, x in enumerate(self.tech_fail_keys):
with self.assertRaises(ValueError):
mseg_techdata.fill_years_nlt(self.in_fail[idx],
self.project_dict,
x)
mseg_techdata.fill_years_lt(self.in_fail, self.project_dict)
class StitchTest(unittest.TestCase):
""" Test operation of stitch function, which reconstructs EIA performance,
cost, lifetime, and consumer choice projections for a technology between a
series of time periods (i.e. 2010-2014, 2014-2020, 2020-2040) in a dict
with annual keys across a given modeling time horizon (i.e. {"2009": XXX,
"2010": XXX, ..., "2040": XXX}) """
# Define a test input array with valid EIA data to stitch together
# across modeling time horizon
ok_array = numpy.array([(2008, 2012, 0.33, 14.5, 55, b"GSL", b"Inc"),
(2012, 2013, 1.03, 20, 60, b"GSL", b"Inc"),
(2013, 2017, 1.53, 21, 61.2, b"GSL", b"Inc"),
(2017, 2020, 2.75, 22, 80.3, b"GSL", b"Inc"),
(2020, 2040, 3.45, 23, 90, b"GSL", b"Inc")],
dtype=[("START_EQUIP_YR", "<i8"),
("END_EQUIP_YR", "<f8"),
("BASE_EFF", "<f8"),
("LIFE_HRS", "<f8"),
("INST_COST", "<f8"),
("NAME", "S3"),
("BULB_TYPE", "S3")])
# Define a test input array with faulty EIA data that should yield an
# error in the function execution (multiple rows with same starting year)
fail_array = numpy.array([(2008, 2012, 0.33, 14.5, 55, b"GSL", b"Inc"),
(2012, 2013, 1.03, 20, 60, b"GSL", b"Inc"),
(2013, 2017, 1.53, 21, 61.2, b"GSL", b"Inc"),
(2017, 2020, 2.75, 22, 80.3, b"GSL", b"Inc"),
(2020, 2040, 3.45, 23, 90, b"GSL", b"Inc"),
(2013, 2017, 1.53, 21, 61.2, b"GSL", b"Inc"),
(2017, 2020, 2.75, 22, 80.3, b"GSL", b"Inc"),
(2020, 2040, 3.45, 23, 90, b"GSL", b"Inc")],
dtype=[("START_EQUIP_YR", "<i8"),
("END_EQUIP_YR", "<f8"),
("BASE_EFF", "<f8"),
("LIFE_HRS", "<f8"),
("INST_COST", "<f8"),
("NAME", "S3"),
("BULB_TYPE", "S3")])
# Define the modeling time horizon to test (2009:2015)
years = [str(i) for i in range(2009, 2015 + 1)]
project_dict = dict.fromkeys(years)
# Define the each variable (column) in the input array with the values that
# will be reconstructed annually across the modeling time horizon, based on
# each row"s "START_EQUIP_YR" column value
col_names = ["BASE_EFF", "INST_COST", "LIFE_HRS"]
# Define a dict of output values for the above variables in col_names that
# should be generated by the function for each year of the modeling time
# horizon based on the ok_array above
ok_out = [{"2009": 0.33, "2010": 0.33, "2011": 0.33, "2012": 1.03,
"2013": 1.53, "2014": 1.53, "2015": 1.53},
{"2009": 55, "2010": 55, "2011": 55, "2012": 60,
"2013": 61.2, "2014": 61.2, "2015": 61.2},
{"2009": 14.5, "2010": 14.5, "2011": 14.5, "2012": 20,
"2013": 21, "2014": 21, "2015": 21}]
# Create a routine for checking equality of a dict
def dict_check(self, dict1, dict2, msg=None):
for (k, i), (k2, i2) in zip(sorted(dict1.items()),
sorted(dict2.items())):
if isinstance(i, dict):
self.assertCountEqual(i, i2)
self.dict_check(i, i2)
else:
self.assertAlmostEqual(dict1[k], dict2[k2], places=2)
# Test that the function yields a correct output dict for each set of
# variable values to be stitched together across the modeling time
# horizon, given the ok_array above as an input
def test_convert_match(self):
for (idx, col_name) in enumerate(self.col_names):
dict1 = mseg_techdata.stitch(
self.ok_array, self.project_dict,
col_name)
dict2 = self.ok_out[idx]
self.dict_check(dict1, dict2)
# Test that the function yields a ValueError given the fail_array above,
# which includes multiple rows with the same "START_EQUIP_YR" column value
def test_convert_fail(self):
for (idx, col_name) in enumerate(self.col_names):
with self.assertRaises(ValueError):
mseg_techdata.stitch(self.fail_array, self.project_dict,
col_name)
# Offer external code execution (include all lines below this point in all
# test files)
def main():
# Triggers default behavior of running all test fixtures in the file
unittest.main()
if __name__ == "__main__":
main()