openstudio-standards 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/openstudio-standards.rb +0 -28
- data/lib/openstudio-standards/hvac_sizing/Siz.Model.rb +1 -0
- data/lib/openstudio-standards/prototypes/common/do_not_edit_metaclasses.rb +459 -459
- data/lib/openstudio-standards/prototypes/common/objects/Prototype.Model.rb +1 -1
- data/lib/openstudio-standards/prototypes/common/objects/Prototype.utilities.rb +22 -0
- data/lib/openstudio-standards/prototypes/common/prototype_metaprogramming.rb +9 -19
- data/lib/openstudio-standards/standards/Standards.Model.rb +26 -9
- data/lib/openstudio-standards/standards/necb/necb_2011/data/standards_data.rb +10 -3
- data/lib/openstudio-standards/standards/necb/necb_2011/necb_2011.rb +25 -14
- data/lib/openstudio-standards/standards/standard.rb +2 -2
- data/lib/openstudio-standards/version.rb +1 -1
- data/lib/openstudio-standards/weather/Weather.Model.rb +31 -12
- metadata +3 -3
@@ -19,7 +19,7 @@ Standard.class_eval do
|
|
19
19
|
# this is required to be blank otherwise it may cause side effects.
|
20
20
|
epw_file = ''
|
21
21
|
end
|
22
|
-
model =
|
22
|
+
model = load_geometry_osm(@geometry_file)
|
23
23
|
model.getThermostatSetpointDualSetpoints(&:remove)
|
24
24
|
model.getBuilding.setName(self.class.to_s)
|
25
25
|
# save new basefile to new geometry folder as class name.
|
@@ -102,6 +102,28 @@ class Standard
|
|
102
102
|
return model
|
103
103
|
end
|
104
104
|
|
105
|
+
# Loads a JSON file containing the space type map into a hash
|
106
|
+
#
|
107
|
+
# @param hvac_map_file [String] path to JSON file, relative to the /data folder
|
108
|
+
# @return [Hash] returns a hash that contains the space type map
|
109
|
+
def load_hvac_map(hvac_map_file)
|
110
|
+
# Load the geometry .osm from relative to the data folder
|
111
|
+
rel_path_to_hvac_map = "../../../../../data/#{hvac_map_file}"
|
112
|
+
|
113
|
+
# Load the JSON depending on whether running from normal gem location
|
114
|
+
# or from the embedded location in the OpenStudio CLI
|
115
|
+
if File.dirname(__FILE__)[0] == ':'
|
116
|
+
# running from embedded location in OpenStudio CLI
|
117
|
+
hvac_map_string = load_resource_relative(rel_path_to_hvac_map)
|
118
|
+
hvac_map = JSON.parse(hvac_map_string)
|
119
|
+
else
|
120
|
+
abs_path = File.join(File.dirname(__FILE__), rel_path_to_hvac_map)
|
121
|
+
hvac_map = JSON.parse(File.read(abs_path))if File.exist?(abs_path)
|
122
|
+
end
|
123
|
+
|
124
|
+
return hvac_map
|
125
|
+
end
|
126
|
+
|
105
127
|
# Convert from SEER to COP (no fan) for cooling coils
|
106
128
|
# @ref [References::ASHRAE9012013] Appendix G
|
107
129
|
#
|
@@ -70,9 +70,9 @@ end
|
|
70
70
|
end
|
71
71
|
@lookup_building_type = self.model_get_lookup_name(@@building_type)
|
72
72
|
#ideally we should map the data required to a instance variable.
|
73
|
-
@geometry_file =
|
74
|
-
hvac_map_file =
|
75
|
-
@system_to_space_map =
|
73
|
+
@geometry_file = 'geometry/' + self.class.name + '.osm'
|
74
|
+
hvac_map_file = 'geometry/' + self.class.name + '.hvac_map.json'
|
75
|
+
@system_to_space_map = load_hvac_map(hvac_map_file)
|
76
76
|
self.set_variables()
|
77
77
|
end
|
78
78
|
# This method is used to extend the class with building-type-specific
|
@@ -188,9 +188,9 @@ end
|
|
188
188
|
end
|
189
189
|
@lookup_building_type = self.model_get_lookup_name(@building_type)
|
190
190
|
#ideally we should map the data required to a instance variable.
|
191
|
-
@geometry_file =
|
192
|
-
hvac_map_file =
|
193
|
-
@system_to_space_map =
|
191
|
+
@geometry_file = 'geometry/' + self.class.name + '.osm'
|
192
|
+
hvac_map_file = 'geometry/' + self.class.name + '.hvac_map.json'
|
193
|
+
# @system_to_space_map = load_hvac_map(hvac_map_file) # No HVAC map json files for NECB
|
194
194
|
self.set_variables()
|
195
195
|
end
|
196
196
|
|
@@ -512,19 +512,9 @@ end
|
|
512
512
|
end
|
513
513
|
@lookup_building_type = @@building_type
|
514
514
|
#ideally we should map the data required to a instance variable.
|
515
|
-
@geometry_file =
|
516
|
-
|
517
|
-
|
518
|
-
raise(\"Could not find geometry osm \#{@prototype_input['geometry_osm']} for #{template}#{building_type}#{hvac_system}, cannot create model.\")
|
519
|
-
return false
|
520
|
-
end
|
521
|
-
hvac_map_file = Folders.instance.data_geometry_folder + '/' + @prototype_input['hvac_json']
|
522
|
-
if !File.exist?(hvac_map_file)
|
523
|
-
OpenStudio.logFree(OpenStudio::Error, 'openstudio.standards.Model', \"Could not find prototype inputs for \#{{'template' => @template,'building_type' => @@building_type, 'hvac' => @@hvac_system}}, cannot create model.\")
|
524
|
-
raise(\"Could not find HVAC json \#{@prototype_input['hvac_json']} for #{template}#{building_type}#{hvac_system}, cannot create model.\")
|
525
|
-
return false
|
526
|
-
end
|
527
|
-
@system_to_space_map = JSON.parse(File.read(hvac_map_file))if File.exist?(hvac_map_file)
|
515
|
+
@geometry_file = 'geometry/' + @prototype_input['geometry_osm']
|
516
|
+
hvac_map_file = 'geometry/' + @prototype_input['hvac_json']
|
517
|
+
@system_to_space_map = load_hvac_map(hvac_map_file)
|
528
518
|
self.set_variables()
|
529
519
|
end
|
530
520
|
|
@@ -4433,16 +4433,33 @@ class Standard
|
|
4433
4433
|
|
4434
4434
|
# Loads a osm as a starting point.
|
4435
4435
|
#
|
4436
|
+
# @param osm_file [String] path to the .osm file, relative to the /data folder
|
4436
4437
|
# @return [Bool] returns true if successful, false if not
|
4437
|
-
def
|
4438
|
-
# Load the geometry .osm
|
4439
|
-
|
4440
|
-
|
4441
|
-
|
4442
|
-
|
4443
|
-
|
4444
|
-
|
4445
|
-
|
4438
|
+
def load_geometry_osm(osm_file)
|
4439
|
+
# Load the geometry .osm from relative to the data folder
|
4440
|
+
osm_model_path = "../../../data/#{osm_file}"
|
4441
|
+
|
4442
|
+
# Load the .osm depending on whether running from normal gem location
|
4443
|
+
# or from the embedded location in the OpenStudio CLI
|
4444
|
+
if File.dirname(__FILE__)[0] == ':'
|
4445
|
+
# running from embedded location in OpenStudio CLI
|
4446
|
+
geom_model_string = load_resource_relative(osm_model_path)
|
4447
|
+
version_translator = OpenStudio::OSVersion::VersionTranslator.new
|
4448
|
+
model = version_translator.loadModelFromString(geom_model_string)
|
4449
|
+
else
|
4450
|
+
abs_path = File.join(File.dirname(__FILE__), osm_model_path)
|
4451
|
+
version_translator = OpenStudio::OSVersion::VersionTranslator.new
|
4452
|
+
model = version_translator.loadModel(abs_path)
|
4453
|
+
end
|
4454
|
+
|
4455
|
+
# Check that the model loaded successfully
|
4456
|
+
if model.empty?
|
4457
|
+
OpenStudio.logFree(OpenStudio::Error, 'openstudio.model.Model', "Version translation failed for #{osm_model_path}")
|
4458
|
+
return false
|
4459
|
+
end
|
4460
|
+
model = model.get
|
4461
|
+
|
4462
|
+
# Check for expected characteristics of geometry model
|
4446
4463
|
if model.getBuildingStorys.empty?
|
4447
4464
|
OpenStudio.logFree(OpenStudio::Error, 'openstudio.model.Model', "Please assign Spaces to BuildingStorys in the geometry model: #{osm_model_path}.")
|
4448
4465
|
end
|
@@ -88,10 +88,17 @@ class StandardsData
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def load_standards_data(datafolder = File.dirname(__FILE__))
|
91
|
-
files = Dir.glob("#{datafolder}/**/*.json").select {|e| File.file? e}
|
92
91
|
@standards_data = {}
|
93
|
-
|
94
|
-
|
92
|
+
if __dir__[0] == ':' # Running from OpenStudio CLI
|
93
|
+
files = embedded_files_relative('./', /.*\.json/)
|
94
|
+
files.each do |file|
|
95
|
+
@standards_data = standards_data.deep_merge(JSON.parse(EmbeddedScripting.getFileAsString(file)))
|
96
|
+
end
|
97
|
+
else
|
98
|
+
files = Dir.glob("#{datafolder}/**/*.json").select {|e| File.file? e}
|
99
|
+
files.each do |file|
|
100
|
+
@standards_data = standards_data.deep_merge (JSON.parse(File.read(file)))
|
101
|
+
end
|
95
102
|
end
|
96
103
|
@standards_data = @standards_data.sort_by_key(true)
|
97
104
|
return @standards_data
|
@@ -6,23 +6,34 @@ class NECB2011 < Standard
|
|
6
6
|
attr_reader :template
|
7
7
|
attr_accessor :standards_data
|
8
8
|
|
9
|
-
|
9
|
+
# Combine the data from the JSON files into a single hash
|
10
|
+
# Load JSON files differently depending on whether loading from
|
11
|
+
# the OpenStudio CLI embedded filesystem or from typical gem installation
|
10
12
|
def load_standards_database_new()
|
11
|
-
# Combine the data from the JSON files into a single hash
|
12
|
-
top_dir = File.expand_path('../../..', File.dirname(__FILE__))
|
13
|
-
standards_data_dir = "#{top_dir}/data/"
|
14
|
-
files = Dir.glob("#{File.dirname(__FILE__)}/data/*.json").select {|e| File.file? e}
|
15
13
|
@standards_data = {}
|
16
14
|
@standards_data["tables"] = []
|
17
|
-
|
18
|
-
|
19
|
-
data
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
|
16
|
+
if __dir__[0] == ':' # Running from OpenStudio CLI
|
17
|
+
embedded_files_relative('data/', /.*\.json/).each do |file|
|
18
|
+
data = JSON.parse(EmbeddedScripting.getFileAsString(file))
|
19
|
+
if not data["tables"].nil? and data["tables"].first["data_type"] =="table"
|
20
|
+
@standards_data["tables"] << data["tables"].first
|
21
|
+
else
|
22
|
+
@standards_data[data.keys.first] = data[data.keys.first]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
else
|
26
|
+
files = Dir.glob("#{File.dirname(__FILE__)}/data/*.json").select {|e| File.file? e}
|
27
|
+
files.each do |file|
|
28
|
+
data = JSON.parse(File.read(file))
|
29
|
+
if not data["tables"].nil? and data["tables"].first["data_type"] =="table"
|
30
|
+
@standards_data["tables"] << data["tables"].first
|
31
|
+
else
|
32
|
+
@standards_data[data.keys.first] = data[data.keys.first]
|
33
|
+
end
|
24
34
|
end
|
25
35
|
end
|
36
|
+
|
26
37
|
#needed for compatibility of standards database format
|
27
38
|
@standards_data['tables'].each do |table|
|
28
39
|
@standards_data[table['name']] = table
|
@@ -102,7 +113,7 @@ class NECB2011 < Standard
|
|
102
113
|
#get models weather object to get the province. Then use that to look up the province.
|
103
114
|
epw = BTAP::Environment::WeatherFile.new(model.weatherFile.get.path.get)
|
104
115
|
fuel_sources = @standards_data['tables'].detect {|table| table['name'] == 'regional_fuel_use'}['table'].detect {|fuel_sources| fuel_sources['state_province_regions'].include?(epw.state_province_region)}
|
105
|
-
raise() if fuel_sources.nil? #this should never happen since we are using only canadian weather files.
|
116
|
+
raise("Could not find fuel sources for weather file, make sure it is a Canadian weather file.") if fuel_sources.nil? #this should never happen since we are using only canadian weather files.
|
106
117
|
return fuel_sources
|
107
118
|
end
|
108
119
|
|
@@ -136,7 +147,7 @@ class NECB2011 < Standard
|
|
136
147
|
raise 'no building_type!' if @instvarbuilding_type.nil?
|
137
148
|
model = nil
|
138
149
|
# prototype generation.
|
139
|
-
model =
|
150
|
+
model = load_geometry_osm(@geometry_file) # standard candidate
|
140
151
|
model.getThermostatSetpointDualSetpoints(&:remove)
|
141
152
|
model.yearDescription.get.setDayofWeekforStartDay('Sunday')
|
142
153
|
model_add_design_days_and_weather_file(model, climate_zone, epw_file) # Standards
|
@@ -112,9 +112,9 @@ class Standard
|
|
112
112
|
@standards_data = {}
|
113
113
|
standards_files.sort.each do |standards_file|
|
114
114
|
temp = ''
|
115
|
-
|
115
|
+
if __dir__[0] == ':' # Running from OpenStudio CLI
|
116
116
|
temp = load_resource_relative("../../../data/standards/#{standards_file}", 'r:UTF-8')
|
117
|
-
|
117
|
+
else
|
118
118
|
File.open("#{standards_data_dir}/#{standards_file}", 'r:UTF-8') do |f|
|
119
119
|
temp = f.read
|
120
120
|
end
|
@@ -73,9 +73,7 @@ class Standard
|
|
73
73
|
|
74
74
|
# Define where the weather files lives
|
75
75
|
weather_dir = nil
|
76
|
-
if
|
77
|
-
# running embedded copy of the gem
|
78
|
-
|
76
|
+
if __dir__[0] == ':' # Running from OpenStudio CLI
|
79
77
|
# load weather file from embedded files
|
80
78
|
epw_string = load_resource_relative("../../../data/weather/#{weather_file_name}")
|
81
79
|
ddy_string = load_resource_relative("../../../data/weather/#{weather_file_name.gsub('.epw', '.ddy')}")
|
@@ -237,8 +235,16 @@ module BTAP
|
|
237
235
|
# this method is used to populate user interfaces if needed from the hash above.
|
238
236
|
def self.get_canadian_weather_file_names()
|
239
237
|
canadian_file_names = []
|
240
|
-
|
241
|
-
|
238
|
+
if __dir__[0] == ':' # Running from OpenStudio CLI
|
239
|
+
embedded_files_relative('../../../', /.*\.epw/).each do |file|
|
240
|
+
canadian_file_names << File.basename(file).to_s
|
241
|
+
end
|
242
|
+
else
|
243
|
+
Dir.glob("#{File.dirname(__FILE__)}/../../../**/*.epw").each do |file|
|
244
|
+
canadian_file_names << File.basename(file).to_s
|
245
|
+
puts "File.basename = #{File.basename(file)}"
|
246
|
+
puts "File.dirname = #{File.dirname(file)}"
|
247
|
+
end
|
242
248
|
end
|
243
249
|
return canadian_file_names
|
244
250
|
end
|
@@ -384,10 +390,6 @@ module BTAP
|
|
384
390
|
# @param weather_file [String]
|
385
391
|
# @return [String] self
|
386
392
|
def initialize(weather_file)
|
387
|
-
# Define the openstudio-standards weather location
|
388
|
-
top_dir = File.expand_path('../../..', File.dirname(__FILE__))
|
389
|
-
weather_dir = "#{top_dir}/data/weather"
|
390
|
-
|
391
393
|
# First check if the epw file exists at a full path. If not found there,
|
392
394
|
# check for the file in the openstudio-standards/data/weather directory.
|
393
395
|
weather_file = weather_file.to_s
|
@@ -398,12 +400,29 @@ module BTAP
|
|
398
400
|
@epw_filepath = weather_file.to_s
|
399
401
|
@ddy_filepath = weather_file.sub('epw', 'ddy').to_s
|
400
402
|
@stat_filepath = weather_file.sub('epw', 'stat').to_s
|
401
|
-
|
403
|
+
else
|
404
|
+
# Run differently depending on whether running from embedded filesystem in OpenStudio CLI or not
|
405
|
+
if __dir__[0] == ':' # Running from OpenStudio CLI
|
406
|
+
# load weather file from embedded files
|
407
|
+
epw_string = load_resource_relative("../../../data/weather/#{weather_file}")
|
408
|
+
ddy_string = load_resource_relative("../../../data/weather/#{weather_file.gsub('.epw', '.ddy')}")
|
409
|
+
stat_string = load_resource_relative("../../../data/weather/#{weather_file.gsub('.epw', '.stat')}")
|
410
|
+
|
411
|
+
# extract to local weather dir
|
412
|
+
weather_dir = File.expand_path(File.join(Dir.pwd, 'extracted_files/weather/'))
|
413
|
+
puts "Extracting weather files to #{weather_dir}"
|
414
|
+
FileUtils.mkdir_p(weather_dir)
|
415
|
+
File.open("#{weather_dir}/#{weather_file}", 'wb') { |f| f << epw_string; f.flush }
|
416
|
+
File.open("#{weather_dir}/#{weather_file.gsub('.epw', '.ddy')}", 'wb') { |f| f << ddy_string; f.flush }
|
417
|
+
File.open("#{weather_dir}/#{weather_file.gsub('.epw', '.stat')}", 'wb') { |f| f << stat_string; f.flush }
|
418
|
+
else # loaded gem from system path
|
419
|
+
top_dir = File.expand_path('../../..', File.dirname(__FILE__))
|
420
|
+
weather_dir = File.expand_path("#{top_dir}/data/weather")
|
421
|
+
end
|
422
|
+
|
402
423
|
@epw_filepath = "#{weather_dir}/#{weather_file}"
|
403
424
|
@ddy_filepath = "#{weather_dir}/#{weather_file.sub('epw', 'ddy')}"
|
404
425
|
@stat_filepath = "#{weather_dir}/#{weather_file.sub('epw', 'stat')}"
|
405
|
-
else
|
406
|
-
raise("Could not find weather file #{weather_file}. Make sure file path is correct.")
|
407
426
|
end
|
408
427
|
|
409
428
|
# Ensure that epw, ddy, and stat file all exist
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openstudio-standards
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Parker
|
@@ -21,7 +21,7 @@ authors:
|
|
21
21
|
autorequire:
|
22
22
|
bindir: bin
|
23
23
|
cert_chain: []
|
24
|
-
date: 2018-
|
24
|
+
date: 2018-04-19 00:00:00.000000000 Z
|
25
25
|
dependencies:
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: minitest-reporters
|
@@ -1630,7 +1630,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1630
1630
|
version: 1.3.6
|
1631
1631
|
requirements: []
|
1632
1632
|
rubyforge_project:
|
1633
|
-
rubygems_version: 2.
|
1633
|
+
rubygems_version: 2.7.6
|
1634
1634
|
signing_key:
|
1635
1635
|
specification_version: 4
|
1636
1636
|
summary: Creates DOE Prototype building models and transforms proposed OpenStudio
|