-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBaseline.rb
More file actions
1477 lines (1298 loc) · 60.6 KB
/
Copy pathBaseline.rb
File metadata and controls
1477 lines (1298 loc) · 60.6 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
# *********************************************************************************
# URBANopt™, Copyright (c) 2019-2022, Alliance for Sustainable Energy, LLC, and other
# contributors. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this list
# of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# Neither the name of the copyright holder nor the names of its contributors may be
# used to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
# *********************************************************************************
require 'urbanopt/reporting'
require 'openstudio/common_measures'
require 'openstudio/model_articulation'
require 'openstudio/ee_measures'
require 'openstudio/calibration'
require 'openstudio/load_flexibility_measures'
require 'json'
require 'rexml/document'
module URBANopt
module Scenario
class BaselineMapper < SimulationMapperBase
# class level variables
@@instance_lock = Mutex.new
@@osw = nil
@@geometry = nil
def initialize
# do initialization of class variables in thread safe way
@@instance_lock.synchronize do
if @@osw.nil?
# load the OSW for this class
osw_path = File.join(File.dirname(__FILE__), 'base_workflow.osw')
File.open(osw_path, 'r') do |file|
@@osw = JSON.parse(file.read, symbolize_names: true)
end
# add any paths local to the project
@@osw[:measure_paths] << File.join(File.dirname(__FILE__), '../measures/')
@@osw[:measure_paths] << File.join(File.dirname(__FILE__), '../resources/hpxml-measures')
@@osw[:file_paths] << File.join(File.dirname(__FILE__), '../weather/')
# configures OSW with extension gem paths for measures and files, all extension gems must be
# required before this
@@osw = OpenStudio::Extension.configure_osw(@@osw)
end
end
end
def lookup_building_type(building_type, template, footprint_area, number_of_stories)
if template.include? 'DEER'
case building_type
when 'Education'
return 'EPr'
when 'Enclosed mall'
return 'RtL'
when 'Food sales'
return 'RSD'
when 'Food service'
return 'RSD'
when 'Inpatient health care'
return 'Nrs'
when 'Laboratory'
return 'Hsp'
when 'Lodging'
return 'Htl'
when 'Mixed use'
return 'ECC'
when 'Mobile Home'
return 'DMo'
when 'Multifamily (2 to 4 units)'
return 'MFm'
when 'Multifamily (5 or more units)'
return 'MFm'
when 'Nonrefrigerated warehouse'
return 'SUn'
when 'Nursing'
return 'Nrs'
when 'Office'
if footprint_area
if footprint_area.to_f > 100000
return 'OfL'
else
return 'OfS'
end
else
raise 'footprint_area required to map office building type'
end
when 'Outpatient health care'
return 'Nrs'
when 'Public assembly'
return 'Asm'
when 'Public order and safety'
return 'Asm'
when 'Refrigerated warehouse'
return 'WRf'
when 'Religious worship'
return 'Asm'
when 'Retail other than mall'
return 'RtS'
when 'Service'
return 'MLI'
when 'Single-Family'
return 'MFm'
when 'Strip shopping mall'
return 'RtL'
when 'Vacant'
return 'SUn'
else
raise "building type #{building_type} cannot be mapped to a DEER building type"
end
else
# default: ASHRAE
case building_type
when 'Education'
return 'SecondarySchool'
when 'Enclosed mall'
return 'RetailStripmall'
when 'Food sales'
return 'FullServiceRestaurant'
when 'Food service'
return 'FullServiceRestaurant'
when 'Inpatient health care'
return 'Hospital'
when 'Laboratory'
return 'Laboratory'
when 'Lodging'
if number_of_stories
if number_of_stories.to_i > 3
return 'LargeHotel'
else
return 'SmallHotel'
end
end
return 'LargeHotel'
when 'Mixed use'
return 'Mixed use'
when 'Mobile Home'
return 'MidriseApartment'
when 'Multifamily (2 to 4 units)'
return 'MidriseApartment'
when 'Multifamily (5 or more units)'
return 'MidriseApartment'
when 'Nonrefrigerated warehouse'
return 'Warehouse'
when 'Nursing'
return 'Outpatient'
when 'Office'
if footprint_area
if footprint_area.to_f < 20000
value = 'SmallOffice'
elsif footprint_area.to_f > 100000
value = 'LargeOffice'
else
value = 'MediumOffice'
end
else
raise 'Floor area required to map office building type'
end
when 'Outpatient health care'
return 'Outpatient'
when 'Public assembly'
return 'MediumOffice'
when 'Public order and safety'
return 'MediumOffice'
when 'Refrigerated warehouse'
return 'Warehouse'
when 'Religious worship'
return 'MediumOffice'
when 'Retail other than mall'
return 'RetailStandalone'
when 'Service'
return 'MediumOffice'
when 'Single-Family'
return 'MidriseApartment'
when 'Strip shopping mall'
return 'RetailStripmall'
when 'Vacant'
return 'Warehouse'
else
raise "building type #{building_type} cannot be mapped to an ASHRAE building type"
end
end
end
def lookup_template_by_year_built(template, year_built)
if template.include? 'DEER'
if year_built <= 1996
return 'DEER 1985'
elsif year_built <= 2003
return 'DEER 1996'
elsif year_built <= 2007
return 'DEER 2003'
elsif year_built <= 2011
return 'DEER 2007'
elsif year_built <= 2014
return 'DEER 2011'
elsif year_built <= 2015
return 'DEER 2014'
elsif year_built <= 2017
return 'DEER 2015'
elsif year_built <= 2020
return 'DEER 2017'
else
return 'DEER 2020'
end
else
# ASHRAE
if year_built < 1980
return 'DOE Ref Pre-1980'
elsif year_built <= 2004
return 'DOE Ref 1980-2004'
elsif year_built <= 2007
return '90.1-2004'
elsif year_built <= 2010
return '90.1-2007'
elsif year_built <= 2013
return '90.1-2010'
else
return '90.1-2013'
end
end
end
def residential_building_types
return [
'Single-Family Detached',
'Single-Family Attached',
'Multifamily'
]
end
def commercial_building_types
return [
'Vacant',
'Office',
'Laboratory',
'Nonrefrigerated warehouse',
'Food sales',
'Public order and safety',
'Outpatient health care',
'Refrigerated warehouse',
'Religious worship',
'Public assembly',
'Education',
'Food service',
'Inpatient health care',
'Nursing',
'Lodging',
'Strip shopping mall',
'Enclosed mall',
'Retail other than mall',
'Service',
'Uncovered Parking',
'Covered Parking',
'Mixed use',
'Multifamily (2 to 4 units)',
'Multifamily (5 or more units)',
'Single-Family'
]
end
def get_arg_default(arg)
case arg.type.valueName.downcase
when 'boolean'
return arg.defaultValueAsBool
when 'double'
return arg.defaultValueAsDouble
when 'integer'
return arg.defaultValueAsInteger
when 'string'
return arg.defaultValueAsString
when 'choice'
return arg.defaultValueAsString
end
end
def get_lookup_tsv(args, filepath)
rows = []
headers = []
units = []
CSV.foreach(filepath, { col_sep: "\t" }) do |row|
if headers.empty?
row.each do |header|
next if header == 'Source'
if args.key?(header.gsub('Dependency=', '').to_sym)
header = header.gsub('Dependency=', '')
end
unless header.include?('Dependency=')
header = header.to_sym
end
headers << header
end
next
elsif units.empty?
row.each do |unit|
units << unit
end
next
end
if headers.length != row.length
row = row[0..-2] # leave out Source column
end
rows << headers.zip(row).to_h
end
return rows
end
def get_lookup_row(args, rows, template_vals)
rows.each do |row|
if row.key?('Dependency=Climate Zone') && (row['Dependency=Climate Zone'] != template_vals[:climate_zone])
next
end
if row.key?('Dependency=IECC Year') && (row['Dependency=IECC Year'] != template_vals[:iecc_year])
next
end
if row.key?('Dependency=Template Month') && (row['Dependency=Template Month'] != template_vals[:t_month])
next
end
if row.key?('Dependency=Template Year') && (row['Dependency=Template Year'] != template_vals[:t_year])
next
end
row.delete('Dependency=Climate Zone')
row.delete('Dependency=IECC Year')
row.delete('Dependency=Template Month')
row.delete('Dependency=Template Year')
row.each do |k, v|
next unless v.nil?
row.delete(k)
end
intersection = args.keys & row.keys
return row if intersection.empty? # found the correct row
skip = false
intersection.each do |k|
if args[k] != row[k]
skip = true
end
end
return row unless skip
end
return nil
end
def get_climate_zone_iecc(epw)
headers = CSV.open(epw, 'r', &:first)
wmo = headers[5]
zones_csv = File.join(File.dirname(__FILE__), '../resources/hpxml-measures/HPXMLtoOpenStudio/resources/data/climate_zones.csv')
CSV.foreach(zones_csv) do |row|
if row[0].to_s == wmo.to_s
return row[6].to_s
end
end
end
# epw_state to subregions mapping methods
#REK: Maybe we can move these method to the geojson gem
def get_future_emissions_region(feature)
# Options are: AZNMc, CAMXc, ERCTc, FRCCc, MROEc, MROWc, NEWEc, NWPPc, NYSTc, RFCEc, RFCMc, RFCWc, RMPAc, SPNOc, SPSOc, SRMVc, SRMWc, SRSOc, SRTVc, and SRVCc
# egrid subregions can map directly to zipcodes but not to states. Some state might include multiple egrid subregions. the default mapper prioritize the egrid subregion that is most common in the state (covers the biggest number of zipcodes)
future_emissions_mapping_hash =
{'FL': 'FRCCc', #['FRCCc', 'SRSOc']
'MS': 'SRMVc', #['SRMVc', 'SRTVc']
'NE': 'MROWc', #['MROWc', 'RMPAc']
'OR': 'NWPPc',
'CA': 'CAMXc', #['CAMXc', 'NWPPc']
'VA': 'SRVCc', #['SRVCc', 'RFCWc', 'RFCEc'],
'AR': 'SRMVc', #['SRMVc', 'SPSOc']
'TX': 'ERCTc', #['ERCTc', 'SRMVc', 'SPSOc', 'AZNMc']
'OH': 'RFCWc',
'UT': 'NWPPc',
'MT': 'NWPPc', #['NWPPc', 'MROWc']
'TN': 'SRTVc',
'ID': 'NWPPc',
'WI': 'MROEc', #['RFCWc', 'MROEc', 'MROWc']
'WV': 'RFCWc',
'NC': 'SRVCc',
'LA': 'SRMVc',
'IL': 'SRMWc', #['RFCWc', 'SRMWc']
'OK': 'SPSOc',
'IA': 'MROWc',
'WA': 'NWPPc',
'SD': 'MROWc', #['MROWc', 'RMPAc']
'MN': 'MROWc',
'KY': 'SRTVc', #['SRTVc', 'RFCWc']
'MI': 'RFCMc', #['RFCMc', 'MROEc']
'KS': 'SPNOc',
'NJ': 'RFCEc',
'NY': 'NYSTc',
'IN': 'RFCWc',
'VT': 'NEWEc',
'NM': 'AZNMc', #['AZNMc', 'SPSOc']
'WY': 'RMPAc', #['RMPAc', 'NWPPc']
'GA': 'SRSOc',
'MO': 'SRMWc', #['SRMWc', 'SPNOc']
'DC': 'RFCEc',
'SC': 'SRVCc',
'PA': 'RFCEc', #['RFCEc', 'RFCWc']
'CO': 'RMPAc',
'AZ': 'AZNMc',
'ME': 'NEWEc',
'AL': 'SRSOc',
'MD': 'RFCEc', #['RFCEc', 'RFCWc']
'NH': 'NEWEc',
'MA': 'NEWEc',
'ND': 'MROWc',
'NV': 'NWPPc', #['NWPPc', 'AZNMc']
'CT': 'NEWEc',
'DE': 'RFCEc',
'RI': 'NEWEc'}
#get the state from weather file
state = feature.weather_filename.split('_', -1)[1]
#find region input based on the state
region = future_emissions_mapping_hash[state.to_sym]
puts "emissions_future_subregion for #{state} is assigned to: #{region}"
puts "You can overwrite this assigned input by specifiying the emissions_future_subregion input in the FeatureFile"
return region
end
def get_hourly_historical_emissions_region(feature)
# Options are: California, Carolinas, Central, Florida, Mid-Atlantic, Midwest, New England, New York, Northwest, Rocky Mountains, Southeast, Southwest, Tennessee, and Texas
# There is no "correct" mapping of eGrid to AVERT regions as they are both large geographical areas that partially overlap.
# Mapping is done using mapping tools from eGrid and AVERT (ZipCode for eGrid and fraction of state for AVERT).
# Mapped based on the maps of each set of regions:
hourly_historical_mapping_hash =
{'FL': 'Florida',
'MS': 'Midwest',
'NE': 'Midwest',#MRWO could be Midwest / Central
'OR': 'Northwest',
'CA': 'California',
'VA': 'Carolinas',
'AR': 'Midwest',
'TX': 'Texas',
'OH': 'Midwest',#RFCW could be Midwest / Mid Atlantic
'UT': 'Northwest',
'MT': 'Northwest',
'TN': 'Tennessee',
'ID': 'Northwest',
'WI': 'Midwest',
'WV': 'Midwest', #RFCW could be Midwest / Mid Atlantic
'NC': 'Carolinas',
'LA': 'Midwest',
'IL': 'Midwest',
'OK': 'Central',
'IA': 'Midwest', #MRWO could be Midwest / Central
'WA': 'Northwest',
'SD': 'Midwest',#MRWO could be Midwest / Central
'MN': 'Midwest',#MRWO could be Midwest / Central
'KY': 'Tennessee',
'MI': 'Midwest',
'KS': 'Central',
'NJ': 'Mid-Atlantic',
'NY': 'New York',
'IN': 'Midwest', #RFCW could be Midwest / Mid Atlantic
'VT': 'New England',
'NM': 'Southwest',
'WY': 'Rocky Mountains',
'GA': 'SRSO',
'MO': 'Midwest',
'DC': 'Mid-Atlantic',
'SC': 'Carolinas',
'PA': 'Mid-Atlantic',
'CO': 'Rocky Mountains',
'AZ': 'Southwest',
'ME': 'New England',
'AL': 'Southeast',
'MD': 'Mid-Atlantic',
'NH': 'New England',
'MA': 'New England',
'ND': 'Midwest',#MRWO could be Midwest / Central
'NV': 'Northwest',
'CT': 'New England',
'DE': 'Mid-Atlantic',
'RI': 'New England'}
#get the state from weather file
state = feature.weather_filename.split('_', -1)[1]
#find region input based on the state
region = hourly_historical_mapping_hash[state.to_sym]
puts "emissions_hourly_historical_subregion for #{state} is assigned to: #{region}"
puts "You can overwrite this assigned input by specifiying the emissions_hourly_historical_subregion input in the FeatureFile"
return region
end
def get_annual_historical_emissions_region(feature)
# Options are: AKGD, AKMS, AZNM, CAMX, ERCT, FRCC, HIMS, HIOA, MROE, MROW, NEWE, NWPP, NYCW, NYLI, NYUP, RFCE, RFCM, RFCW, RMPA, SPNO, SPSO, SRMV, SRMW, SRSO, SRTV, and SRVC
# egrid subregions can map directly to zipcodes but not to states. Some state might include multiple egrid subregions. the default mapper prioritize the egrid subregion that is most common in the state (covers the biggest number of zipcodes)
annual_historical_mapping_hash =
{'FL': 'FRCC',
'MS': 'SRMV',
'NE': 'MROW',
'OR': 'NWPP',
'CA': 'CAMX',
'VA': 'SRVC',
'AR': 'SRMV',
'TX': 'ERCT',
'OH': 'RFCW',
'UT': 'NWPP',
'MT': 'NWPP',
'TN': 'SRTV',
'ID': 'NWPP',
'WI': 'MROE',
'WV': 'RFCW',
'NC': 'SRVC',
'LA': 'SRMV',
'IL': 'SRMW',
'OK': 'SPSO',
'IA': 'MROW',
'WA': 'NWPP',
'SD': 'MROW',
'MN': 'MROW',
'KY': 'SRTV',
'MI': 'RFCM',
'KS': 'SPNO',
'NJ': 'RFCE',
'NY': 'NYCW',
'IN': 'RFCW',
'VT': 'NEWE',
'NM': 'AZNM',
'WY': 'RMPA',
'GA': 'SRSO',
'MO': 'SRMW',
'DC': 'RFCE',
'SC': 'SRVC',
'PA': 'RFCE',
'CO': 'RMPA',
'AZ': 'AZNM',
'ME': 'NEWE',
'AL': 'SRSO',
'MD': 'RFCE',
'NH': 'NEWE',
'MA': 'NEWE',
'ND': 'MROW',
'NV': 'NWPP',
'CT': 'NEWE',
'DE': 'RFCE',
'RI': 'NEWE'}
#get the state from weather file
state = feature.weather_filename.split('_', -1)[1]
#finf region input based on the state
region = annual_historical_mapping_hash[state.to_sym]
puts "emissions_annual_historical_subregion for #{state} is assigned to: #{region}"
puts "You can overwrite this assigned input by specifiying the emissions_annual_historical_subregion input in the FeatureFile"
return region
end
def is_defined(feature, method_name, raise_error=true)
begin
if feature.method_missing(method_name)
return true
end
rescue NoMethodError
if raise_error
raise "*** ERROR *** #{method_name} is not set on this feature"
end
return false
end
end
def create_osw(scenario, features, feature_names)
if features.size != 1
raise 'Baseline currently cannot simulate more than one feature.'
end
feature = features[0]
feature_id = feature.id
feature_type = feature.type
# take the centroid of the vertices as the location of the building
feature_vertices_coordinates = feature.feature_json[:geometry][:coordinates][0]
feature_location = feature.find_feature_center(feature_vertices_coordinates).to_s
feature_name = feature.name
if feature_names.size == 1
feature_name = feature_names[0]
end
# deep clone of @@osw before we configure it
osw = Marshal.load(Marshal.dump(@@osw))
# now we have the feature, we can look up its properties and set arguments in the OSW
osw[:name] = feature_name
osw[:description] = feature_name
if feature_type == 'Building'
building_type = feature.building_type
if building_type.nil?
# need building type
raise 'Building type is not set'
end
if residential_building_types.include? building_type
debug = false
# Check for required residential fields
is_defined(feature, :number_of_stories_above_ground)
is_defined(feature, :foundation_type)
if not is_defined(feature, :hpxml_directory, false)
# check additional fields when HPXML dir is not given
is_defined(feature, :attic_type)
is_defined(feature, :number_of_bedrooms)
if ['Single-Family Attached', 'Multifamily'].include?(building_type)
is_defined(feature, :number_of_residential_units)
end
end
args = {}
# Custom HPXML Files
begin
args[:hpxml_dir] = feature.hpxml_directory
rescue StandardError
end
# Occupancy Calculation Type
args[:occupancy_calculation_type] = 'asset'
begin
args[:occupancy_calculation_type] = feature.occupancy_calculation_type
rescue StandardError
end
# Simulation Control
args[:simulation_control_timestep] = 60
begin
args[:simulation_control_timestep] = 60 / feature.timesteps_per_hour
rescue StandardError
end
args[:simulation_control_run_period] = 'Jan 1 - Dec 31'
args[:simulation_control_run_period_calendar_year] = 2007
begin
abbr_monthnames = Date::ABBR_MONTHNAMES
begin_month = abbr_monthnames[feature.begin_date[5, 2].to_i]
begin_day_of_month = feature.begin_date[8, 2].to_i
end_month = abbr_monthnames[feature.end_date[5, 2].to_i]
end_day_of_month = feature.end_date[8, 2].to_i
args[:simulation_control_run_period] = "#{begin_month} #{begin_day_of_month} - #{end_month} #{end_day_of_month}"
args[:simulation_control_run_period_calendar_year] = feature.begin_date[0, 4].to_i
rescue StandardError
end
args[:weather_station_epw_filepath] = "../../../weather/#{feature.weather_filename}"
# Geometry
args[:geometry_building_num_units] = 1
args[:geometry_unit_num_floors_above_grade] = 1
case building_type
when 'Single-Family Detached'
args[:geometry_unit_type] = 'single-family detached'
args[:geometry_unit_num_floors_above_grade] = feature.number_of_stories_above_ground
when 'Single-Family Attached'
args[:geometry_unit_type] = 'single-family attached'
begin
args[:geometry_building_num_units] = feature.number_of_residential_units
rescue StandardError
end
args[:geometry_unit_num_floors_above_grade] = feature.number_of_stories_above_ground
when 'Multifamily'
args[:geometry_unit_type] = 'apartment unit'
begin
args[:geometry_building_num_units] = feature.number_of_residential_units
rescue StandardError
end
end
args[:geometry_num_floors_above_grade] = feature.number_of_stories_above_ground
args[:geometry_foundation_type] = 'SlabOnGrade'
args[:geometry_foundation_height] = 0.0
case feature.foundation_type
when 'crawlspace - vented'
args[:geometry_foundation_type] = 'VentedCrawlspace'
args[:geometry_foundation_height] = 3.0
when 'crawlspace - unvented'
args[:geometry_foundation_type] = 'UnventedCrawlspace'
args[:geometry_foundation_height] = 3.0
when 'crawlspace - conditioned'
args[:geometry_foundation_type] = 'ConditionedCrawlspace'
args[:geometry_foundation_height] = 3.0
when 'basement - unconditioned'
args[:geometry_foundation_type] = 'UnconditionedBasement'
args[:geometry_foundation_height] = 8.0
when 'basement - conditioned'
args[:geometry_foundation_type] = 'ConditionedBasement'
args[:geometry_foundation_height] = 8.0
when 'ambient'
args[:geometry_foundation_type] = 'Ambient'
args[:geometry_foundation_height] = 8.0
end
begin
case feature.attic_type
when 'attic - vented'
args[:geometry_attic_type] = 'VentedAttic'
begin
args[:geometry_roof_type] = feature.roof_type
rescue StandardError
end
when 'attic - unvented'
args[:geometry_attic_type] = 'UnventedAttic'
begin
args[:geometry_roof_type] = feature.roof_type
rescue StandardError
end
when 'attic - conditioned'
args[:geometry_attic_type] = 'ConditionedAttic'
begin
args[:geometry_roof_type] = feature.roof_type
rescue StandardError
end
when 'flat roof'
args[:geometry_attic_type] = 'FlatRoof'
end
rescue StandardError
end
args[:geometry_roof_type] = 'gable'
begin
case feature.roof_type
when 'Hip'
args[:geometry_roof_type] = 'hip'
end
rescue StandardError
end
begin
args[:geometry_unit_cfa] = feature.floor_area / args[:geometry_building_num_units]
rescue StandardError
end
begin
args[:geometry_unit_num_bedrooms] = feature.number_of_bedrooms / args[:geometry_building_num_units]
rescue StandardError
end
args[:geometry_unit_num_occupants] = 'auto'
begin
args[:geometry_unit_num_occupants] = "#{feature.number_of_occupants / args[:geometry_building_num_units]}"
rescue StandardError
end
args[:geometry_average_ceiling_height] = 8.0
begin
args[:geometry_average_ceiling_height] = feature.maximum_roof_height / feature.number_of_stories_above_ground
rescue StandardError
end
begin
num_garage_spaces = 0
if feature.onsite_parking_fraction
num_garage_spaces = 1
if args[:geometry_unit_cfa] > 2500.0
num_garage_spaces = 2
end
end
args[:geometry_garage_width] = 12.0 * num_garage_spaces
args[:geometry_garage_protrusion] = 1.0
rescue StandardError
end
args[:neighbor_left_distance] = 0.0
args[:neighbor_right_distance] = 0.0
# SCHEDULES
feature_ids = []
scenario.feature_file.features.each do |feature|
feature_ids << feature.id
end
args[:feature_id] = feature_id
args[:schedules_random_seed] = feature_ids.index(feature_id)
args[:schedules_type] = 'stochastic' # smooth or stochastic
args[:schedules_variation] = 'unit' # building or unit
# HVAC
system_type = 'Residential - furnace and central air conditioner'
begin
system_type = feature.system_type
rescue StandardError
end
args[:heating_system_type] = 'none'
if system_type.include?('electric resistance')
args[:heating_system_type] = 'ElectricResistance'
elsif system_type.include?('furnace')
args[:heating_system_type] = 'Furnace'
elsif system_type.include?('boiler')
args[:heating_system_type] = 'Boiler'
end
args[:cooling_system_type] = 'none'
if system_type.include?('central air conditioner')
args[:cooling_system_type] = 'central air conditioner'
elsif system_type.include?('room air conditioner')
args[:cooling_system_type] = 'room air conditioner'
elsif system_type.include?('evaporative cooler')
args[:cooling_system_type] = 'evaporative cooler'
end
args[:heat_pump_type] = 'none'
if system_type.include?('air-to-air')
args[:heat_pump_type] = 'air-to-air'
elsif system_type.include?('mini-split')
args[:heat_pump_type] = 'mini-split'
elsif system_type.include?('ground-to-air')
args[:heat_pump_type] = 'ground-to-air'
end
args[:heating_system_fuel] = 'natural gas'
begin
args[:heating_system_fuel] = feature.heating_system_fuel_type
rescue StandardError
end
if args[:heating_system_type] == 'ElectricResistance'
args[:heating_system_fuel] = 'electricity'
end
# APPLIANCES
args[:cooking_range_oven_fuel_type] = args[:heating_system_fuel]
args[:clothes_dryer_fuel_type] = args[:heating_system_fuel]
# WATER HEATER
args[:water_heater_fuel_type] = args[:heating_system_fuel]
template = nil
begin
template = feature.template
rescue StandardError
end
# IECC / EnergyStar / Other
if !template.nil? && template.include?('Residential IECC')
captures = template.match(/Residential IECC (?<iecc_year>\d+) - Customizable Template (?<t_month>\w+) (?<t_year>\d+)/)
template_vals = Hash[captures.names.zip(captures.captures)]
template_vals = template_vals.transform_keys(&:to_sym)
epw = File.join(File.dirname(__FILE__), '../weather', feature.weather_filename)
template_vals[:climate_zone] = get_climate_zone_iecc(epw)
# ENCLOSURE
enclosure_filepath = File.join(File.dirname(__FILE__), 'residential/enclosure.tsv')
enclosure = get_lookup_tsv(args, enclosure_filepath)
row = get_lookup_row(args, enclosure, template_vals)
# Determine which surfaces to place insulation on
if args[:geometry_foundation_type].include? 'Basement'
row[:foundation_wall_assembly_r] = row[:foundation_wall_assembly_r_basement]
row[:floor_over_foundation_assembly_r] = 2.1
row[:floor_over_garage_assembly_r] = 2.1
elsif args[:geometry_foundation_type].include? 'Crawlspace'
row[:foundation_wall_assembly_r] = row[:foundation_wall_assembly_r_crawlspace]
row[:floor_over_foundation_assembly_r] = 2.1
row[:floor_over_garage_assembly_r] = 2.1
end
row.delete(:foundation_wall_assembly_r_basement)
row.delete(:foundation_wall_assembly_r_crawlspace)
if ['ConditionedAttic'].include?(args[:geometry_attic_type])
row[:roof_assembly_r] = row[:ceiling_assembly_r]
row[:ceiling_assembly_r] = 2.1
end
args.update(row) unless row.nil?
# HVAC
if args[:heating_system_type] != 'none'
heating_system_filepath = File.join(File.dirname(__FILE__), 'residential/heating_system.tsv')
heating_system = get_lookup_tsv(args, heating_system_filepath)
row = get_lookup_row(args, heating_system, template_vals)
args.update(row) unless row.nil?
end
if args[:cooling_system_type] != 'none'
cooling_system_filepath = File.join(File.dirname(__FILE__), 'residential/cooling_system.tsv')
cooling_system = get_lookup_tsv(args, cooling_system_filepath)
row = get_lookup_row(args, cooling_system, template_vals)
args.update(row) unless row.nil?
end
if args[:heat_pump_type] != 'none'
heat_pump_filepath = File.join(File.dirname(__FILE__), 'residential/heat_pump.tsv')
heat_pump = get_lookup_tsv(args, heat_pump_filepath)
row = get_lookup_row(args, heat_pump, template_vals)
args.update(row) unless row.nil?
end
# APPLIANCES
['refrigerator', 'clothes_washer', 'dishwasher', 'clothes_dryer'].each do |appliance|
appliances_filepath = File.join(File.dirname(__FILE__), "residential/#{appliance}.tsv")
appliances = get_lookup_tsv(args, appliances_filepath)
row = get_lookup_row(args, appliances, template_vals)
args.update(row) unless row.nil?
end
# MECHANICAL VENTILATION
mechvent_filepath = File.join(File.dirname(__FILE__), 'residential/mechanical_ventilation.tsv')
mechvent = get_lookup_tsv(args, mechvent_filepath)
row = get_lookup_row(args, mechvent, template_vals)
args.update(row) unless row.nil?
# EXHAUST
exhaust_filepath = File.join(File.dirname(__FILE__), 'residential/exhaust.tsv')
exhaust = get_lookup_tsv(args, exhaust_filepath)
row = get_lookup_row(args, exhaust, template_vals)
args.update(row) unless row.nil?
# WATER HEATER
water_heater_filepath = File.join(File.dirname(__FILE__), 'residential/water_heater.tsv')
water_heater = get_lookup_tsv(args, water_heater_filepath)
row = get_lookup_row(args, water_heater, template_vals)
args.update(row) unless row.nil?
end
# Parse BuildResidentialModel measure xml so we can override defaults with template values
default_args = {}
OpenStudio::Extension.set_measure_argument(osw, 'BuildResidentialModel', '__SKIP__', false)
measures_dir = File.absolute_path(File.join(File.dirname(__FILE__), '../resources/hpxml-measures'))
measure_xml = File.read(File.join(measures_dir, 'BuildResidentialHPXML', 'measure.xml'))
measure = REXML::Document.new(measure_xml).root
measure.elements.each('arguments/argument') do |arg|
arg_name = arg.elements['name'].text.to_sym
next if [:hpxml_path].include? arg_name
default_args[arg_name] = nil
if arg.elements['default_value']
arg_default = arg.elements['default_value'].text
default_args[arg_name] = arg_default
end
end
args.each_key do |arg_name|
unless default_args.key?(arg_name)
next if [:feature_id, :schedules_type, :schedules_random_seed, :schedules_variation, :geometry_num_floors_above_grade, :hpxml_dir].include?(arg_name)
puts "Argument '#{arg_name}' is unknown."
end
end
default_args.each do |arg_name, arg_default|
next if arg_default.nil?
if !args.key?(arg_name)
args[arg_name] = arg_default