forked from jtlangevin/flex-bldgs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflex.py
More file actions
2055 lines (1928 loc) · 99.4 KB
/
flex.py
File metadata and controls
2055 lines (1928 loc) · 99.4 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
#!/usr/bin/env python3
import pymc3 as pm
import theano as tt
from theano.sandbox.rng_mrg import MRG_RandomStream
import numpy as np
import pandas as pd
# from numpy.polynomial.polynomial import polyfit
from scipy.special import softmax
from scipy import stats
from os import getcwd, path, remove
from argparse import ArgumentParser
import pickle
import arviz as az
import seaborn as sns
from matplotlib import pyplot as plt
import matplotlib as mpl
import json
from pymc3.exceptions import SamplingError
from matplotlib.ticker import FormatStrFormatter
tt.config.compute_value = "ignore"
class UsefulFilesVars(object):
"""Summarize key model input, estimation, and output information.
Attributes:
coefs (tuple): Path to CSV file with regression coefficients
coef_names_dtypes (list): Variable names/formats for coefficients CSV
mod_dict (dict): Dict with information on input data, variables, and
output plotting file names for each model type.
predict_out (JSON): Output JSON with strategy recommendation pcts.
"""
def __init__(self, bldg_type_vint, mod_init, mod_est, mod_assess):
"""Initialize class attributes."""
# Initialize all data input variables as None
dmd_bl_dat, stored_dmd_bl, dmd_therm_dat, dmd_ntherm_dat, tmp_dat, \
dmd_tmp_dat, stored_tmp, stored_dmd_therm, stored_dmd_ntherm, \
stored_lt, pc_dmd_dat, stored_pc_dmd = (None for n in range(12))
# Set data input and output files for all models
# Medium office, >=2004 vintage
if bldg_type_vint == "mediumofficenew":
# Handle data inputs differently for model initialization vs.
# model re-estimation and prediction (the former uses different
# CSVs for each building type, while the latter will only draw
# from one CSV)
if mod_init is True or (mod_assess is True and mod_est is False):
dmd_bl_dat = ("data", "MO_B.csv")
dmd_therm_dat = ("data", "MO_Thermal_Demand_new.csv")
dmd_ntherm_dat = ("data", "MO_Nonthermal_Demand_new.csv")
tmp_dat = ("data", "MO_Temperature_new.csv")
pc_dmd_dat = ("data", "MO_PC_Demand_new.csv")
elif mod_est is True:
dmd_bl_dat = ("data", "test_update_bl.csv")
dmd_therm_dat, dmd_ntherm_dat, tmp_dat, pc_dmd_dat = (
("data", "test_update.csv") for n in range(4))
else:
dmd_bl_dat = ("data", "test_predict_bl.csv")
dmd_therm_dat, dmd_ntherm_dat, tmp_dat, pc_dmd_dat = (
("data", "test_predict.csv") for n in range(4))
# Set stored model data files
stored_dmd_bl = ("model_stored", "dmd_mo_b.pkl")
stored_dmd_therm = ("model_stored", "dmd_therm_mo_n.pkl")
stored_dmd_ntherm = ("model_stored", "dmd_ntherm_mo_n.pkl")
stored_tmp = ("model_stored", "tmp_mo_n.pkl")
stored_pc_dmd = ("model_stored", "pc_dmd_mo_n.pkl")
# Regression coefficients
self.coefs = ("data", "coefs_mo_n.csv")
# Medium office, <2004 vintage
elif bldg_type_vint == "mediumofficeold":
if mod_init is True or (mod_assess is True and mod_est is False):
dmd_bl_dat = ("data", "MO_B.csv")
dmd_therm_dat = ("data", "MO_Thermal_Demand_old.csv")
dmd_ntherm_dat = ("data", "MO_Nonthermal_Demand_old.csv")
tmp_dat = ("data", "MO_Temperature_old.csv")
pc_dmd_dat = ("data", "MO_PC_Demand_old.csv")
elif mod_est is True:
dmd_bl_dat = ("data", "test_update_bl.csv")
dmd_therm_dat, dmd_ntherm_dat, tmp_dat, pc_dmd_dat = (
("data", "test_update.csv") for n in range(4))
else:
dmd_bl_dat = ("data", "test_predict_bl.csv")
dmd_therm_dat, dmd_ntherm_dat, tmp_dat, pc_dmd_dat = (
("data", "test_predict.csv") for n in range(4))
# Set stored model data files
stored_dmd_bl = ("model_stored", "dmd_mo_b.pkl")
stored_dmd_therm = ("model_stored", "dmd_therm_mo_o.pkl")
stored_dmd_ntherm = ("model_stored", "dmd_ntherm_mo_o.pkl")
stored_tmp = ("model_stored", "tmp_mo_o.pkl")
stored_pc_dmd = ("model_stored", "pc_dmd_mo_o.pkl")
# Regression coefficients
self.coefs = ("data", "coefs_mo_o.csv")
# Retail, >=2004 vintage
elif bldg_type_vint == "stdaloneretailnew":
if mod_init is True or (mod_assess is True and mod_est is False):
dmd_bl_dat = ("data", "SR_B.csv")
dmd_therm_dat = ("data", "SR_Thermal_Demand_new.csv")
dmd_ntherm_dat = ("data", "SR_Nonthermal_Demand_new.csv")
tmp_dat = ("data", "SR_Temperature_new.csv")
pc_dmd_dat = ("data", "SR_PC_Demand_new.csv")
elif mod_est is True:
dmd_bl_dat = ("data", "test_update_bl.csv")
dmd_therm_dat, dmd_ntherm_dat, tmp_dat, pc_dmd_dat = (
("data", "test_update.csv") for n in range(4))
else:
dmd_bl_dat = ("data", "test_predict_bl.csv")
dmd_therm_dat, dmd_ntherm_dat, tmp_dat, pc_dmd_dat = (
("data", "test_predict.csv") for n in range(4))
# Set stored model data files
stored_dmd_bl = ("model_stored", "dmd_saret_b.pkl")
stored_dmd_therm = ("model_stored", "dmd_therm_saret_n.pkl")
stored_dmd_ntherm = ("model_stored", "dmd_ntherm_saret_n.pkl")
stored_tmp = ("model_stored", "tmp_saret_n.pkl")
stored_pc_dmd = ("model_stored", "pc_dmd_saret_n.pkl")
# Regression coefficients
self.coefs = ("data", "coefs_saret_n.csv")
# Retail, <2004 vintage
elif bldg_type_vint == "stdaloneretailold":
if mod_init is True or (mod_assess is True and mod_est is False):
dmd_bl_dat = ("data", "SR_B.csv")
dmd_therm_dat = ("data", "SR_Thermal_Demand_old.csv")
dmd_ntherm_dat = ("data", "SR_Nonthermal_Demand_old.csv")
tmp_dat = ("data", "SR_Temperature_old.csv")
pc_dmd_dat = ("data", "SR_PC_Demand_old.csv")
elif mod_est is True:
dmd_bl_dat = ("data", "test_update_bl.csv")
dmd_therm_dat, dmd_ntherm_dat, tmp_dat, pc_dmd_dat = (
("data", "test_update.csv") for n in range(4))
else:
dmd_bl_dat = ("data", "test_predict_bl.csv")
dmd_therm_dat, dmd_ntherm_dat, tmp_dat, pc_dmd_dat = (
("data", "test_predict.csv") for n in range(4))
# Set stored model data files
stored_dmd_bl = ("model_stored", "dmd_saret_b.pkl")
stored_dmd_therm = ("model_stored", "dmd_therm_saret_o.pkl")
stored_dmd_ntherm = ("model_stored", "dmd_ntherm_saret_o.pkl")
stored_tmp = ("model_stored", "tmp_saret_o.pkl")
stored_pc_dmd = ("model_stored", "pc_dmd_saret_o.pkl")
# Regression coefficients
self.coefs = ("data", "coefs_saret_o.csv")
# Large office, >=2004 vintage
elif bldg_type_vint == "largeofficenew":
if mod_init is True or (mod_assess is True and mod_est is False):
dmd_bl_dat = ("data", "MO_B.csv") # ***** UPDATE *****
dmd_therm_dat = ("data", "LO_Thermal_Demand_new.csv")
dmd_ntherm_dat = ("data", "LO_Nonthermal_Demand_new.csv")
tmp_dat = ("data", "LO_Temperature_new.csv")
pc_dmd_dat = ("data", "LO_PC_Demand_new.csv")
elif mod_est is True:
dmd_bl_dat = ("data", "test_update_bl.csv")
dmd_therm_dat, dmd_ntherm_dat, tmp_dat, pc_dmd_dat = (
("data", "test_update.csv") for n in range(4))
else:
dmd_bl_dat = ("data", "test_predict_bl.csv")
dmd_therm_dat, dmd_ntherm_dat, tmp_dat, pc_dmd_dat = (
("data", "test_predict.csv") for n in range(4))
# Set stored model data files
stored_dmd_bl = ("model_stored", "dmd_lo_b.pkl")
stored_dmd_therm = ("model_stored", "dmd_therm_lo_n.pkl")
stored_dmd_ntherm = ("model_stored", "dmd_ntherm_lo_n.pkl")
stored_tmp = ("model_stored", "tmp_lo_n.pkl")
stored_pc_dmd = ("model_stored", "pc_dmd_lo_n.pkl")
# Regression coefficients
self.coefs = ("data", "coefs_lo_n.csv")
# Large office, <2004 vintage
elif bldg_type_vint == "largeofficeold":
if mod_init is True or (mod_assess is True and mod_est is False):
dmd_bl_dat = ("data", "MO_B.csv") # ***** UPDATE *****
dmd_therm_dat = ("data", "LO_Thermal_Demand_old.csv")
dmd_ntherm_dat = ("data", "LO_Nonthermal_Demand_old.csv")
tmp_dat = ("data", "LO_Temperature_old.csv")
pc_dmd_dat = ("data", "LO_PC_Demand_old.csv")
elif mod_est is True:
dmd_bl_dat = ("data", "test_update_bl.csv")
dmd_therm_dat, dmd_ntherm_dat, tmp_dat, pc_dmd_dat = (
("data", "test_update.csv") for n in range(4))
else:
dmd_bl_dat = ("data", "test_predict_bl.csv")
dmd_therm_dat, dmd_ntherm_dat, tmp_dat, pc_dmd_dat = (
("data", "test_predict.csv") for n in range(4))
# Set stored model data files
stored_dmd_bl = ("model_stored", "dmd_lo_b.pkl")
stored_dmd_therm = ("model_stored", "dmd_therm_lo_o.pkl")
stored_dmd_ntherm = ("model_stored", "dmd_ntherm_lo_o.pkl")
stored_tmp = ("model_stored", "tmp_lo_o.pkl")
stored_pc_dmd = ("model_stored", "pc_dmd_lo_o.pkl")
# Regression coefficients
self.coefs = ("data", "coefs_lo_o.csv")
# Large office (all-electric), >=2004 vintage
elif bldg_type_vint == "largeofficenew_elec":
if mod_init is True or (mod_assess is True and mod_est is False):
dmd_bl_dat = ("data", "MO_B.csv") # ***** UPDATE *****
dmd_therm_dat = ("data", "LO_allElec_Thermal_Demand_new.csv")
dmd_ntherm_dat = (
"data", "LO_allElec_Nonthermal_Demand_new.csv")
tmp_dat = ("data", "LO_allElec_Temperature_new.csv")
pc_dmd_dat = ("data", "LO_allElec_PC_Demand_new.csv")
elif mod_est is True:
dmd_bl_dat = ("data", "test_update_bl.csv")
dmd_therm_dat, dmd_ntherm_dat, tmp_dat, pc_dmd_dat = (
("data", "test_update.csv") for n in range(4))
else:
dmd_bl_dat = ("data", "test_predict_bl.csv")
dmd_therm_dat, dmd_ntherm_dat, tmp_dat, pc_dmd_dat = (
("data", "test_predict.csv") for n in range(4))
# Set stored model data files
stored_dmd_bl = ("model_stored", "dmd_lo_allelec_b.pkl")
stored_dmd_therm = ("model_stored", "dmd_therm_lo_allelec_n.pkl")
stored_dmd_ntherm = ("model_stored", "dmd_ntherm_lo_allelec_n.pkl")
stored_tmp = ("model_stored", "tmp_lo_allelec_n.pkl")
stored_pc_dmd = ("model_stored", "pc_dmd_lo_allelec_n.pkl")
# Regression coefficients
self.coefs = ("data", "coefs_lo_elec_n.csv")
# Large office (all-electric), <2004 vintage
elif bldg_type_vint == "largeofficeold_elec":
if mod_init is True or (mod_assess is True and mod_est is False):
dmd_bl_dat = ("data", "MO_B.csv") # ***** UPDATE *****
dmd_therm_dat = ("data", "LO_allElec_Thermal_Demand_old.csv")
dmd_ntherm_dat = (
"data", "LO_allElec_Nonthermal_Demand_old.csv")
tmp_dat = ("data", "LO_allElec_Temperature_old.csv")
pc_dmd_dat = ("data", "LO_allElec_PC_Demand_old.csv")
elif mod_est is True:
dmd_bl_dat = ("data", "test_update_bl.csv")
dmd_therm_dat, dmd_ntherm_dat, tmp_dat, pc_dmd_dat = (
("data", "test_update.csv") for n in range(4))
else:
dmd_bl_dat = ("data", "test_predict_bl.csv")
dmd_therm_dat, dmd_ntherm_dat, tmp_dat, pc_dmd_dat = (
("data", "test_predict.csv") for n in range(4))
# Set stored model data files
stored_dmd_bl = ("model_stored", "dmd_lo_allelec_b.pkl")
stored_dmd_therm = ("model_stored", "dmd_therm_lo_allelec_o.pkl")
stored_dmd_ntherm = ("model_stored", "dmd_ntherm_lo_allelec_o.pkl")
stored_tmp = ("model_stored", "tmp_lo_allelec_o.pkl")
stored_pc_dmd = ("model_stored", "pc_dmd_lo_allelec_o.pkl")
# Regression coefficients
self.coefs = ("data", "coefs_lo_elec_o.csv")
# Big box retail, 2004 vintage
elif bldg_type_vint == "bigboxretail":
if mod_init is True or (mod_assess is True and mod_est is False):
dmd_bl_dat = ("data", "SR_B.csv") # ***** UPDATE *****
dmd_therm_dat = ("data", "BBR_Thermal_Demand_new.csv")
dmd_ntherm_dat = ("data", "BBR_Nonthermal_Demand_new.csv")
tmp_dat = ("data", "BBR_Temperature_new.csv")
pc_dmd_dat = ("data", "BBR_PC_Demand_new.csv")
elif mod_est is True:
dmd_bl_dat = ("data", "test_update_bl.csv")
dmd_therm_dat, dmd_ntherm_dat, tmp_dat, pc_dmd_dat = (
("data", "test_update.csv") for n in range(4))
else:
dmd_bl_dat = ("data", "test_predict_bl.csv")
dmd_therm_dat, dmd_ntherm_dat, tmp_dat, pc_dmd_dat = (
("data", "test_predict.csv") for n in range(4))
# Set stored model data files
stored_dmd_bl = ("model_stored", "dmd_bbr_b.pkl")
stored_dmd_therm = ("model_stored", "dmd_therm_bbr_n.pkl")
stored_dmd_ntherm = ("model_stored", "dmd_ntherm_bbr_n.pkl")
stored_tmp = ("model_stored", "tmp_bbr_n.pkl")
stored_pc_dmd = ("model_stored", "pc_dmd_bbr_n.pkl")
# Regression coefficients
self.coefs = ("data", "coefs_bbr_n.csv")
# Set DCE input/output file names
dce_dat = ("data", "dce_dat.csv")
stored_dce = ("model_stored", "dce.pkl")
# Set data input file column names and data types for model
# initialization; these are different by model type (though the same
# for the temperature and demand models, which draw from the same CSV)
if mod_init is True or (mod_assess is True and mod_est is False):
dmd_bl_names_dtypes = [
('id', 'vintage', 'day_typ', 'hour_number', 'climate',
'dmd_sf', 't_out', 'rh_out', 'occ_frac',
'v1980', 'v2004', 'v2010', 'v19802004',
'cz_2A', 'cz_2B', 'cz_3A', 'cz_3B', 'cz_3C',
'cz_4A', 'cz_4B', 'cz_4C', 'cz_5A', 'cz_5B',
'cz_6A', 'cz_6B', 'cz_7A'),
(['<i4'] * 4 + ['<U25'] + ['<f8'] * 4 + ['<i4'] * 17)]
dmd_tmp_names_dtypes, dmd_ntmp_names_dtypes = ([
('vintage', 'climate', 'hour', 't_out', 'rh_out', 'occ_frac',
'dmd_delt_sf', 't_in_delt', 'rh_in_delt', 'lt_pwr_delt_pct',
'mels_delt_pct', 'tsp_delt', 'tsp_delt_lag',
'hrs_since_dr_st', 'hrs_since_dr_end', 'pc_tmp_inc',
'pc_length', 'hrs_since_pc_st', 'hrs_since_pc_end'),
(['<i4'] + ['<U25'] + ['<i4'] + ['<f8'] * 16)] for
n in range(2))
self.coef_names_dtypes = [
('demand_bl', 'demand_therm', 'demand_ntherm', 'temperature',
'demand_precool'), (['<f8'] * 5)]
# Set data input file column names and data types for model
# re-estimation; these will be the same across models
elif mod_est is True:
dmd_bl_names_dtypes = [
('id', 'vintage', 'day_typ', 'day_num', 'hour_number',
'climate', 'dmd_sf', 't_out', 'rh_out', 'occ_frac',
'v1980', 'v2004', 'v2010', 'v19802004',
'cz_2A', 'cz_2B', 'cz_3A', 'cz_3B', 'cz_3C',
'cz_4A', 'cz_4B', 'cz_4C', 'cz_5A', 'cz_5B',
'cz_6A', 'cz_6B', 'cz_7A'),
(['<i4'] * 5 + ['<U25'] + ['<f8'] * 4 + ['<i4'] * 17)]
dmd_tmp_names_dtypes, dmd_ntmp_names_dtypes = ([
('vintage', 'climate', 'hour', 't_out', 'rh_out', 'occ_frac',
'dmd_delt_sf', 't_in_delt', 'rh_in_delt', 'lt_pwr_delt_pct',
'mels_delt_pct', 'tsp_delt', 'tsp_delt_lag',
'hrs_since_dr_st', 'hrs_since_dr_end', 'pc_tmp_inc',
'pc_length', 'hrs_since_pc_st', 'hrs_since_pc_end'),
(['<i4'] + ['<U25'] + ['<i4'] + ['<f8'] * 16)] for
n in range(2))
self.coef_names_dtypes = [
('demand_bl', 'demand_therm', 'demand_ntherm', 'temperature',
'demand_precool'), (['<f8'] * 5)]
# Set data input file column names and data types for model
# prediction; these will be the same across models
else:
dmd_bl_names_dtypes = [
('Hr', 'vintage', 'hour_number', 'climate',
't_out', 'rh_out', 'occ_frac',
'v1980', 'v2004', 'v2010', 'v19802004',
'cz_2A', 'cz_2B', 'cz_3A', 'cz_3B', 'cz_3C',
'cz_4A', 'cz_4B', 'cz_4C', 'cz_5A', 'cz_5B',
'cz_6A', 'cz_6B', 'cz_7A'),
(['<i4'] + ['<f8'] + ['<i4'] + ['<U25'] + ['<f8'] * 3 +
['<i4'] * 17)]
dmd_tmp_names_dtypes, dmd_ntmp_names_dtypes = ([(
'Name', 'Hr', 't_out', 'rh_out', 'lt_nat',
'base_lt_frac', 'occ_frac', 'delt_price_kwh',
'hrs_since_dr_st',
'hrs_since_dr_end', 'hrs_since_pc_st',
'hrs_since_pc_end', 'tsp_delt', 'lt_pwr_delt_pct',
'ven_delt_pct', 'mels_delt_pct', 'tsp_delt_lag',
'lt_pwr_delt_pct_lag', 'ven_delt_pct_lag',
'mels_delt_pct_lag', 'pc_tmp_inc', 'pc_length',
'lt_pwr_delt'),
(['<U50'] + ['<f8'] * 22)] for n in range(2))
self.coef_names_dtypes = [
('demand_bl', 'demand_therm', 'demand_ntherm', 'temperature',
'demand_precool'), (['<f8'] * 5)]
# Set DCE model column names and data types
# dce_names_dtypes = [(
# 'economy', 'pc_tmp', 'tmp', 'lgt', 'daylt', 'choice', 'plug'),
# (['<f8'] * 7)]
dce_names_dtypes = [(
'economy', 'pc_tmp_high', 'pc_tmp_low', 'tmp', 'lgt', 'daylt',
'choice', 'plug'), (['<f8'] * 8)]
# For each model type, store information on input/output data file
# names, input/output data file formats, model variables, and
# diagnostic assessment figure file names
self.mod_dict = {
"demand_bl": {
"io_data": [dmd_bl_dat, stored_dmd_bl],
"io_data_names": dmd_bl_names_dtypes,
"var_names": ['dmd_bl_params', 'dmd_bl_sd',
'Baseline Demand (W/sf)'],
"fig_names": [
"traceplots_dmd_bl.png", "postplots_dmd_bl.png",
"ppcheck_dmd_bl.png", "scatter_dmd_bl.png",
"update_dmd_bl.png"]
},
"demand_therm": {
"io_data": [dmd_therm_dat, stored_dmd_therm],
"io_data_names": dmd_tmp_names_dtypes,
"var_names": [
'dmd_therm_params', 'dmd_therm_sd',
'Demand Change (W/sf)'],
"fig_names": [
"traceplots_dmd_therm.png", "postplots_dmd_therm.png",
"ppcheck_dmd_therm.png", "scatter_dmd_therm.png",
"update_dmd_therm.png"]
},
"demand_ntherm": {
"io_data": [dmd_ntherm_dat, stored_dmd_ntherm],
"io_data_names": dmd_ntmp_names_dtypes,
"var_names": [
'dmd_ntherm_params', 'dmd_ntherm_sd',
'Demand Change (W/sf)'],
"fig_names": [
"traceplots_dmd_ntherm.png", "postplots_dmd_ntherm.png",
"ppcheck_dmd_ntherm.png", "scatter_dmd_ntherm.png",
"update_dmd_ntherm.png"]
},
"temperature": {
"io_data": [tmp_dat, stored_tmp],
"io_data_names": dmd_tmp_names_dtypes,
"var_names": [
'ta_params', 'ta_sd',
'Temperature Change (ºF)'],
"fig_names": [
"traceplots_tmp.png", "postplots_tmp.png",
"ppcheck_tmp.png", "scatter_tmp.png",
"update_tmp.png"]
},
"demand_precool": {
"io_data": [pc_dmd_dat, stored_pc_dmd],
"io_data_names": dmd_tmp_names_dtypes,
"var_names": [
'dmd_pc_params', 'dmd_pc_sd',
'Demand Change (W/sf)'],
"fig_names": [
"traceplots_dmd_pc.png", "postplots_dmd_pc.png",
"ppcheck_dmd_pc.png", "scatter_dmd_pc.png",
"update_dmd_pc.png"]
},
"choice": {
"io_data": [dce_dat, stored_dce],
"io_data_names": dce_names_dtypes,
"var_names": ['dce_params', 'dce_sd', 'dce'],
"fig_names": ["traceplots_dce.png", "postplots_dce.png"]
}
}
self.predict_out = ("data", "recommendations.json")
class ModelDataLoad(object):
"""Load the data files needed to initialize, estimate, or run models.
Attributes:
dmd_therm (numpy ndarray): Input data for thermal demand
model initialization.
dmd_ntherm (numpy ndarray): Input data for non-thermal demand
model initialization.
tmp (numpy ndarray): Input data for temperature model initialization.
pc_dmd (numpy ndarray): Input data for pre-cooling demand model init.
coefs (tuple): Path to CSV file with regression coefficients for
use in model re-estimation.
strategy (numpy ndarray): Strategies covered by prediction input data
strategy_orig (numpy ndarray): Strategies covered by prediction input
data before screening for invalid input conditions.
hr (numpy ndarray): Hours covered by DR model prediction input data.
hr_orig (numpy ndarray): Covered hours before screening DR prediction
data for invalid input conditions.
hr_bl (numpy.ndarray): Hours covered by the baseline model prediction
data.
tmp_delt (numpy ndarray): Data used to determine whether
a measure changes the thermostat set point in a current hour.
tmp_delt_prev (numpy ndarray): Data used to determine whether
a measure changed the thermostat set point in a previous hour.
lgt_delt (numpy ndarray): Data used to determine whether
a measure changes the lighting setting in a current hour.
plug_delt (numpy ndarray): Plug load adjustment fractions by DR
strategy for use in model prediction.
pc_mag (numpy.array): Precooling magnitude assoc. with each strategy.
oaf_delt (numpy ndarray): Outdoor air adjustment fractions by DR
strategy for use in model prediction.
price_delt (numpy ndarray): $/kWh incentive by DR strategy for use
in model prediction.
"""
def __init__(self, handyfilesvars, mod_init, mod_assess,
mod_est, update_days):
"""Initialize class attributes."""
# Initialize OAF delta, plug load delta and price delta as None
self.coefs, self.oaf_delt, self.plug_delt, self.lgt_delt, \
self.price_delt = (None for n in range(5))
# Data read-in for model initialization is specific to each type
# of model (though demand/temperature share the same input data);
if mod_init is True or (mod_assess is True and mod_est is False):
# Read in data for initializing baseline demand model
self.dmd_bl = np.genfromtxt(
path.join(base_dir,
*handyfilesvars.mod_dict[
"demand_bl"]["io_data"][0]),
skip_header=True, delimiter=',',
names=handyfilesvars.mod_dict[
"demand_bl"]["io_data_names"][0],
dtype=handyfilesvars.mod_dict[
"demand_bl"]["io_data_names"][1])
# Read in data for initializing thermal demand model
self.dmd_therm = np.genfromtxt(
path.join(base_dir,
*handyfilesvars.mod_dict[
"demand_therm"]["io_data"][0]),
skip_header=True, delimiter=',',
names=handyfilesvars.mod_dict[
"demand_therm"]["io_data_names"][0],
dtype=handyfilesvars.mod_dict[
"demand_therm"]["io_data_names"][1])
# Read in data for initializing non-thermal demand model
self.dmd_ntherm = np.genfromtxt(
path.join(base_dir,
*handyfilesvars.mod_dict[
"demand_ntherm"]["io_data"][0]),
skip_header=True, delimiter=',',
names=handyfilesvars.mod_dict[
"demand_ntherm"]["io_data_names"][0],
dtype=handyfilesvars.mod_dict[
"demand_ntherm"]["io_data_names"][1])
# Read in data for initializing temperature model
self.tmp = np.genfromtxt(
path.join(base_dir,
*handyfilesvars.mod_dict[
"temperature"]["io_data"][0]),
skip_header=True, delimiter=',',
names=handyfilesvars.mod_dict[
"temperature"]["io_data_names"][0],
dtype=handyfilesvars.mod_dict[
"temperature"]["io_data_names"][1])
# Read in data for initializing demand pre-cool model
self.pc_dmd = np.genfromtxt(
path.join(base_dir,
*handyfilesvars.mod_dict[
"demand_precool"]["io_data"][0]),
skip_header=True, delimiter=',',
names=handyfilesvars.mod_dict[
"demand_precool"]["io_data_names"][0],
dtype=handyfilesvars.mod_dict[
"demand_precool"]["io_data_names"][1])
# Read in data for initializing choice model
self.choice = np.genfromtxt(
path.join(base_dir, *handyfilesvars.mod_dict[
"choice"]["io_data"][0]),
skip_header=True, delimiter=',',
names=handyfilesvars.mod_dict[
"choice"]["io_data_names"][0],
dtype=handyfilesvars.mod_dict[
"choice"]["io_data_names"][1])
# Stop routine if files were not properly read in
if any([len(x) == 0 for x in [
self.dmd_bl, self.dmd_therm, self.dmd_ntherm, self.tmp,
self.pc_dmd, self.choice]]):
raise ValueError("Failure to read input file(s)")
# Read in reference frequentist coefs to compare Bayesian estimates
# against
self.coefs = np.genfromtxt(
path.join(base_dir, *handyfilesvars.coefs),
skip_header=True, delimiter=',',
names=handyfilesvars.coef_names_dtypes[0],
dtype=handyfilesvars.coef_names_dtypes[1])
# Data read-in for model re-estimation/prediction is common across
# model types
else:
# Read in data for baseline demand model
dmd_bl = np.genfromtxt(
path.join(base_dir,
*handyfilesvars.mod_dict[
"demand_bl"]["io_data"][0]),
skip_header=True, delimiter=',',
names=handyfilesvars.mod_dict[
"demand_bl"]["io_data_names"][0],
dtype=handyfilesvars.mod_dict[
"demand_bl"]["io_data_names"][1])
# Read in data for other DR model types
common_data = np.genfromtxt(
path.join(base_dir,
*handyfilesvars.mod_dict[
"demand_therm"]["io_data"][0]),
skip_header=True, delimiter=',',
names=handyfilesvars.mod_dict[
"demand_therm"]["io_data_names"][0],
dtype=handyfilesvars.mod_dict[
"demand_therm"]["io_data_names"][1])
# Restrict prediction input file to appropriate prediction or
# model estimation update data (if applicable)
if mod_est is False:
# Set inputs to baseline demand model
# from prediction/estimation input files
self.dmd_bl = dmd_bl
self.hr_bl = dmd_bl['Hr']
# Screen precooling or temperature-related strategies
# (indicated by a set point change or lagged set point change
# that is non-zero) for OAT <= 70
screened_strats = np.unique(
common_data[np.where((
(common_data['tsp_delt'] != 0) |
(common_data['tsp_delt_lag'] != 0)) &
(common_data['t_out'] <= 70))]['Name'])
# Post-screening data to use for predictions
common_data_screened = common_data[
np.isin(common_data['Name'], screened_strats, invert=True)]
# Pull out key variables from screened data as class attributes
self.tmp_delt = common_data_screened['tsp_delt']
self.tmp_delt_prev = common_data_screened['tsp_delt_lag']
self.lgt_delt = common_data_screened['lt_pwr_delt_pct']
self.plug_delt = common_data_screened['mels_delt_pct']
self.pc_mag = common_data_screened['pc_tmp_inc']
self.hr = common_data_screened['Hr']
self.hr_orig = common_data['Hr']
self.strategy = common_data_screened['Name']
self.strategy_orig = common_data['Name']
self.price_delt = common_data_screened['delt_price_kwh']
# Set inputs to demand, temperature, lighting, and
# pre-cooling models from screened prediction input files
self.dmd_therm, self.dmd_ntherm, self.tmp, \
self.pc_dmd = (common_data_screened for n in range(4))
elif mod_est is True:
# Set inputs to demand, temperature, co2, lighting, and
# pre-cooling models from prediction/estimation input files
# Note: DR period data are flagged by rows where the set point
# temperature change is greater than or equal to zero
self.dmd_bl = dmd_bl
# DR thermal demand data; set point change is positive or lag
# set point change is negative (first hour of rebound)
self.dmd_therm = common_data[
np.where((common_data['tsp_delt'] > 0) |
(common_data['tsp_delt_lag'] < 0) &
(common_data['t_out'] > 70))]
# DR temp. data; set point change is positive
self.tmp = common_data[np.where(
(common_data['tsp_delt'] > 0) &
(common_data['t_out'] > 70))]
# DR non-thermal data; set point change and lagged set point
# change are both zero
self.dmd_ntherm = common_data[
np.where((common_data['tsp_delt'] == 0) &
(common_data['tsp_delt_lag'] == 0) & (
(common_data['lt_pwr_delt_pct'] != 0) |
(common_data['mels_delt_pct'] != 0)))]
# Precooling data; set point change is negative
self.pc_dmd = common_data[
np.where(
(common_data['tsp_delt'] < 0) &
(common_data['t_out'] > 70) &
(common_data['occ_frac'] > 0))]
# Read in reference frequentist coefs. to compare Bayesian
# estimates against
self.coefs = np.genfromtxt(
path.join(base_dir, *handyfilesvars.coefs),
skip_header=True, delimiter=',',
names=handyfilesvars.coef_names_dtypes[0],
dtype=handyfilesvars.coef_names_dtypes[1])
# Initialize attributes related to prediction mode to zero
self.tmp_delt, self.tmp_delt_prev, self.lgt_delt, \
self.plug_delt, self.pc_mag, self.hr, \
self.hr_orig, self.strategy, self.strategy_orig, \
self.price_delt, self.hr_bl = (None for n in range(11))
# When not initializing or assessing a model, choice model
# attribute is irrelevant
self.choice = None
class ModelIO(object):
"""Initialize input/output variables/data structure for each model
Attributes:
train_inds (numpy ndarray): Indices to use in restricting data for
use in model training.
test_inds (numpy ndarray): Indices to use in restricting data for
use in model testing.
X_all (numpy ndarray): Model input observations.
Y_all (numpy ndarray): Model output observations.
"""
def __init__(
self, handyfilesvars, mod_init, mod_est, mod_assess, mod, data,
bldg_type_vint):
"""Initialize class attributes."""
# If model is being initialized and model assessment is requested,
# set the portion of the data that should be used across models for
# training vs. testing each model
if (mod_init is True and mod_assess is True) or mod_assess is True:
train_pct = 0.7
else:
train_pct = None
if mod == "demand_bl":
# If model is being initialized and model assessment is requested,
# or previously initialized model is being assessed,
# set training/testing indices to use on the demand_bl. data
if (mod_init is True and mod_assess is True) or mod_assess is True:
# Set training indices
self.train_inds = np.random.randint(
0, len(data.dmd_bl),
size=int(len(data.dmd_bl) * train_pct))
# Set testing indices
self.test_inds = [
x for x in range(len(data.dmd_bl)) if
x not in self.train_inds]
# Initialize variables for baseline demand model
# Whole building occupancy fraction
occ_frac = data.dmd_bl['occ_frac']
# Outdoor air temperature
temp_out = data.dmd_bl['t_out']
# Outdoor relative humidity
rh_out = data.dmd_bl['rh_out']
# Number of hour
hour_number = data.dmd_bl['hour_number']
# # Climate zones
# climate_zone = data.dmd_bl['climate']
# # Vintages
# vintage = data.dmd_bl['vintage']
# Set a vector of ones for intercept estimation
intercept = np.ones(len(occ_frac))
# Categorical variables for Climate zones
# cz_2A = data.dmd_bl['cz_2A']
cz_2B = data.dmd_bl['cz_2B']
cz_3A = data.dmd_bl['cz_3A']
cz_3B = data.dmd_bl['cz_3B']
cz_3C = data.dmd_bl['cz_3C']
cz_4A = data.dmd_bl['cz_4A']
cz_4B = data.dmd_bl['cz_4B']
cz_4C = data.dmd_bl['cz_4C']
cz_5A = data.dmd_bl['cz_5A']
cz_5B = data.dmd_bl['cz_5B']
cz_6A = data.dmd_bl['cz_6A']
cz_6B = data.dmd_bl['cz_6B']
cz_7A = data.dmd_bl['cz_7A']
# Categorical variables for Vintages
# v_1980 = data.dmd_bl['v1980']
v_2004 = data.dmd_bl['v2004']
v_2010 = data.dmd_bl['v2010']
v_19802004 = data.dmd_bl['v19802004']
# Outdoor temperature, outdoor relative humidity
tmp_out_rh_out = temp_out * rh_out
# Set model input (X) variables
self.X_all = np.stack([
intercept, temp_out, rh_out,
v_19802004, v_2004, v_2010,
cz_2B, cz_3A, cz_3B, cz_3C, cz_4A, cz_4B,
cz_4C, cz_5A, cz_5B, cz_6A, cz_6B, cz_7A,
occ_frac, hour_number, tmp_out_rh_out], axis=1)
# Set model output (Y) variable for estimation cases
if mod_init is True or mod_est is True or mod_assess is True:
self.Y_all = data.dmd_bl['dmd_sf']
elif mod == "demand_therm":
# If model is being initialized and model assessment is requested,
# or previously initialized model is being assessed,
# set training/testing indices to use on the demand/temp. data
if (mod_init is True and mod_assess is True) or mod_assess is True:
# Set training indices
# self.train_inds = np.random.randint(
# 0, len(data.dmd_therm),
# size=int(len(data.dmd_therm) * train_pct))
# # Set testing indices
# self.test_inds = [
# x for x in range(len(data.dmd_therm)) if
# x not in self.train_inds]
self.train_inds, self.test_inds = list(
range(len(data.dmd_therm)) for n in range(2))
# Initialize variables for temperature and demand models
# Whole building occupancy fraction
occ_frac = data.dmd_therm['occ_frac']
# Outdoor air temperature
temp_out = data.dmd_therm['t_out']
# Outdoor relative humidity
rh_out = data.dmd_therm['rh_out']
# Temperature set point difference
tmp_delta = data.dmd_therm['tsp_delt']
# Temperature set point difference lag
tmp_delta_lag = data.dmd_therm['tsp_delt_lag']
# Hours since DR event started (adjustment to normal op. condition)
dr_start = data.dmd_therm['hrs_since_dr_st']
# Hours since DR event ended (adjustment to normal op. condition)
dr_end = data.dmd_therm['hrs_since_dr_end']
# Lighting fraction reduction
lt_delta = data.dmd_therm['lt_pwr_delt_pct']
# Plug load power fraction reduction
plug_delta = data.dmd_therm['mels_delt_pct']
# Set a vector of ones for intercept estimation
intercept = np.ones(len(tmp_delta))
# Initialize interactive terms
# Cooling SP/OAT interaction
tmp_delt_tmp_out = tmp_delta * temp_out
# Cooling SP/occupancy interaction
tmp_delt_occ_frac = tmp_delta * occ_frac
# Cooling SP/occupancy interaction
tmp_delt_dr_start = tmp_delta * dr_start
# Set model input (X) variables
# In this model, the MELs input is dropped for retail
if bldg_type_vint not in [
"stdaloneretailnew", "stdaloneretailold", "bigboxretail"]:
self.X_all = np.stack([
intercept, temp_out, rh_out, occ_frac, tmp_delta, lt_delta,
plug_delta, dr_start, dr_end, tmp_delta_lag,
tmp_delt_tmp_out, tmp_delt_occ_frac, tmp_delt_dr_start],
axis=1)
else:
self.X_all = np.stack([
intercept, temp_out, rh_out, occ_frac, tmp_delta, lt_delta,
dr_start, dr_end, tmp_delta_lag, tmp_delt_tmp_out,
tmp_delt_occ_frac, tmp_delt_dr_start],
axis=1)
# Set model output (Y) variable for estimation cases
if mod_init is True or mod_est is True or mod_assess is True:
self.Y_all = data.dmd_therm['dmd_delt_sf']
elif mod == "demand_ntherm":
# If model is being initialized and model assessment is requested,
# or previously initialized model is being assessed,
# set training/testing indices to use on the demand/temp. data
if (mod_init is True and mod_assess is True) or mod_assess is True:
# Set training indices
# self.train_inds = np.random.randint(
# 0, len(data.dmd_ntherm),
# size=int(len(data.dmd_ntherm) * train_pct))
# # Set testing indices
# self.test_inds = [
# x for x in range(len(data.dmd_ntherm)) if
# x not in self.train_inds]
self.train_inds, self.test_inds = list(
range(len(data.dmd_ntherm)) for n in range(2))
# Initialize variables for non-thermal demand model
# Lighting fraction reduction
lt_delta = data.dmd_ntherm['lt_pwr_delt_pct']
# Plug load power fraction reduction
plug_delta = data.dmd_ntherm['mels_delt_pct']
# Set a vector of ones for intercept estimation
intercept = np.ones(len(lt_delta))
# Set model input (X) variables
# In this model, the MELs input is dropped for retail
if bldg_type_vint not in [
"stdaloneretailnew", "stdaloneretailold", "bigboxretail"]:
self.X_all = np.stack([
intercept, lt_delta, plug_delta], axis=1)
else:
self.X_all = np.stack([
intercept, lt_delta], axis=1)
# Set model output (Y) variable for estimation cases
if mod_init is True or mod_est is True or mod_assess is True:
self.Y_all = data.dmd_ntherm['dmd_delt_sf']
elif mod == "temperature":
# If model is being initialized and model assessment is requested,
# or previously initialized model is being assessed,
# set training/testing indices to use on the demand/temp. data
if (mod_init is True and mod_assess is True) or mod_assess is True:
# Set training indices
# self.train_inds = np.random.randint(
# 0, len(data.tmp),
# size=int(len(data.tmp) * train_pct))
# # Set testing indices
# self.test_inds = [
# x for x in range(len(data.tmp)) if
# x not in self.train_inds]
self.train_inds, self.test_inds = list(
range(len(data.tmp)) for n in range(2))
# Initialize variables for temperature and demand models
# Whole building occupancy fraction
occ_frac = data.tmp['occ_frac']
# Outdoor air temperature
temp_out = data.tmp['t_out']
# Outdoor relative humidity
rh_out = data.tmp['rh_out']
# Temperature set point difference
tmp_delta = data.tmp['tsp_delt']
# Temperature set point difference lag
tmp_delta_lag = data.tmp['tsp_delt_lag']
# Hours since DR event started (adjustment to normal op. condition)
dr_start = data.tmp['hrs_since_dr_st']
# Hours since pre-cooling ended (if applicable)
pcool_duration = data.tmp['pc_length']
# Magnitude of pre-cooling temperature offset
pcool_magnitude = data.tmp['pc_tmp_inc']
# Set a vector of ones for intercept estimation
intercept = np.ones(len(tmp_delta))
# Initialize interactive terms
# Pre-cool duration, and magnitude
pcool_interact = pcool_duration * pcool_magnitude
# Cooling SP/OAT interaction
tmp_delt_tmp_out = tmp_delta * temp_out
# Cooling SP/occupancy interaction
tmp_delt_occ_frac = tmp_delta * occ_frac
# Cooling SP/occupancy interaction
tmp_delt_dr_start = tmp_delta * dr_start
# Set model input (X) variables
self.X_all = np.stack([
intercept, temp_out, rh_out, occ_frac, tmp_delta,
dr_start, tmp_delta_lag, pcool_magnitude, pcool_duration,
tmp_delt_tmp_out, tmp_delt_occ_frac, tmp_delt_dr_start,
pcool_interact], axis=1)
# Set model output (Y) variable for estimation cases
if mod_init is True or mod_est is True or mod_assess is True:
self.Y_all = data.tmp['t_in_delt']
elif mod == "demand_precool":
# If model is being initialized and model assessment is requested,
# or previously initialized model is being assessed,
# set training/testing indices to use on the demand/temp. data
if (mod_init is True and mod_assess is True) or mod_assess is True:
# Set training indices
# self.train_inds = np.random.randint(
# 0, len(data.pc_dmd),
# size=int(len(data.pc_dmd) * train_pct))
# # Set testing indices
# self.test_inds = [
# x for x in range(len(data.pc_dmd)) if
# x not in self.train_inds]
self.train_inds, self.test_inds = list(
range(len(data.pc_dmd)) for n in range(2))
# Initialize variables for temp/demand pre-cooling models
# Whole building occupancy fraction
occ_frac = data.pc_dmd['occ_frac']
# Outdoor air temperature
temp_out = data.pc_dmd['t_out']
# Outdoor relative humidity
rh_out = data.pc_dmd['rh_out']
# Temperature set point difference
tmp_delta = data.pc_dmd['tsp_delt']
# Hours since pre-cooling started
pc_start = data.pc_dmd['hrs_since_pc_st']
# Cooling SP/OAT interaction
tmp_delt_tmp_out = tmp_delta * temp_out
# Cooling SP/occupancy interaction
tmp_delt_occ_frac = tmp_delta * occ_frac
# Cooling SP/occupancy interaction
tmp_delt_pc_start = tmp_delta * pc_start
# Set a vector of ones for intercept estimation
intercept = np.ones(len(tmp_delta))
# Set model input (X) variables
self.X_all = np.stack([
intercept, temp_out, rh_out, occ_frac, tmp_delta, pc_start,
tmp_delt_tmp_out, tmp_delt_occ_frac, tmp_delt_pc_start],
axis=1)
# Set model output (Y) variable for estimation cases
if mod_init is True or mod_est is True or mod_assess is True:
self.Y_all = data.pc_dmd['dmd_delt_sf']
# Initialize input/output variables for choice regression
elif mod == "choice":
# Set train/test data to all data in this case
self.train_inds, self.test_inds = ([
x for x in range(len(data.choice))] for n in range(2))
# Economic benefit
economy = data.choice['economy']
# # Pre-cooling temp. decrease
# pc_tmp = data.choice['pc_tmp']
# Pre-cooling temp. decrease (<=2 deg F event temp. increase)
pc_tmp_l = data.choice['pc_tmp_low']
# Pre-cooling temp. decrease (>2 deg F event temp. increase)
pc_tmp_h = data.choice['pc_tmp_high']
# Temp. increase
tmp = data.choice['tmp']
# Lighting decrease
lgt = data.choice['lgt']
# Daylighting
dl = data.choice['daylt']
# Daylighting multiplied by lgt
lgt_dl = lgt * dl
# Plug load decrease
plug = data.choice['plug']
# Set model input (X) variables; note, NO INTERCEPT
# self.X_all = np.stack([
# economy, pc_tmp, tmp, lgt, lgt_dl, plug], axis=1)
self.X_all = np.stack([
economy, pc_tmp_l, pc_tmp_h, tmp, lgt, lgt_dl, plug], axis=1)
# Set model output (Y) variable for estimation cases
self.Y_all = data.choice['choice']
class ModelIOTrain():
"""Pull subset of data observations for use in model training.
Attributes:
X (numpy ndarray): Input data subset to use for model training.
Y (numpy ndarray): Output data subset to use for model training.
"""
def __init__(self, io_dat, mod_init, mod_assess):
"""Initialize class attributes."""
# Only pull testing data subset for model initialization and/or
# assessment of previously initialized model; otherwise
# use all the available data for testing
if (mod_init is True and mod_assess is True) or mod_assess is True:
self.X = io_dat.X_all[io_dat.train_inds]
self.Y = io_dat.Y_all[io_dat.train_inds]
else:
self.X = io_dat.X_all
self.Y = io_dat.Y_all
class ModelIOTest():
"""Pull subset of data observations for use in model testing.
Attributes:
X (numpy ndarray): Input data subset to use for model testing.
Y (numpy ndarray): Output data subset to use for model testing.
"""
def __init__(self, io_dat, mod_init, mod_assess):
"""Initialize class attributes."""
# Only pull testing data subset for model initialization and/or
# assessment of previously initialized model; otherwise
# use all the available data for testing
if mod_init is True or mod_assess is True:
self.X = io_dat.X_all[io_dat.test_inds]
self.Y = io_dat.Y_all[io_dat.test_inds]
else:
self.X = io_dat.X_all