class URBANopt::Scenario::REoptScenarioCSV

Attributes

reopt_feature_assumptions[RW]

Path to json files of reopt assumptions for feature reports ordered by feature order

Public Class Methods

new(name, root_dir, run_dir, feature_file, mapper_files_dir, csv_file, num_header_rows, reopt_files_dir = nil, scenario_reopt_assumptions_file_name = nil) click to toggle source

REoptScenarioCSV is an extension of ScenarioCSV which assigns a Simulation Mapper to each Feature in a FeatureFile using a simple CSV format. The a REopt Lite enabled CSV file has four columns 1) feature_id, 2) feature_name, 3) mapper_class_name and 4) optional reopt assumptions file name. There is one row for each Feature. A REoptScenarioCSV can be instantiated with set of assumptions to use in REopt Lite for an optimization at the aggregated ScenarioReport level. A REoptScenarioCSV is also instantiated with a reopt_files_dir file directory containing all REopt Lite assumptions files (required only if the ScenarioReport or its FeatureReports will have specified assumptions).

[parameters:]

  • name - String - Human readable scenario name.

  • root_dir - String - Root directory for the scenario, contains Gemfile describing dependencies.

  • run_dir - String - Directory for simulation of this scenario, deleting run directory clears the scenario.

  • feature_file - URBANopt::Core::FeatureFile - FeatureFile containing features to simulate.

  • mapper_files_dir - String - Directory containing all mapper class files containing MapperBase definitions.

  • csv_file - String - Path to CSV file assigning a MapperBase class to each feature in feature_file.

  • num_header_rows - String - Number of header rows to skip in CSV file.

  • reopt_files_dir - String - Path to folder containing default REopt Lite assumptions JSON's.

  • scenario_reopt_assumptions_file_name - String - Name of .json file in the reopt_files_dir location to use in assessing the aggregated ScenarioReport in REopt Lite.

Calls superclass method
# File lib/urbanopt/reopt/scenario/reopt_scenario_csv.rb, line 35
def initialize(name, root_dir, run_dir, feature_file, mapper_files_dir, csv_file, num_header_rows, reopt_files_dir = nil, scenario_reopt_assumptions_file_name = nil)
  super(name, root_dir, run_dir, feature_file, mapper_files_dir, csv_file, num_header_rows)

  @reopt_files_dir = reopt_files_dir
  @reopt_feature_assumptions = []
  @scenario_reopt_assumptions_file = nil

  if !reopt_files_dir.nil? && !scenario_reopt_assumptions_file_name.nil?
    @scenario_reopt_assumptions_file = File.join(@reopt_files_dir, scenario_reopt_assumptions_file_name)
  end
end

Public Instance Methods

simulation_dirs() click to toggle source

Gets all the simulation directories

# File lib/urbanopt/reopt/scenario/reopt_scenario_csv.rb, line 53
def simulation_dirs
  # DLM: TODO use HeaderConverters from CSV module
  rows_skipped = 0
  result = []
  CSV.foreach(@csv_file).with_index do |row, idx|
    if rows_skipped < @num_header_rows
      rows_skipped += 1
      next
    end

    break if row[0].nil?

    # gets +feature_id+ , +feature_name+ and +mapper_class+ from csv_file
    feature_id = row[0].chomp
    feature_name = row[1].chomp
    mapper_class = row[2].chomp
    # Assume fourth columns, if exists, contains the name of the JSON file in the reopt_files_dir to use when running \REopt Lite for the feature report

    if row.length > 3 && !@reopt_files_dir.nil?
      @reopt_feature_assumptions[idx - 1] = File.join(@reopt_files_dir, row[3].chomp)
    end
    
    # gets +features+ from the feature_file.
    features = []
    feature = feature_file.get_feature_by_id(feature_id)
    features << feature

    feature_names = []
    feature_names << feature_name
    simulation_dir = SimulationDirOSW.new(self, features, feature_names, mapper_class)

    result << simulation_dir
  end
  return result
end