Class: URBANopt::Scenario::REoptScenarioCSV

Inherits:
ScenarioCSV
  • Object
show all
Defined in:
lib/urbanopt/reopt/scenario/reopt_scenario_csv.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

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 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 for an optimization at the aggregated ScenarioReport level. A REoptScenarioCSV is also instantiated with a reopt_files_dir file directory containing all REopt 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 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.



35
36
37
38
39
40
41
42
43
44
45
# 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

Instance Attribute Details

#reopt_feature_assumptionsObject

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



47
48
49
# File 'lib/urbanopt/reopt/scenario/reopt_scenario_csv.rb', line 47

def reopt_feature_assumptions
  @reopt_feature_assumptions
end

#scenario_reopt_assumptions_fileObject (readonly)

Path to json file of reopt assumptions for scenario report



50
51
52
# File 'lib/urbanopt/reopt/scenario/reopt_scenario_csv.rb', line 50

def scenario_reopt_assumptions_file
  @scenario_reopt_assumptions_file
end

Instance Method Details

#simulation_dirsObject

Gets all the simulation directories



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