Class: URBANopt::RNM::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/urbanopt/rnm/runner.rb

Overview

Runner class handles running a scenario through RNM-US and retrieving results

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, run_dir, scenario_csv_path, feature_file_path, extended_catalog_path: nil, average_peak_catalog_path: nil, reopt: false, opendss_catalog: true) ⇒ Runner

Initialize Runner attributes: name , root directory , run directory and feature_file_path

parameters:
  • name - String - Human readable scenario name.

  • run_dir - String - Full path to directory for simulation of this scenario

  • feature_file_path - String - Full path to GeoJSON feature file containing features and streets for simulation.

  • scenario_csv_path - String - Full path to the Scenario CSV file containing list of features to run for this scenario.

  • extended_catalog_path - String - Full path to the extended catalog

  • average_peak_catalog_path - String - Full path to average peak catalog

  • reopt - Boolean - Use REopt results to generate inputs? Defaults to false

  • opendss_catalog - Boolean - Generate OpenDSS catalog? Defaults to true



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
# File 'lib/urbanopt/rnm/runner.rb', line 25

def initialize(name, run_dir, scenario_csv_path, feature_file_path, extended_catalog_path: nil, average_peak_catalog_path: nil, reopt: false, opendss_catalog: true)
  @name = name
  # these are all absolute paths
  @run_dir = run_dir
  @feature_file_path = feature_file_path
  @scenario_csv_path = scenario_csv_path
  @api_client = nil
  @rnm_dirname = 'rnm-us'
  @rnm_dir = File.join(@run_dir, @rnm_dirname)
  @reopt = reopt
  @extended_catalog_path = extended_catalog_path
  @average_peak_catalog_path = average_peak_catalog_path
  @opendss_catalog = opendss_catalog
  @results = []

  # load feature file
  @feature_file = JSON.parse(File.read(@feature_file_path))

  # process CSV to get feature IDs only
  @scenario_features = get_scenario_features

  # set default catalog paths if they are nil
  if @extended_catalog_path.nil?
    @extended_catalog_path = File.join(File.dirname(__FILE__), '..', '..', '..', 'catalogs', 'extended_catalog.json')
  end
  if @average_peak_catalog_path.nil?
    @average_peak_catalog_path = File.join(File.dirname(__FILE__), '..', '..', '..', 'catalogs', 'average_peak_per_building_type.json')
  end

  # initialize @@logger
  @@logger ||= URBANopt::RNM.logger

  # puts "REOPT: #{@reopt}, OPENDSS_CATALOG: #{@opendss_catalog}"
end

Instance Attribute Details

#average_peak_catalog_pathObject (readonly)

Feature file path associated with this Scenario.



82
83
84
# File 'lib/urbanopt/rnm/runner.rb', line 82

def average_peak_catalog_path
  @average_peak_catalog_path
end

#extended_catalog_pathObject (readonly)

Feature file path associated with this Scenario.



86
87
88
# File 'lib/urbanopt/rnm/runner.rb', line 86

def extended_catalog_path
  @extended_catalog_path
end

#feature_file_pathObject (readonly)

Feature file path associated with this Scenario.



70
71
72
# File 'lib/urbanopt/rnm/runner.rb', line 70

def feature_file_path
  @feature_file_path
end

#nameObject (readonly)

Name of the Scenario.



62
63
64
# File 'lib/urbanopt/rnm/runner.rb', line 62

def name
  @name
end

#reoptObject (readonly)

Feature file path associated with this Scenario.



78
79
80
# File 'lib/urbanopt/rnm/runner.rb', line 78

def reopt
  @reopt
end

#run_dirObject (readonly)

Directory to run this Scenario.



66
67
68
# File 'lib/urbanopt/rnm/runner.rb', line 66

def run_dir
  @run_dir
end

#scenario_csv_pathObject (readonly)

Scenario CSV path associated with this Scenario.



74
75
76
# File 'lib/urbanopt/rnm/runner.rb', line 74

def scenario_csv_path
  @scenario_csv_path
end

Instance Method Details

#create_simulation_filesObject

Create RNM-US Input Files



106
107
108
109
110
# File 'lib/urbanopt/rnm/runner.rb', line 106

def create_simulation_files
  # generate RNM-US input files
  in_files = URBANopt::RNM::InputFiles.new(@run_dir, @scenario_features, @feature_file, @extended_catalog_path, @average_peak_catalog_path, reopt: @reopt, opendss_catalog: @opendss_catalog)
  in_files.create
end

#download_results(sim_id = nil) ⇒ Object

Download results for a simulation separately



128
129
130
# File 'lib/urbanopt/rnm/runner.rb', line 128

def download_results(sim_id = nil)
  @api_client.download_results(sim_id)
end

#get_scenario_featuresObject

Get Scenario Features



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/urbanopt/rnm/runner.rb', line 91

def get_scenario_features
  @num_header_rows = 1
  features = []
  CSV.foreach(@scenario_csv_path, headers: true) do |row|
    break if row[0].nil?

    # gets +feature_id+ and append to list
    features << row[0].chomp
  end
  return features
end

#post_processObject

Post-process results back into scenario json file



135
136
137
138
# File 'lib/urbanopt/rnm/runner.rb', line 135

def post_process
  @rnm_pp = URBANopt::RNM::PostProcessor.new(@results, @run_dir, @feature_file)
  @rnm_pp.post_process
end

#run(use_local = false) ⇒ Object

Run RNM-US Simulation (via RNM-US api) and get results

parameters:
  • use_local - Boolean - Flag to use localhost API vs production API



117
118
119
120
121
122
123
# File 'lib/urbanopt/rnm/runner.rb', line 117

def run(use_local = false)
  # start client
  @api_client = URBANopt::RNM::ApiClient.new(@name, @rnm_dir, use_localhost = use_local, reopt = @reopt)
  @api_client.zip_input_files
  @api_client.submit_simulation
  @results = @api_client.get_results
end

#run_validationObject

Run OpenDSS validation



144
145
146
147
148
# File 'lib/urbanopt/rnm/runner.rb', line 144

def run_validation
  # generate RNM-US input files
  validation = URBANopt::RNM::Validation.new(@run_dir)
  validation.run_validation
end