Method: URBANopt::Scenario::HoneybeeMapper#create_osw

Defined in:
lib/files/Honeybee.rb

#create_osw(scenario, features, feature_names) ⇒ Object



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
# File 'lib/files/Honeybee.rb', line 75

def create_osw(scenario, features, feature_names)

  if features.size != 1
    raise "Mapper currently cannot simulate more than one feature at a time."
  end
  feature = features[0]
  feature_id = feature.id
  feature_type = feature.type
  feature_name = feature.name

  # 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
  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))

  # set the name and description of the OSW to reference this particular feature
  osw[:name] = feature_name
  osw[:description] = feature_name

  if feature_type == 'Building'
      # set the honeybee JSON key to the honeybee_model measure
      OpenStudio::Extension.set_measure_argument(
          osw, 'from_honeybee_model', 'model_json', feature.detailed_model_filename)

      # add any of the mapper measure variables
      if not @@mapper_measures.nil?
        @@mapper_measures.each do |map_measure_param|
          # get the attribute from the feature
          feature_param = feature.send(map_measure_param[2])
          # set the measure argument
          OpenStudio::Extension.set_measure_argument(
            osw, map_measure_param[0], map_measure_param[1], feature_param)
        end
      end

      # add the feature id and name to the reporting measure
      OpenStudio::Extension.set_measure_argument(
        osw, 'default_feature_reports', 'feature_id', feature_id)
      OpenStudio::Extension.set_measure_argument(
        osw, 'default_feature_reports', 'feature_name', feature_name)
      OpenStudio::Extension.set_measure_argument(
        osw, 'default_feature_reports', 'feature_type', feature_type)
      OpenStudio::Extension.set_measure_argument(
        osw, 'default_feature_reports', 'feature_location', feature_location)

  end
  return osw
end