Class: URBANopt::REopt::REoptPostProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/urbanopt/reopt/reopt_post_processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scenario_report, scenario_reopt_assumptions_file = nil, reopt_feature_assumptions = [], nrel_developer_key = nil, localhost = false) ⇒ REoptPostProcessor

REoptPostProcessor updates a ScenarioReport or FeatureReport based on REopt Lite optimization response.

parameters:
  • scenario_report - ScenarioReport - Optional. A scenario report that has been returned from the URBANopt::Scenario::ScenarioDefaultPostProcessor - used in creating default output file names in REopt Lite optimizations.

  • scenario_reopt_assumptions_file - String - Optional. JSON file formatted for a REopt Lite analysis containing custom input parameters for optimizations at the Scenario Report level

  • reopt_feature_assumptions - Array - Optional. A list of JSON file formatted for a REopt Lite analysis containing custom input parameters for optimizations at the Feature Report level. The order and number of files must match the Feature Reports in the scenario_report input.

  • use_localhost - Bool - If this is true, requests will be sent to a version of the REopt Lite API running on localhost. Default is false, such that the production version of REopt Lite is accessed.

  • nrel_developer_key - String - API used to access the REopt Lite APi. Required only if localhost is false. Obtain from developer.nrel.gov/signup/



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
# File 'lib/urbanopt/reopt/reopt_post_processor.rb', line 52

def initialize(scenario_report, scenario_reopt_assumptions_file = nil, reopt_feature_assumptions = [], nrel_developer_key = nil, localhost = false)
  # initialize @@logger
  @@logger ||= URBANopt::REopt.reopt_logger

  if reopt_feature_assumptions.nil?
    reopt_feature_assumptions = []
  end
  @nrel_developer_key = nrel_developer_key
  @localhost = localhost
  @reopt_base_post = { Scenario: { Site: { ElectricTariff: {}, LoadProfile: {}, Wind: { max_kw: 0 } } } }

  @scenario_reopt_default_output_file = nil
  @scenario_timeseries_default_output_file = nil
  @scenario_reopt_default_assumptions_hash = nil
  @feature_reports_reopt_default_assumption_hashes = []
  @feature_reports_reopt_default_output_files = []
  @feature_reports_timeseries_default_output_files = []

  if !scenario_report.nil?
    @scenario_report = scenario_report

    @scenario_reopt_default_output_file = File.join(@scenario_report.directory_name, "scenario_report_#{@scenario_report.id}_reopt_run.json")
    @scenario_timeseries_default_output_file = File.join(@scenario_report.directory_name, "scenario_report_#{@scenario_report.id}_timeseries.csv")

    @scenario_report.feature_reports.each do |fr|
      @feature_reports_reopt_default_output_files << File.join(fr.directory_name, "feature_report_#{fr.id}_reopt_run.json")
    end

    @scenario_report.feature_reports.each do |fr|
      @feature_reports_timeseries_default_output_files << File.join(fr.directory_name, "feature_report_#{fr.id}_timeseries.csv")
    end
  end

  if !scenario_reopt_assumptions_file.nil?
    File.open(scenario_reopt_assumptions_file, 'r') do |file|
      @scenario_reopt_default_assumptions_hash = JSON.parse(file.read, symbolize_names: true)
    end
  end

  if !reopt_feature_assumptions.empty?
    reopt_feature_assumptions.each do |file|
      @feature_reports_reopt_default_assumption_hashes << JSON.parse(File.open(file, 'r').read, symbolize_names: true)
    end
  end
end

Instance Attribute Details

#feature_reports_reopt_default_assumption_hashesObject

Returns the value of attribute feature_reports_reopt_default_assumption_hashes.



99
100
101
# File 'lib/urbanopt/reopt/reopt_post_processor.rb', line 99

def feature_reports_reopt_default_assumption_hashes
  @feature_reports_reopt_default_assumption_hashes
end

#feature_reports_reopt_default_output_filesObject

Returns the value of attribute feature_reports_reopt_default_output_files.



99
100
101
# File 'lib/urbanopt/reopt/reopt_post_processor.rb', line 99

def feature_reports_reopt_default_output_files
  @feature_reports_reopt_default_output_files
end

#feature_reports_timeseries_default_output_filesObject

Returns the value of attribute feature_reports_timeseries_default_output_files.



99
100
101
# File 'lib/urbanopt/reopt/reopt_post_processor.rb', line 99

def feature_reports_timeseries_default_output_files
  @feature_reports_timeseries_default_output_files
end

#scenario_reopt_default_assumptions_hashObject

Returns the value of attribute scenario_reopt_default_assumptions_hash.



98
99
100
# File 'lib/urbanopt/reopt/reopt_post_processor.rb', line 98

def scenario_reopt_default_assumptions_hash
  @scenario_reopt_default_assumptions_hash
end

#scenario_reopt_default_output_fileObject

Returns the value of attribute scenario_reopt_default_output_file.



98
99
100
# File 'lib/urbanopt/reopt/reopt_post_processor.rb', line 98

def scenario_reopt_default_output_file
  @scenario_reopt_default_output_file
end

#scenario_timeseries_default_output_fileObject

Returns the value of attribute scenario_timeseries_default_output_file.



98
99
100
# File 'lib/urbanopt/reopt/reopt_post_processor.rb', line 98

def scenario_timeseries_default_output_file
  @scenario_timeseries_default_output_file
end

Instance Method Details

#run_feature_report(feature_report, reopt_assumptions_hash = nil, reopt_output_file = nil, timeseries_csv_path = nil) ⇒ Object

Updates a FeatureReport based on an optional set of REopt Lite optimization assumptions.

parameters:
  • feature_report - URBANopt::Scenario::DefaultReports::FeatureReport - FeatureReport which will be used in creating and then updated by a REopt Lite opimization response.

  • reopt_assumptions_hash - Hash - Optional. A REopt Lite formatted hash containing default parameters (i.e. utility rate, escalation rate) which will be updated by the FeatureReport (i.e. location, roof availability)

  • reopt_output_file - String - Optional. Path to a file at which REpopt Lite responses will be saved.

  • timeseries_csv_path - String - Optional. Path to a file at which the new timeseries CSV for the FeatureReport will be saved.

return:

URBANopt::Scenario::DefaultReports::FeatureReport - Returns an updated FeatureReport



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/urbanopt/reopt/reopt_post_processor.rb', line 114

def run_feature_report(feature_report, reopt_assumptions_hash = nil, reopt_output_file = nil, timeseries_csv_path = nil)
  api = URBANopt::REopt::REoptLiteAPI.new(@nrel_developer_key, @localhost)
  adapter = URBANopt::REopt::FeatureReportAdapter.new

  reopt_input = adapter.reopt_json_from_feature_report(feature_report, reopt_assumptions_hash)
  if reopt_output_file.nil?
    reopt_output_file = feature_report.directory_name
  end
  reopt_output = api.reopt_request(reopt_input, reopt_output_file)
  return adapter.update_feature_report(feature_report, reopt_output, timeseries_csv_path)
end

#run_feature_reports(feature_reports, reopt_assumptions_hashes = [], reopt_output_files = [], timeseries_csv_paths = []) ⇒ Object

Updates a set of FeatureReports based on an optional set of REopt Lite optimization assumptions.

parameters:
  • feature_reports - Array - An array of URBANopt::Scenario::DefaultReports::FeatureReport objetcs which will each be used to create (and are subsquently updated by) a REopt Lite opimization response.

  • reopt_assumptions_hashes - Array - Optional. An array of REopt Lite formatted hashes containing default parameters (i.e. utility rate, escalation rate) which will be updated by the ScenarioReport (i.e. location, roof availability). The number and order of the hashes should match the feature_reports array.

  • reopt_output_files - Array - Optional. A array of paths to files at which REpopt Lite responses will be saved. The number and order of the paths should match the feature_reports array.

  • timeseries_csv_path - Array - Optional. A array of paths to files at which the new timeseries CSV for the FeatureReports will be saved. The number and order of the paths should match the feature_reports array.

return:

Array Returns an array of updated URBANopt::Scenario::DefaultReports::FeatureReport objects



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
# File 'lib/urbanopt/reopt/reopt_post_processor.rb', line 170

def run_feature_reports(feature_reports, reopt_assumptions_hashes = [], reopt_output_files = [], timeseries_csv_paths = [])
  if !reopt_assumptions_hashes.empty?
    @feature_reports_reopt_default_assumption_hashes = reopt_assumptions_hashes
  end

  if !reopt_output_files.empty?
    @feature_reports_reopt_default_output_files = reopt_output_files
  end

  if !timeseries_csv_paths.empty?
    @feature_reports_timeseries_default_output_files = timeseries_csv_paths
  end

  if @feature_reports_reopt_default_output_files.empty?
    feature_reports.each do |fr|
      @feature_reports_reopt_default_output_files << File.join(fr.directory_name, "feature_report_#{fr.id}_reopt_run.json")
    end
  end

  if @feature_reports_timeseries_default_output_files.empty?
    feature_reports.each do |fr|
      @feature_reports_timeseries_default_output_files << File.join(fr.directory_name, "feature_report_#{fr.id}_timeseries.csv")
    end
  end

  api = URBANopt::REopt::REoptLiteAPI.new(@nrel_developer_key, @localhost)
  feature_adapter = URBANopt::REopt::FeatureReportAdapter.new
  new_feature_reports = []
  feature_reports.each_with_index do |feature_report, idx|
    begin
      reopt_input = feature_adapter.reopt_json_from_feature_report(feature_report, @feature_reports_reopt_default_assumption_hashes[idx])
      if reopt_output_files[idx].nil?
        reopt_output_files[idx] = feature_report.directory_name
      end
      reopt_output = api.reopt_request(reopt_input, @feature_reports_reopt_default_output_files[idx])
      new_feature_report = feature_adapter.update_feature_report(feature_report, reopt_output, @feature_reports_timeseries_default_output_files[idx])
      new_feature_reports.push(new_feature_report)
    rescue StandardError
      @@logger.info("Could not optimize Feature Report #{feature_report.name} #{feature_report.id}")
    end
  end

  return new_feature_reports
end

#run_scenario_report(scenario_report, reopt_assumptions_hash = nil, reopt_output_file = nil, timeseries_csv_path = nil) ⇒ Object

Updates a ScenarioReport based on an optional set of REopt Lite optimization assumptions.

parameters:
  • feature_report - URBANopt::Scenario::DefaultReports::ScenarioReport - ScenarioReport which will be used in creating and then updated by a REopt Lite opimization response.

  • reopt_assumptions_hash - Hash - Optional. A REopt Lite formatted hash containing default parameters (i.e. utility rate, escalation rate) which will be updated by the ScenarioReport (i.e. location, roof availability)

  • reopt_output_file - String - Optional. Path to a file at which REpopt Lite responses will be saved.

  • timeseries_csv_path - String - Optional. Path to a file at which the new timeseries CSV for the ScenarioReport will be saved.

return:

URBANopt::Scenario::DefaultReports::ScenarioReport Returns an updated ScenarioReport



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/urbanopt/reopt/reopt_post_processor.rb', line 138

def run_scenario_report(scenario_report, reopt_assumptions_hash = nil, reopt_output_file = nil, timeseries_csv_path = nil)
  if !reopt_assumptions_hash.nil?
    @scenario_reopt_default_assumptions_hash = reopt_assumptions_hash
  end
  if !reopt_output_file.nil?
    @scenario_reopt_default_output_file = reopt_output_file
  end
  if !timeseries_csv_path.nil?
    @scenario_timeseries_default_output_file = timeseries_csv_path
  end

  api = URBANopt::REopt::REoptLiteAPI.new(@nrel_developer_key, @localhost)
  adapter = URBANopt::REopt::ScenarioReportAdapter.new

  reopt_input = adapter.reopt_json_from_scenario_report(scenario_report, @scenario_reopt_default_assumptions_hash)

  reopt_output = api.reopt_request(reopt_input, @scenario_reopt_default_output_file)

  return adapter.update_scenario_report(scenario_report, reopt_output, @scenario_timeseries_default_output_file)
end

#run_scenario_report_features(scenario_report, reopt_assumptions_hashes = [], reopt_output_files = [], feature_report_timeseries_csv_paths = []) ⇒ Object

Updates a ScenarioReport based on an optional set of REopt Lite optimization assumptions.

parameters:
  • scenario_report - Array - A URBANopt::Scenario::DefaultReports::ScenarioReport which will each be used to create (and is subsquently updated by) REopt Lite opimization responses for each of its FeatureReports.

  • reopt_assumptions_hashes - Array - Optional. An array of REopt Lite formatted hashes containing default parameters (i.e. utility rate, escalation rate) which will be updated by the ScenarioReport (i.e. location, roof availability). The number and order of the hashes should match the array in ScenarioReport.feature_reports.

  • reopt_output_files - Array - Optional. An array of paths to files at which REpopt Lite responses will be saved. The number and order of the paths should match the array in ScenarioReport.feature_reports.

  • feature_report_timeseries_csv_paths - Array - Optional. An array of paths to files at which the new timeseries CSV for the FeatureReports will be saved. The number and order of the paths should match the array in ScenarioReport.feature_reports.

return:

URBANopt::Scenario::DefaultReports::ScenarioReport - Returns an updated ScenarioReport



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/urbanopt/reopt/reopt_post_processor.rb', line 226

def run_scenario_report_features(scenario_report, reopt_assumptions_hashes = [], reopt_output_files = [], feature_report_timeseries_csv_paths = [])
  new_feature_reports = run_feature_reports(scenario_report.feature_reports, reopt_assumptions_hashes, reopt_output_files, feature_report_timeseries_csv_paths)

  new_scenario_report = URBANopt::Scenario::DefaultReports::ScenarioReport.new
  new_scenario_report.id = scenario_report.id
  new_scenario_report.name = scenario_report.name
  new_scenario_report.directory_name = scenario_report.directory_name

  timeseries_hash = { column_names: scenario_report.timeseries_csv.column_names }
  new_scenario_report.timeseries_csv = URBANopt::Scenario::DefaultReports::TimeseriesCSV.new(timeseries_hash)

  new_feature_reports.each do |feature_report|
    new_scenario_report.add_feature_report(feature_report)
  end

  return new_scenario_report
end