-
Notifications
You must be signed in to change notification settings - Fork 1
/
Housing_Class1.py
1256 lines (1086 loc) · 50.1 KB
/
Housing_Class1.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
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 27 05:36:53 2017
@author: shubaraghavan
"""
from Appliances_Class import *
from Inputs_Energy import *
import CAISO
from CAISO.mapping.py import *
import copy
# from AnnualHeatDemand import AnnualEngDemand
# import xlrd
# import xlsxwriter
import numpy as np
# import seaborn as sns
# from matplotlib.pyplot import cm
# import matplotlib.pyplot as plt
from matplotlib.pyplot import *
# import matplotlib.patches as mpatch
import csv
import pandas as pd
import datetime
def binomial_draw(p, n=1, N=1):
s = sum(np.random.binomial(n, p, N) == 1) / N
return s
# print binomial_draw(0.9)
def remove_device(devlist, thisdevice, devicename):
for dd in devlist:
if dd != thisdevice and devicename in dd.name:
devlist.remove(dd)
"""List of 16 dictionaries, each corresponding to a dictionary. Each dictionary maps
a tuple of year and end-use to a list of total energy usage for all hours"""
days_in_months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
months = {"Jan": 0,
"Feb": 1,
"Mar": 2,
"Apr": 3,
"May": 4,
"Jun": 5,
"Jul": 6,
"Aug": 7,
"Sep": 8,
"Oct": 9,
"Nov": 10,
"Dec": 11}
seasons = {"Winter": ("Jan", "Feb"),
"Spring": ("Mar", "May"),
"Summer": ("Jun", "Aug"),
"Fall": ("Sep", "Nov")}
class HouseType:
hourly_energy = [{} for x in range(16)]
def __init__(self, type, HouseNum, cznum, size1, size2, vintage, devices, is_new=False):
self.type = type # SingleFam, Multi_Fam, apt, mobile
self.HouseNum = HouseNum
self.cznum = cznum
self.size1 = size1 # surface area of the walls
self.size2 = size2 # surface area of the roof
self.vintage = vintage
self.devices = devices # device class
self.end_uses = [device.name for device in self.devices]
self.year_dict = {}
self.is_new = is_new # boolean
#if self.devices[0].vintage <= 2007:
# pp = binomial_draw(0.1)
# if pp ==0:
# self.versionId = 1
# self.vintage = 2005
# elif pp == 1:
# self.versionId =2
# self.vintage = 1990
# elif self.vintage > 2007:
# self.versionId = 3
# self.deviceCnt = deviceCnt
# def HHCountWithdevice(self, devicetype):
class Day:
def __init__(self, datetime, season, use):
self.season = season
# self.weekday = "weekday"
self.datetime = datetime
self.use = use
self.dayuse = sum(self.use)
"""
def set_season(self, season):
self.season = season
def set_day(self, weekday):
self.weekday = weekday
"""
def create_year_dict(self, year):
for end_use in self.end_uses:
self.year_dict[end_use] = self.create_year(self.cznum, year, end_use)
def create_year(self, cznum, year, end_use):
daylist = []
use = []
curr_datetime = datetime.datetime(year, 1, 1)
usage = HouseType.hourly_energy[cznum - 1][year, end_use]
for i in range(len(usage)):
use.append(usage[i])
if (i + 1) % 24 == 0:
if 6 <= curr_datetime.month <= 9:
season = "summer"
else:
season = "winter"
daylist.append(HouseType.Day(curr_datetime, season, use))
use = []
curr_datetime = curr_datetime + datetime.timedelta(days=1)
return daylist
"""Calculates yearly price for a house based on a given method. TODO: SHOULD WE MAKE CODE
CLEANER BY DEFINING THE FLAT AND TIER RATES AS CLASS ATTRIBUTES?
I THOUGHT ABOUT IT, BUT DOES NOT REALLY MAKE SENSE AS A TRAIT OF A SINGLE HOUSE"""
def yearly_cost(self, method, flat_rate=0.19, baseline=15, tier1=0.22376, tier2=0.28159, tier3=0.49334,
speak=0.25354, soffpeak=0.20657, wpeak=0.18022, woffpeak=0.17133):
if method == 'flat':
return self.flat(flat_rate)
elif method == 'tier':
return self.tier(baseline, tier1, tier2, tier3)
elif method == 'tou':
return self.tou(speak, soffpeak, wpeak, woffpeak)
"""Calculates price over a range of months for a house based on a given method."""
def cost_for_month_range(self, method, st_month, end_month, flat_rate=0.19, baseline=15, tier1=0.22376, tier2=0.28159, tier3=0.49334,
speak=0.25354, soffpeak=0.20657, wpeak=0.18022, woffpeak=0.17133):
if method == 'flat':
return self.flat_month(st_month, end_month)
elif method == 'tier':
return self.tier_month(st_month, end_month)
elif method == 'tou':
return self.tou_month(st_month, end_month)
def flat_month(self, st_month, end_month, price=0.19):
flat_use = {}
for end_use, daylist in self.year_dict.items():
parttotaluse = 0
for day in daylist:
if st_month <= day.datetime.month <= end_month:
parttotaluse = parttotaluse + day.dayuse
flat_use[end_use] = parttotaluse * price
flat_use["Total"] = sum(list(flat_use.values()))
return flat_use
def flat(self, price=0.19):
"""flat_use = {}
for end_use, daylist in self.year_dict.items():
parttotaluse = 0
for day in daylist:
#print(type(day))
parttotaluse = parttotaluse + day.dayuse
flat_use[end_use] = parttotaluse * price
flat_use["Total"] = sum(list(flat_use.values()))"""
return self.flat_month(1, 12, price)
"""TODO: DOUBLE-CHECK THIS IS THE CORRECT WAY TO CALCULATE MONTHLY TIERED PRICING.
I DID WHAT MAKES THE MOST LOGICAL SENSE"""
def tier_month(self, st_month, end_month, baseline=15, tier1=0.22376, tier2=0.28159, tier3=0.49334):
tiered_use = {}
for end_use in self.year_dict.keys():
daylist, totaluse, monthlyuse, i = self.year_dict[end_use], 0, [], 1
for day in daylist:
if day.datetime.month == i:
totaluse = totaluse + day.dayuse
continue
i += 1
monthlyuse.append(totaluse)
totaluse = 0 + day.dayuse
monthlyuse.append(totaluse) # Takes December into account
totalcost = 0
for i in range(st_month, end_month + 1):
totalcost = totalcost + min(baseline, monthlyuse[i-1]) * tier1 + max(0, monthlyuse[i-1] - baseline)\
* tier2 + max(0, monthlyuse[i-1] - 4*baseline) * tier3
tiered_use[end_use] = totalcost
tiered_use["Total"] = sum(list(tiered_use.values()))
return tiered_use
def tier(self, baseline=15, tier1=0.22376, tier2=0.28159, tier3=0.49334):
"""# https://www.pge.com/tariffs/assets/pdf/tariffbook/ELEC_SCHEDS_E-1.pdf
tiered_use = {}
for end_use in self.year_dict.keys():
daylist, totaluse, monthlyuse, i = self.year_dict[end_use], 0, [], 1
for day in daylist:
if day.datetime.month == i:
totaluse = totaluse + day.dayuse
continue
i += 1
monthlyuse.append(totaluse)
totaluse = 0 + day.dayuse
monthlyuse.append(totaluse) # Takes December into account
totalcost = 0
for month in monthlyuse:
totalcost = totalcost + min(baseline, month) * tier1 + max(0, min(month - baseline, 3 * baseline)) * tier2 + max(0, month - 4*baseline) * tier3
tiered_use[end_use] = totalcost
tiered_use["Total"] = sum(list(tiered_use.values()))"""
return self.tier_month(1, 12)
def tou_month(self, st_month, end_month, speak=0.25354, soffpeak=0.20657, wpeak=0.18022, woffpeak=0.17133):
tou_use = {}
for end_use in self.year_dict.keys():
speaksum, soffpeaksum, wpeaksum, woffpeaksum = 0, 0, 0, 0 #summer and winter peak/offpeak
daylist= self.year_dict[end_use]
for day in daylist: #Could make more efficient by a constant factor later if necessary
if st_month <= day.datetime.month <= end_month:
if day.season == "summer":
if day.datetime.weekday() < 5: # Checks for a weekend
speaksum = speaksum + sum(day.use[14:19]) # Peak hours are 3 PM - 8 PM
soffpeaksum = soffpeaksum + sum(day.use[:14]) + sum(day.use[19:])
else:
soffpeaksum = soffpeaksum + day.dayuse
else:
if day.datetime.weekday() < 5:
wpeaksum = wpeaksum + sum(day.use[14:19])
woffpeaksum = woffpeaksum + sum(day.use[:14]) + sum(day.use[19:])
else:
woffpeaksum = woffpeaksum + day.dayuse
end_use_price = speaksum * speak + soffpeaksum * soffpeak + wpeaksum * wpeak + woffpeaksum * woffpeak
tou_use[end_use] = end_use_price
tou_use["Total"] = sum(list(tou_use.values()))
return tou_use
def tou(self, speak=0.25354, soffpeak=0.20657, wpeak=0.18022, woffpeak=0.17133):
# https://www.pge.com/tariffs/assets/pdf/tariffbook/ELEC_SCHEDS_EL-TOU.pdf
"""tou_use = {}
for end_use in self.year_dict.keys():
speaksum, soffpeaksum, wpeaksum, woffpeaksum = 0, 0, 0, 0 #summer and winter peak/offpeak
daylist= self.year_dict[end_use]
for day in daylist:
if day.season == "summer":
if day.datetime.weekday() < 5: # Checks for a weekend
speaksum = speaksum + sum(day.use[14:19]) # Peak hours are 3 PM - 8 PM
soffpeaksum = soffpeaksum + sum(day.use[:14]) + sum(day.use[19:])
else:
soffpeaksum = soffpeaksum + day.dayuse
else:
if day.datetime.weekday() < 5:
wpeaksum = wpeaksum + sum(day.use[14:19])
woffpeaksum = woffpeaksum + sum(day.use[:14]) + sum(day.use[19:])
else:
woffpeaksum = woffpeaksum + day.dayuse
end_use_price = speaksum * speak + soffpeaksum * soffpeak + wpeaksum * wpeak + woffpeaksum * woffpeak
tou_use[end_use] = end_use_price
tou_use["Total"] = sum(list(tou_use.values()))"""
return self.tou_month(1, 12)
def update_dictionary(filename, year, end_use):
with open(filename, 'r') as csvfile:
read_csv = csv.reader(csvfile)
for cznum in range(16):
csvfile.seek(0)
first = True
HouseType.hourly_energy[cznum][(year, end_use)] = []
for row in read_csv:
if first:
first = False
continue
HouseType.hourly_energy[cznum][(year, end_use)].append(float(row[cznum + 1]))
def get_total_annual_emissions(self, year):
"""
Returns annual emissions including refrigerant leakage
"""
ref_leakage = 0
for device in self.devices:
ref_leakage += device.AvgRefLeaks(year)
return self.get_annual_emissions(year) + ref_leakage
def get_annual_emissions(self, year):
"""
Returns annual emissions NOT including refrigerant leakage
"""
total_annual_energy_usage = self.get_total_annual_usage(year)
return total_annual_energy_usage * ElecEmisYrly[year]
def get_annual_emissions_hourly(self):
result = {}
for end_use in self.end_uses:
total = 0
year_dict = self.year_dict[end_use]
for day in year_dict:
month = day.datetime.month
month_emissions = rates.iloc[month - 1]
counter = 0
for item in month_emissions.iteritems():
total += item[1] * day.use[counter]
counter += 1
result[end_use] = total
return result
def get_annual_emissions_per_enduse(self, year):
result = {}
annual_usage = self.get_annual_usage()
for end_use in self.end_uses:
result[end_use] = annual_usage[end_use] * ElecEmisYrly[year]
return result
def get_monthly_emissions(self, st_month, end_month, year):
total_monthly_energy_usage = sum(list(self.get_hourly_usage_for_months(st_month, end_month, year).values()))
return total_monthly_energy_usage * ElecEmisYrly[year]
def get_hourly_usage_for_year(self, year, end_use):
"""
Helper function to access the appropriate hourly usage for a particular cznum, year, and end use.
Returns a list of size 8760 with all the hourly energy usage.
"""
return HouseType.hourly_energy[self.cznum - 1][(year, end_use)]
# def get_annual_cost_base_price(self, year, end_uses, rate): REMOVED BECAUSE INTEGRATED AMY'S PRICING CODE
# annual_usage = self.get_total_annual_usage(year, end_uses)
# return annual_usage * rate
def get_total_annual_usage(self, year):
usages = self.get_annual_usage(year)
total = 0
for usage in usages.values():
total += usage
return total
def get_annual_usage(self, year):
result = {}
for end_use in self.end_uses:
result[end_use] = sum(self.get_hourly_usage_for_year(year, end_use))
return result
def get_hourly_usage_for_seasons(self, season, year,):
"""
Calculates the energy used for a particular season.
"""
st_month = seasons[season][0]
end_month = seasons[season][1]
return self.get_hourly_usage_for_months(st_month, end_month, year,)
def get_hourly_usage_for_months(self, st_month, end_month, year, st_hour=0, end_hour=23):
"""
Calculates the energy used for a particular month range.
st_month and end_month are strings containing the first 3 letters of the month.
st_hour and end_hour can be specified, but function defaults to calculating usage for the entire day.
"""
st_month_num = months[st_month]
end_month_num = months[end_month]
st_day = 0
for i in range(st_month_num):
st_day += days_in_months[i]
end_day = 0
for i in range(end_month_num + 1):
end_day += days_in_months[i]
end_day -= 1
# print(str(st_day) + " " + str(end_day))
return self.hour_range(st_hour, end_hour, st_day, end_day, year)
def get_peak_energy_usage_per_month(self, year):
"""
Gets the maximum energy usage and corresponding hour for each month
"""
result = {}
for end_use in self.end_uses:
current = self.get_hourly_usage_for_year(year, end_use)
month_usages = {}
curr_hour = 0
for i in range(12):
max_hour = curr_hour
max_energy = 0
for j in range(curr_hour, curr_hour + 24 * days_in_months[i]):
if current[j] > max_energy:
max_hour = j + 1
max_energy = current[j]
curr_hour = curr_hour + 24 * days_in_months[i]
month_usages[i + 1] = [max_hour, max_energy]
result[end_use] = month_usages
return result
def hour_range(self, st_hour, end_hour, st_day, end_day, year):
"""
Calculates the energy used for a particular time range across a day range.
Ex: st_hour = 10, end_hour = 18, st_day = 0, end_day = 30
Returns the total hourly energy used from 10 a.m. to 6 p.m. each day
from January 1st to January 31st.
"""
result = {}
for end_use in self.end_uses:
total = 0
hourly_usage_for_year = self.get_hourly_usage_for_year(year, end_use)
for i in range(st_day, end_day + 1):
for j in range(st_hour, end_hour + 1):
day_in_hours = i * 24
total += hourly_usage_for_year[day_in_hours + j]
# print(end_day * 24 + end_hour)
result[end_use] = total
return result
"""Function which returns hourly energy usage """
def hourly_usage(self, year, end_use, hour):
temp = (year, end_use) # Tuple of variables
return HouseType.hourly_energy[self.cznum][temp][hour - 1]
def HHenergyUsage_BTU(self): # outputs heating and cooling energy in BTUs
# num = self.deviceCnt
esumheat = 0
esumcool = 0
i = 0
num = len(self.devices)
NGswitch = 0
# print "TEST", num
for k in range(0, num):
if self.devices[k].name != "Cooler" and self.devices[k].name != "Cond":
i += 1
esumheat += self.devices[k].AnnualHeatEngUsage_BTU() # this does not contain Blower usage
# print "before", i, esumheat
if self.devices[k].fuel.name == "NG" and NGswitch == 0:
NGswitch = 1
if "WH" not in self.devices[k].name:
esumheat += NG_AnnualElecUsage * kWh_BTU # Adding blower usage
# print "I", i, self.devices[k].name, NG_AnnualElecUsage,esumheat, "\n"
if self.devices[k].name == "Cooler":
i += 1
esumcool += self.devices[k].AnnualCoolEngUsage_BTU()
# print "II", i, self.devices[k].name, esumcool , "\n"
if self.devices[k].name == "Cond":
i += 1
esumcool += self.devices[k].AnnualCoolEngUsage_BTU()
esumheat += self.devices[k].AnnualHeatEngUsage_BTU()
# print "III",i, self.devices[k].name, esumcool, esumheat , "\n"
return esumheat, esumcool # esumheat contains NG blower electric usage
def HHenergyUsage_BTU_withoutNGBlower(self): # outputs heating and cooling energy in BTUs
# num = self.deviceCnt
esumheat = 0
esumcool = 0
i = 0
num = len(self.devices)
# NGswitch = 0
# print "TEST", num
for k in range(0, num):
if self.devices[k].name != "Cooler" and self.devices[k].name != "Cond":
i += 1
esumheat += self.devices[k].AnnualHeatEngUsage_BTU() # this does not contain Blower usage
# print "before", i, esumheat
# if self.devices[k].fuel.name == "NG" and NGswitch == 0:
# NGswitch = 1
# if "WH" not in self.devices[k].name:
# esumheat += NG_AnnualElecUsage * kWh_BTU #Adding blower usage
# print "I", i, self.devices[k].name, NG_AnnualElecUsage,esumheat, "\n"
if self.devices[k].name == "Cooler":
i += 1
esumcool += self.devices[k].AnnualCoolEngUsage_BTU()
# print "II", i, self.devices[k].name, esumcool , "\n"
if self.devices[k].name == "Cond":
i += 1
esumcool += self.devices[k].AnnualCoolEngUsage_BTU()
esumheat += self.devices[k].AnnualHeatEngUsage_BTU()
# print "III",i, self.devices[k].name, esumcool, esumheat , "\n"
return esumheat, esumcool # esumheat contains NG blower electric usage
def HHenergyUsage_kWh(self): # total energy usage in a house in KWh
eng = self.HHenergyUsage_BTU()
X = eng[0] / kWh_BTU + eng[1] / kWh_BTU
# if (self.versionID == 1) return X*1.1:
return X
def HHenergyUsage_units(self): # actually this should HHenergyUsage_fueltype,
# outputs NG usage and Elec usage - the latter includes the electricity demand of NG Fan blower
num = len(self.devices) # BUT NOW output in kWh ..don't change it though...
esumNG = 0 # NG usage in kWh
esumElec = 0 # Elec usage in kWh
NGswitch = 0
# print "cnt", num, devices[0].fuel.name, devices[1].fuel.name,devices[2].fuel.name
for k in range(0, num):
# print "\n Name", self.devices[0].name
if self.devices[k].fuel.name == "NG" and NGswitch == 0: # to avoid double counting NG appliances
NGswitch = 1
NGEng = self.HHenergyUsage_BTU()[0] / kWh_BTU
NGEng = NGEng - NG_AnnualElecUsage
esumNG += NGEng # in kWh
if "WH" not in self.devices[k].name: # only for NG space heaters
esumElec += NG_AnnualElecUsage
# print "\n NG Eng",k, self.devices[k].name ,esumNG
elif self.devices[k].fuel.name == "Elec":
if self.devices[k].name != "Cooler" and self.devices[k].name != "Cond":
eheat = self.devices[k].AnnualHeatEngUsage_BTU() / kWh_BTU
esumElec += eheat
# print "\n heating Energy",k, self.devices[k].name, eheat
if self.devices[k].name == "Cooler":
ecool = self.devices[k].AnnualCoolEngUsage_BTU() / kWh_BTU
esumElec += ecool
# print "\n Cooling Energy", k, self.devices[k].name,ecool
if self.devices[k].name == "Cond":
ecool = self.devices[k].AnnualCoolEngUsage_BTU() / kWh_BTU
eheat = self.devices[k].AnnualHeatEngUsage_BTU() / kWh_BTU
esumElec += ecool + eheat
# print "\n Cond Energy", k,devices[k].name, ecool, eheat
return esumNG, esumElec
def HHemissions(self, year):
num = len(self.devices)
# print "num of devices", num
emisng = 0
emiselec = 0
refemis = 0
for k in range(0, num):
if self.devices[k].fuel.name == "Elec":
if self.devices[k].hasRefrigerant == True:
refemis += self.devices[k].AvgRefLeaks(year)
# print "\Iterate through device", self.type, self.devices[k].name, refemis
# print "\n ref yes/no", self.type,self.devices[k].fuel.name, self.devices[k].hasRefrigerant
NGeng = self.HHenergyUsage_units()[0] # this is in kWh
Eleceng = self.HHenergyUsage_units()[1]
# print "\n heat & cool eng", self.type,year, NGeng, Eleceng
emisng = (NGeng / Therm_kWh) * NGEmisYrly[year] / 1000
emiselec = Eleceng * ElecEmisYrly[year] / 1000
# print "\n HH EMissions", year, self.type, NGeng,Eleceng, emisng, emiselec, refemis
return emisng, emiselec + refemis # in metric tons
def HHemissions_refrig(self, year):
num = len(self.devices)
# print "num of devices", num
emisng = 0
emiselec = 0
refemis = 0
for k in range(0, num):
hdd = self.devices[k].HDD
cdd = self.devices[k].CDD
if self.devices[k].fuel.name == "Elec":
if self.devices[k].hasRefrigerant == True:
if self.devices[k].name == "Cooler":
refemis += self.devices[k].AvgRefLeaks(year) # * cdd/(hdd+cdd)
if self.devices[k].name == "Cond":
refemis += self.devices[k].AvgRefLeaks(year)
# print "\Iterate through device", self.type, self.devices[k].name, refemis
# print "\n ref yes/no", self.type,self.devices[k].fuel.name, self.devices[k].hasRefrigerant
NGeng = self.HHenergyUsage_units()[0] # this is in kWh
Eleceng = self.HHenergyUsage_units()[1]
# print "\n heat & cool eng", self.type,year, NGeng, Eleceng
emisng = (NGeng / Therm_kWh) * NGEmisYrly[year] / 1000
emiselec = Eleceng * ElecEmisYrly[year] / 1000
# print "\n HH EMissions", year, self.type, NGeng,Eleceng, emisng, emiselec, refemis, "..", ElecEmisYrly[year], NGEmisYrly[year]
return emisng, emiselec, refemis
def HHemissions_heatcool(self, year):
num = len(self.devices)
emisheat = 0
emiscool = 0
for k in range(0, num):
hdd = self.devices[k].HDD
cdd = self.devices[k].CDD
if self.devices[k].name != "Cooler" and self.devices[k].name != "Cond":
heateng = self.devices[k].AnnualHeatEngUsage_BTU() # NO NG BLOWER Usage
if self.devices[k].fuel.name == "Elec":
emisheat += (heateng / kWh_BTU) * ElecEmisYrly[year] / 1000
if self.devices[k].hasRefrigerant == True:
emisheat += self.devices[k].AvgRefLeaks(year)
# print "before",self.type, i, emisheat
if self.devices[k].fuel.name == "NG":
emisheat += (heateng / Therm_BTU) * NGEmisYrly[year] / 1000
if "WH" not in self.devices[k].name:
emisheat += (NG_AnnualElecUsage) * ElecEmisYrly[year] / 1000 # ADDING BLOWER USAGE
# print "I",self.type, i, emisheat, "\n"
if self.devices[k].name == "Cooler":
cooleng = self.devices[k].AnnualCoolEngUsage_BTU() / kWh_BTU
emiscool += cooleng * ElecEmisYrly[year] / 1000
if self.devices[k].hasRefrigerant == True:
emiscool += self.devices[k].AvgRefLeaks(year) * cdd / (hdd + cdd)
# print "II",self.type, i, emiscool , self.devices[k].AvgRefLeaks(year) ,"\n"
if self.devices[k].name == "Cond":
heateng = self.devices[k].AnnualHeatEngUsage_BTU() / kWh_BTU
cooleng = self.devices[k].AnnualCoolEngUsage_BTU() / kWh_BTU
hdd = self.devices[k].HDD
cdd = self.devices[k].CDD
emisheat += heateng * ElecEmisYrly[year] / 1000 + self.devices[k].AvgRefLeaks(year) * (hdd / (hdd + cdd))
emiscool += cooleng * ElecEmisYrly[year] / 1000 + self.devices[k].AvgRefLeaks(year) * (cdd / (hdd + cdd))
print
"III", self.type, i, self.devices[k].HDD, self.devices[k].CDD, emisheat, emiscool, self.devices[
k].AvgRefLeaks(year)
return emisheat, emiscool
def HHEnergyCost(self, year):
eng_units = self.HHenergyUsage_units()
ngdemand = eng_units[0] / Therm_kWh
elecdemand = eng_units[1]
# print "HH Energy units", self.type, year, ngdemand, elecdemand
ngCost = ngdemand * NGCostYrly[year]
elecCost = elecdemand * ElecCostYrly[year]
# print "Unit Cost", self.type, year, ngdemand, elecdemand,NGCostYrly[year], ElecCostYrly[year],ngCost, elecCost
return ngCost, elecCost
def HHTotalEnergyCost(self, year):
# print "Total Eng Cost", year, self.type, self.HHEnergyCost(year)[0], self.HHEnergyCost(year)[1]
return self.HHEnergyCost(year)[0] + self.HHEnergyCost(year)[1]
def HHTotalEmissions(self, year):
# print "Total Emis", year,self.type, self.HHemissions(year)[0] + self.HHemissions(year)[1]
return (self.HHemissions(year)[0] + self.HHemissions(year)[1])
def HHDevicesCapCost(self, year):
dev = self.devices
num = len(dev)
cost = 0
for k in range(0, num):
cost += self.devices[k].IC
# print "dev cost",num, self.devices[k].name, self.devices[k].IC
return cost
def HHNPVDevicesCost(self, year): # NPV of Capital Cost and OM Cost through the life of Devices
dev = self.devices
num = len(dev)
hhnpv = 0
for k in range(0, num):
# print "\n test devices Cost", year, self.type, self.devices[k].name, self.devices[k].lt
cost = self.devices[k].NPVCost(year)
# print "NPV Cost", cost
hhnpv += cost
# print year, self.type, hhnpv
return hhnpv
def HHNPVEnergyCost(self, year):
dev = self.devices
num = len(dev)
minLT = 0
engcost = 0
minLT = 0
for k in range(0, num):
minLT = min(self.devices[0].lt, self.devices[k].lt)
# print "MIN LT", self.type, self.devices[k].name,minLT, self.devices[k].lt
for k in range(year, year + minLT + 1):
cost = self.HHTotalEnergyCost(k)
engcost += cost / (1 + DiscRate) ** (k - year + 1)
# print year, self.type, cost
return engcost
def HHNPVEmissionsCost(self, year, UnitCarbonCost=0): # at CCost = $1, this is just a NPV of emissions
CCost = UnitCarbonCost
dev = self.devices
num = len(dev)
minLT = self.devices[0].lt
hhemisCost = 0
for k in range(0, num):
minLT = min(self.devices[k].lt, self.devices[k].lt)
# print "min LT", self.type, self.devices[k].name, minLT
for time in range(1, minLT + 1):
years = year + time
hhemis = self.HHTotalEmissions(years)
hhemisCost += CCost * hhemis / (1 + DiscRate) ** (time + 1)
# print "HH Emissions", year, self.type, hhemis, hhemisCost
return hhemisCost
def HHNPVDevicesCost(self, year): # NPV of Capital Cost and OM Cost through the life of Devices
dev = self.devices
num = len(dev)
hhnpv = 0
for k in range(0, num):
# print "\n test devices Cost", year, self.type, self.devices[k].name, self.devices[k].lt
cost = self.devices[k].NPVCost(year)
# print "NPV Cost", cost
hhnpv += cost
# print year, self.type, hhnpv
return hhnpv
# =================================================================================================================
def HHNPVEnergyCost_LT(self, year, horizon):
dev = self.devices
num = len(dev)
minLT = 0
engcost = 0
minLT = horizon
# print "MIN LT", self.type, self.devices[k].name,minLT, self.devices[k].lt
for k in range(year, year + minLT):
cost = self.HHTotalEnergyCost(k)
engcost += cost / (1 + DiscRate) ** (k - year)
# print year, self.type, cost
# print year, self.devices[0].name, engcost
return engcost
def HHNPVEmissionsCost_LT(self, year, horizon, UnitCarbonCost=0): # at CCost = $1, this is just a NPV of emissions
CCost = UnitCarbonCost
dev = self.devices
num = len(dev)
minLT = horizon
hhemisCost = 0
# print "min LT", self.type, self.devices[k].name, minLT
for time in range(1, minLT + 1):
years = year + time
hhemis = self.HHTotalEmissions(years)
hhemisCost += CCost * hhemis / (1 + DiscRate) ** (time)
# print "HH Emissions", year, self.type, hhemis, hhemisCost
return hhemisCost
# ============================================================================
def HHpayback(self, Hx, yr, CC): # SF3 = Hx and SF1= self two appliances vs Conditioner...specifically
N = 1
maxN = 22 #
dev1 = self.devices
dev2 = Hx.devices
num1 = len(dev1) # self
num2 = len(dev2) # SF3
Capcost1 = self.HHDevicesCapCost(yr)
Capcost2 = Hx.HHDevicesCapCost(yr)
delta_cost = Capcost2 - Capcost1
eng1 = self.HHTotalEnergyCost(yr) # Assuming O&M are the same for both...not true..but
eng2 = Hx.HHTotalEnergyCost(yr)
emis1 = self.HHTotalEmissions(yr)
emis2 = Hx.HHTotalEmissions(yr)
deng = eng2 - eng1
demis = CC * (emis2 - emis1)
delta = (deng + demis) / (1 + DiscRate) ** N
cnt = 0
# print "cnt 0...",cnt, N, yr, CC, delta_cost, deng, demis,delta
if round(delta_cost + delta, 0) <= 0:
return 0
elif round(delta_cost + delta, 0) > 0: # App2 is more expensive but app2 energy cheaper
while N <= maxN and round(delta_cost + delta, 0) > 0:
cnt += 1
N = N + 1
deng = Hx.HHTotalEnergyCost(yr + N) - self.HHTotalEnergyCost(yr + N)
demis = CC * (Hx.HHTotalEmissions(yr + N) - self.HHTotalEmissions(yr + N))
diff = (deng + demis)
delta += diff / (1 + DiscRate) ** (N)
return N
def HHCCBreakEven(self, Hx, yr, TimeHorizon=15): # breakeven carbon cost of Hx with self.
# print "\n Calling X1"
CC = 0
delta_cost = Hx.HHDevicesCapCost(yr) - self.HHDevicesCapCost(yr)
engcost1 = 0
engcost2 = 0
emis1 = 0
emis2 = 0
for k in range(yr, yr + TimeHorizon + 1):
cost1 = self.HHTotalEnergyCost(k)
engcost1 += cost1 / (1 + DiscRate) ** (k - yr)
hhemis1 = self.HHTotalEmissions(k)
emis1 += hhemis1 / (1 + DiscRate) ** (k - yr)
cost2 = Hx.HHTotalEnergyCost(k)
engcost2 += cost2 / (1 + DiscRate) ** (k - yr)
hhemis2 = Hx.HHTotalEmissions(k)
emis2 += hhemis2 / (1 + DiscRate) ** (k - yr)
delta_eng = engcost2 - engcost1
diff_emis = emis2 - emis1
delta_emis = CC * diff_emis
# print "breakeven CC..", CC, delta_cost , engcost1, engcost2, emis1, emis2
if round(delta_cost + delta_eng + delta_emis, 0) <= 0:
return CC
elif round(delta_cost + delta_eng + delta_emis, 0) > 0:
while round(delta_cost + delta_eng + delta_emis, 0) > 0 and CC <= 2000:
CC += 25
delta_emis = CC * diff_emis
# print "breakeven CC: ", yr,k, self.type, Hx.type, CC, delta_cost, delta_eng, emis2- emis1
return CC
def HHLCC(self, year, CarbonCost=0): # assuming time horizon is MinLifeTime of all appliances
lcc = self.HHNPVDevicesCost(year) + self.HHNPVEnergyCost(year) + self.HHNPVEmissionsCost(year, CarbonCost)
return lcc
class SFHomes(HouseType, object):
def __init__(self, type, HouseNum, cznum, size1, size2, vintage, devices, is_new=False):
super(SFHomes, self).__init__(type, HouseNum, cznum, size1, size2, vintage, devices, is_new)
# def HHenergy(self):
# return super(SFHomes, self).HHenergyUsage_BTU()
class MFHomes(HouseType, object):
def __init__(self, type, HouseNum, cznum, size11, size21, vintage, devices, is_new=False):
super(MFHomes, self).__init__(type, HouseNum, cznum, size11, size21, vintage, devices, is_new)
# def HHenergyUsage_BTU(self):
# return super(MFHomes, self).HHenergyUsage_BTU()
def getDead(p1_homes, devices, homeType, fuelName, k, yr):
# print "dead test", device.name, device.fuel.name
for dev in devices:
print
"testtest", yr, dev.C, k, len(devices), dev.name, fuelName, dev.annualreplacement(yr)
num = sum([dev.annualreplacement(yr) for dev in devices if (dev.C == k and dev.fuel.name == fuelName)])
# print "dead", num
return num
def getAppDead(p1_homes, devices, homeType, fuelName, AppName, k, yr):
if "HP" in AppName:
return sum([dev.annualreplacement(yr) for dev in devices if
(dev.C == k and dev.fuel.name == fuelName and "HP" in dev.name)])
elif "Cooler" in AppName:
return sum([dev.annualreplacement(yr) for dev in devices if
(dev.C == k and dev.fuel.name == fuelName and "Cooler" in dev.name)])
elif "Cond" in AppName:
return sum([dev.annualreplacement(yr) for dev in devices if
(dev.C == k and dev.fuel.name == fuelName and "Cond" in dev.name)])
def homesWithApp(homes, deviceName):
num = 0
for home in homes:
dev = home.devices
for d in dev:
if d.name == deviceName:
num += 1
return num
class HomesStats:
def __init__(self, year, cznum, homes):
self.year = year
self.cznum = cznum
self.homes = homes # hometype
self.aggregateHomeStats = {} # mapping of hometype to AggregateStats
# self.aggregatedevicesByType = {} # stats on different kinds of devices
class AggregateStats:
def __init__(self):
self.num = 0 # total homes of a hometype in a #cz in a year
self.num1 = 0 # total homes iwth heating
self.num2 = 0 # total homes with cooling
self.numdev = 0 # number of total devices in a home
self.aggDevices = {} # list of devices for each hometype
self.eng1 = 0 # NG energy
self.eng2 = 0 # electricity
self.heateng = 0
self.cooleng = 0
self.emis1 = 0 # NG emis
self.emis2 = 0 # Elec Emis
self.emis_refrig = 0
self.heatemis = 0
self.coolemis = 0
self.engCost1 = 0 # NG Cost
self.engCost2 = 0 # Elec Cost
self.heatCost = 0
self.coolCost = 0
self.replaceCost = 0
self.hpcond_heat = 0 # heat energy of HP Cond
self.hpcond_cool = 0
# self.devices = devices #specifics of device list in that home in that year in that cZ
self.aggDevices = aggDevices
# combine two lists of home classes into one struct
aggDevices = {}
def updateHomeStats(A, B):
# print A.year, B.year, A.cznum, B.cznum
z = copy.deepcopy(A)
z.year = A.year
z.cznum = A.cznum
# homesL1 = [A.homes]
# z.homes = homesL1.extend([B.homes] )
z.homes = copy.deepcopy(A.homes) + copy.deepcopy(B.homes)
# for homeType in B.aggregateHomeStats:
# if homeType in A.aggregateHomeStats:
# z.aggregateHomeStats[homeType] = combine(A.aggregateHomeStats[homeType], B.aggregateHomeStats[homeType])
# else:
# z.aggregateHomeStats[homeType] = B.aggregateHomeStats[homeType]
return z
# go field by field, creating homeStats with each field as combo self.field and otherHomeStats.field
# combine two aggregate stats
def combine(A, B):
newaggregate = copy.copy(A)
newaggregate.num += B.num
newaggregate.num1 += B.num1 # NUm HHs with heating
newaggregate.num2 += B.num2 # Num HHs iwth cooling
newaggregate.eng1 += B.eng1 # NG eng in kWh
newaggregate.eng2 += B.eng2 # Elec eng in kWH
newaggregate.heaeng += B.heateng
newaggregate.cooeng += B.cooleng
newaggregate.emis1 += B.emis1
newaggregate.emis2 += B.emis2
newaggregate.emis_refrig += B.emis_refrig
newaggregate.heatemis += B.heatemis
newaggregate.coolemis += B.coolemis
newaggregate.engCost1 += B.engCost1
newaggregate.engCost2 += B.engCost2
newaggregate.heatCost += B.heatCost
newaggregate.coolCost += B.coolCost
newaggregate.replaceCost += B.replaceCost
newaggregate.hpcond_heat += B.hpcond_heat
newaggregate.hpcond_cool += B.hpcond_cool
# newaggregate.aggDevices = A.aggDevices
# for dev in B.aggDevices:
# newaggregate.aggDevices += B.aggDevices
return newaggregate
# get a list of devices -
def getDevices(stats, homeType):
devs = []
for home in stats.homes:
if home.type == homeType:
for d in home.devices:
# if d.lt == 15:
devs += [copy.copy(d)]
return devs
def isDeviceinHome(home, devname):
for d in home.devices:
if d.name == devname:
return 1
return 0
"""
def addDevice(home, newdevname):
for d in home.devices:
dev = home.devices
if d.name != newdev.name: # if device already in the house..return the existing dev list
dev += newdev
return dev
"""
# get a list of devices of deviceType in a particular year from all hometypes
def getDevicesYear(stats, deviceType, year):
devs = []
for home in stats.homes:
# homeType = home.type
for d in home.devices:
if d.name == deviceType:
devs += [copy.copy(d)]
return devs
#
def getDeviceCountYear(stats, deviceType, year): # Num of devices of this type in a year in all homes
cnt = 0
for home in stats.homes:
# homeType = home.type
for d in home.devices:
if d.name == deviceType:
cnt += 1
return cnt
def getDeviceCountinHome(stats, deviceType, homeType, year): # THIS works
cnt = 0
for home in stats.homes:
if home.type == homeType:
for d in home.devices:
if d.name == deviceType:
cnt += 1
# print "func call:", home.type, d.name, cnt
return cnt
def getDeviceEnginHome(stats, deviceType, homeType):