Class: URBANopt::REopt::ScenarioReportAdapter

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

Instance Method Summary collapse

Constructor Details

#initializeScenarioReportAdapter

ScenarioReportAdapter can convert a ScenarioReport into a REopt Lite posts or updates a ScenarioReport and its FeatureReports from REopt Lite response(s)

parameters:


43
44
45
46
# File 'lib/urbanopt/reopt/scenario_report_adapter.rb', line 43

def initialize
  # initialize @@logger
  @@logger ||= URBANopt::REopt.reopt_logger
end

Instance Method Details

#modrow(x, i) ⇒ Object

:nodoc:



366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
# File 'lib/urbanopt/reopt/scenario_report_adapter.rb', line 366

def modrow(x, i) # :nodoc:
  x[$generation_timeseries_kwh_col] = $generation_timeseries_kwh[i] || 0
  x[$load_col] = $load[i] || 0
  x[$utility_to_load_col] = $utility_to_load[i] || 0
  x[$utility_to_battery_col] = $utility_to_battery[i] || 0
  x[$storage_to_load_col] = $storage_to_load[i] || 0
  x[$storage_to_grid_col] = $storage_to_grid[i] || 0
  x[$storage_soc_col] = $storage_soc[i] || 0
  x[$generator_total_col] = $generator_total[i] || 0
  x[$generator_to_battery_col] = $generator_to_battery[i] || 0
  x[$generator_to_load_col] = $generator_to_load[i] || 0
  x[$generator_to_grid_col] = $generator_to_grid[i] || 0
  x[$pv_total_col] = $pv_total[i] || 0
  x[$pv_to_battery_col] = $pv_to_battery[i] || 0
  x[$pv_to_load_col] = $pv_to_load[i] || 0
  x[$pv_to_grid_col] = $pv_to_grid[i] || 0
  x[$wind_total_col] = $wind_total[i] || 0
  x[$wind_to_battery_col] = $wind_to_battery[i] || 0
  x[$wind_to_load_col] = $wind_to_load[i] || 0
  x[$wind_to_grid_col] = $wind_to_grid[i] || 0
  return x
end

#reopt_json_from_scenario_report(scenario_report, reopt_assumptions_json = nil) ⇒ Object

Convert a ScenarioReport into a REopt Lite post

parameters:
  • scenario_report - URBANopt::Scenario::DefaultReports::ScenarioReport - ScenarioReport to use in converting the reopt_assumptions_hash, if provided, to a REopt Lite post. Otherwise, if the reopt_assumptions_hash is nil a default post will be updated from this ScenarioReport and submitted to the REopt Lite API.

  • reopt_assumptions_hash - Hash - Optional. A hash formatted for submittal to the REopt Lite API containing default values. Values will be overwritten from the ScenarioReport where available (i.e. latitude, roof_squarefeet). Missing optional parameters will be filled in with default values by the API.

return:

Hash - Returns hash formatted for submittal to the REopt Lite API



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
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
128
129
130
131
132
133
134
135
136
137
# File 'lib/urbanopt/reopt/scenario_report_adapter.rb', line 58

def reopt_json_from_scenario_report(scenario_report, reopt_assumptions_json = nil)
  name = scenario_report.name.delete ' '
  scenario_id = scenario_report.id.delete ' '
  description = "scenario_report_#{name}_#{scenario_id}"

  # Create base REpopt Lite post
  reopt_inputs = { Scenario: { Site: { ElectricTariff: { blended_monthly_demand_charges_us_dollars_per_kw: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], blended_monthly_rates_us_dollars_per_kwh: [0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13] }, LoadProfile: {}, Wind: { max_kw: 0 } } } }
  if !reopt_assumptions_json.nil?
    reopt_inputs = reopt_assumptions_json
  else
    @@logger.info('Using default REopt Lite assumptions')
  end

  # Update required info
  if scenario_report.location.latitude.nil? || scenario_report.location.longitude.nil? || (scenario_report.location.latitude == 0) || (scenario_report.location.longitude == 0)
    if !scenario_report.feature_reports.nil? && (scenario_report.feature_reports != [])
      lats = []
      longs = []
      scenario_report.feature_reports.each do |x|
        if ![nil, 0].include?(x[:location][:latitude]) && ![nil, 0].include?(x[:location][:longitude])
          lats.push(x[:location][:latitude])
          longs.push(x[:location][:longitude])
        end
      end

      if !lats.empty? && !longs.empty?
        scenario_report.location.latitude = lats.reduce(:+) / lats.size.to_f
        scenario_report.location.longitude = longs.reduce(:+) / longs.size.to_f
      end
    end
  end

  # Update required info
  requireds_names = ['latitude', 'longitude']
  requireds = [scenario_report.location.latitude, scenario_report.location.longitude]

  if requireds.include?(nil) || requireds.include?(0)
    requireds.each_with_index do |i, x|
      if [nil, 0].include? x
        n = requireds_names[i]
        raise "Missing value for #{n} - this is a required input"
      end
    end
  end

  reopt_inputs[:Scenario][:description] = description

  reopt_inputs[:Scenario][:Site][:latitude] = scenario_report.location.latitude
  reopt_inputs[:Scenario][:Site][:longitude] = scenario_report.location.longitude

  # Update optional info
  if !scenario_report.program.roof_area.nil?
    reopt_inputs[:Scenario][:Site][:roof_squarefeet] = scenario_report.program.roof_area[:available_roof_area]
  end

  if !scenario_report.program.site_area.nil?
    reopt_inputs[:Scenario][:Site][:land_acres] = scenario_report.program.site_area * 1.0 / 43560 # acres/sqft
  end

  # Update load profile info
  begin
    col_num = scenario_report.timeseries_csv.column_names.index('Electricity:Facility')
    t = CSV.read(scenario_report.timeseries_csv.path, headers: true, converters: :numeric)
    energy_timeseries_kwh = t.by_col[col_num].map { |e| ((e || 0) * 0.293071) } # convert kBTU to KWH

    if (scenario_report.timesteps_per_hour || 1) > 1
      energy_timeseries_kwh = energy_timeseries_kwh.each_slice(scenario_report.timesteps_per_hour).to_a.map { |x| x.inject(0, :+) / x.length.to_f }
    end

    if energy_timeseries_kwh.length < scenario_report.timesteps_per_hour * 8760
      energy_timeseries_kwh += [0] * ((scenario_report.timesteps_per_hour * 8760) - energy_timeseries_kwh.length)
      @@logger.info("Assuming load profile for Scenario Report #{scenario_report.name} #{scenario_report.id} starts January 1 - filling in rest with zeros")
    end
    reopt_inputs[:Scenario][:Site][:LoadProfile][:loads_kw] = energy_timeseries_kwh
  rescue StandardError
    raise "Could not parse the annual electric load from the timeseries csv - #{scenario_report.timeseries_csv.path}"
  end

  return reopt_inputs
end

#reopt_jsons_from_scenario_feature_reports(scenario_report, reopt_assumptions_hashes = []) ⇒ Object

Converts a FeatureReport list from a ScenarioReport into an array of REopt Lite posts

parameters:
  • scenario_report - URBANopt::Scenario::DefaultReports::ScenarioReport - ScenarioReport to use in converting FeatureReports and respecitive reopt_assumptions_hashes, if provided, to a REopt Lite post. If no reopt_assumptions_hashes are provided default posts will be updated from these FeatureReports and submitted to the REopt Lite API.

  • reopt_assumptions_hashes - Array - Optional. An array of hashes formatted for submittal to the REopt Lite API containing default values. Values will be overwritten from the ScenarioReport where available (i.e. latitude, roof_squarefeet). Missing optional parameters will be filled in with default values by the API. The order should match the list in ScenarioReport.feature_reports.

return:

Array - Returns an array of hashes formatted for submittal to the REopt Lite API in the order of the FeatureReports lited in ScenarioReport.feature_reports.



149
150
151
152
153
154
155
156
157
158
159
# File 'lib/urbanopt/reopt/scenario_report_adapter.rb', line 149

def reopt_jsons_from_scenario_feature_reports(scenario_report, reopt_assumptions_hashes = [])
  results = []
  adapter = URBANopt::REopt::FeatureReportAdapter.new

  scenario_report.feature_reports.each_with_index do |feature_report, idx|
    fr = adapter.reopt_json_from_feature_report(feature_report, reopt_assumptions_hashes[idx])
    results << fr
  end

  return results
end

#update_scenario_report(scenario_report, reopt_output, timeseries_csv_path = nil) ⇒ Object

Updates a ScenarioReport from a REopt Lite response

parameters:
  • scenario_report - URBANopt::Scenario::DefaultReports::ScenarioReport - ScenarioReport to update from a REopt Lite response.

  • reopt_output - Hash - A hash response from the REopt Lite API.

  • timeseries_csv_path - String - Optional. The path to a file at which new timeseries data will be written. If not provided a file is created based on the run_uuid of the REopt Lite optimization task.

return:

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



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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/urbanopt/reopt/scenario_report_adapter.rb', line 172

def update_scenario_report(scenario_report, reopt_output, timeseries_csv_path = nil)
  if reopt_output['outputs']['Scenario']['status'] != 'optimal'
    @@logger.info("Warning cannot Feature Report #{scenario_report.name} #{scenario_report.id}  - REopt optimization was non-optimal")
    return scenario_report
  end

  # Update location
  scenario_report.location.latitude = reopt_output['inputs']['Scenario']['Site']['latitude']
  scenario_report.location.longitude = reopt_output['inputs']['Scenario']['Site']['longitude']

  # Update timeseries csv from \REopt Lite dispatch data
  scenario_report.timesteps_per_hour = reopt_output['inputs']['Scenario']['time_steps_per_hour']

  # Update distributed generation sizing and financials
  (scenario_report.distributed_generation.lcc_us_dollars = reopt_output['outputs']['Scenario']['Site']['Financial']['lcc_us_dollars']) || 0
  (scenario_report.distributed_generation.npv_us_dollars = reopt_output['outputs']['Scenario']['Site']['Financial']['npv_us_dollars']) || 0
  (scenario_report.distributed_generation.year_one_energy_cost_us_dollars = reopt_output['outputs']['Scenario']['Site']['ElectricTariff']['year_one_energy_cost_us_dollars']) || 0
  (scenario_report.distributed_generation.year_one_demand_cost_us_dollars = reopt_output['outputs']['Scenario']['Site']['ElectricTariff']['year_one_demand_cost_us_dollars']) || 0
  (scenario_report.distributed_generation.year_one_bill_us_dollars = reopt_output['outputs']['Scenario']['Site']['ElectricTariff']['year_one_bill_us_dollars']) || 0
  (scenario_report.distributed_generation.total_energy_cost_us_dollars = reopt_output['outputs']['Scenario']['Site']['ElectricTariff']['total_energy_cost_us_dollars']) || 0

  (scenario_report.distributed_generation.solar_pv.size_kw = reopt_output['outputs']['Scenario']['Site']['PV']['size_kw']) || 0
  (scenario_report.distributed_generation.wind.size_kw = reopt_output['outputs']['Scenario']['Site']['Wind']['size_kw']) || 0
  (scenario_report.distributed_generation.generator.size_kw = reopt_output['outputs']['Scenario']['Site']['Generator']['size_kw']) || 0
  (scenario_report.distributed_generation.storage.size_kw = reopt_output['outputs']['Scenario']['Site']['Storage']['size_kw']) || 0
  (scenario_report.distributed_generation.storage.size_kwh = reopt_output['outputs']['Scenario']['Site']['Storage']['size_kwh']) || 0

  # Update dispatch
  generation_timeseries_kwh = Matrix[[0] * 8760]
  unless reopt_output['outputs']['Scenario']['Site']['PV'].nil?
    if (reopt_output['outputs']['Scenario']['Site']['PV']['size_kw'] || 0) > 0
      if !reopt_output['outputs']['Scenario']['Site']['PV']['year_one_power_production_series_kw'].nil?
        generation_timeseries_kwh += Matrix[reopt_output['outputs']['Scenario']['Site']['PV']['year_one_power_production_series_kw']]
      end
    end
  end

  # unless reopt_output['outputs']['Scenario']['Site']['Storage'].nil?
  #   if (reopt_output['outputs']['Scenario']['Site']['Storage']['size_kw'] or 0) > 0
  #     if !reopt_output['outputs']['Scenario']['Site']['Storage']['year_one_to_grid_series_kw'].nil?
  #       generation_timeseries_kwh = generation_timeseries_kwh + Matrix[reopt_output['outputs']['Scenario']['Site']['Storage']['year_one_to_grid_series_kw']]
  #     end
  #   end
  # end

  unless reopt_output['outputs']['Scenario']['Site']['Wind'].nil?
    if (reopt_output['outputs']['Scenario']['Site']['Wind']['size_kw'] || 0) > 0
      if !reopt_output['outputs']['Scenario']['Site']['Wind']['year_one_power_production_series_kw'].nil?
        generation_timeseries_kwh += Matrix[reopt_output['outputs']['Scenario']['Site']['Wind']['year_one_power_production_series_kw']]
      end
    end
  end

  unless reopt_output['outputs']['Scenario']['Site']['Generator'].nil?
    if (reopt_output['outputs']['Scenario']['Site']['Generator']['size_kw'] || 0) > 0
      if !reopt_output['outputs']['Scenario']['Site']['Generator']['year_one_power_production_series_kw'].nil?
        generation_timeseries_kwh += Matrix[reopt_output['outputs']['Scenario']['Site']['Generator']['year_one_power_production_series_kw']]
      end
    end
  end

  $generation_timeseries_kwh = generation_timeseries_kwh.to_a[0]
  $generation_timeseries_kwh_col = scenario_report.timeseries_csv.column_names.index('ElectricityProduced:Total')
  if $generation_timeseries_kwh_col.nil?
    $generation_timeseries_kwh_col = scenario_report.timeseries_csv.column_names.length
    scenario_report.timeseries_csv.column_names.push('ElectricityProduced:Total')
  end

  $load = reopt_output['outputs']['Scenario']['Site']['LoadProfile']['year_one_electric_load_series_kw'] || [0] * 8760
  $load_col = scenario_report.timeseries_csv.column_names.index('Electricity:Load:Total')
  if $load_col.nil?
    $load_col = scenario_report.timeseries_csv.column_names.length
    scenario_report.timeseries_csv.column_names.push('Electricity:Load:Total')
  end

  $utility_to_load = reopt_output['outputs']['Scenario']['Site']['ElectricTariff']['year_one_to_load_series_kw'] || [0] * 8760
  $utility_to_load_col = scenario_report.timeseries_csv.column_names.index('Electricity:Grid:ToLoad')
  if $utility_to_load_col.nil?
    $utility_to_load_col = scenario_report.timeseries_csv.column_names.length
    scenario_report.timeseries_csv.column_names.push('Electricity:Grid:ToLoad')
  end

  $utility_to_battery = reopt_output['outputs']['Scenario']['Site']['ElectricTariff']['year_one_to_battery_series_kw'] || [0] * 8760
  $utility_to_battery_col = scenario_report.timeseries_csv.column_names.index('Electricity:Grid:ToBattery')
  if $utility_to_battery_col.nil?
    $utility_to_battery_col = scenario_report.timeseries_csv.column_names.length
    scenario_report.timeseries_csv.column_names.push('Electricity:Grid:ToBattery')
  end

  $storage_to_load = reopt_output['outputs']['Scenario']['Site']['Storage']['year_one_to_load_series_kw'] || [0] * 8760
  $storage_to_load_col = scenario_report.timeseries_csv.column_names.index('Electricity:Storage:ToLoad')
  if $storage_to_load_col.nil?
    $storage_to_load_col = scenario_report.timeseries_csv.column_names.length
    scenario_report.timeseries_csv.column_names.push('Electricity:Storage:ToLoad')
  end

  $storage_to_grid = reopt_output['outputs']['Scenario']['Site']['Storage']['year_one_to_grid_series_kw'] || [0] * 8760
  $storage_to_grid_col = scenario_report.timeseries_csv.column_names.index('Electricity:Storage:ToGrid')
  if $storage_to_grid_col.nil?
    $storage_to_grid_col = scenario_report.timeseries_csv.column_names.length
    scenario_report.timeseries_csv.column_names.push('Electricity:Storage:ToGrid')
  end

  $storage_soc = reopt_output['outputs']['Scenario']['Site']['Storage']['year_one_soc_series_pct'] || [0] * 8760
  $storage_soc_col = scenario_report.timeseries_csv.column_names.index('Electricity:Storage:StateOfCharge')
  if $storage_soc_col.nil?
    $storage_soc_col = scenario_report.timeseries_csv.column_names.length
    scenario_report.timeseries_csv.column_names.push('Electricity:Storage:StateOfCharge')
  end

  $generator_total = reopt_output['outputs']['Scenario']['Site']['Generator']['year_one_power_production_series_kw'] || [0] * 8760
  $generator_total_col = scenario_report.timeseries_csv.column_names.index('ElectricityProduced:Generator:Total')
  if $generator_total_col.nil?
    $generator_total_col = scenario_report.timeseries_csv.column_names.length
    scenario_report.timeseries_csv.column_names.push('ElectricityProduced:Generator:Total')
  end

  $generator_to_battery = reopt_output['outputs']['Scenario']['Site']['Generator']['year_one_to_battery_series_kw'] || [0] * 8760
  $generator_to_battery_col = scenario_report.timeseries_csv.column_names.index('ElectricityProduced:Generator:ToBattery')
  if $generator_to_battery_col.nil?
    $generator_to_battery_col = scenario_report.timeseries_csv.column_names.length
    scenario_report.timeseries_csv.column_names.push('ElectricityProduced:Generator:ToBattery')
  end

  $generator_to_load = reopt_output['outputs']['Scenario']['Site']['Generator']['year_one_to_load_series_kw'] || [0] * 8760
  $generator_to_load_col = scenario_report.timeseries_csv.column_names.index('ElectricityProduced:Generator:ToLoad')
  if $generator_to_load_col.nil?
    $generator_to_load_col = scenario_report.timeseries_csv.column_names.length
    scenario_report.timeseries_csv.column_names.push('ElectricityProduced:Generator:ToLoad')
  end

  $generator_to_grid = reopt_output['outputs']['Scenario']['Site']['Generator']['year_one_to_grid_series_kw'] || [0] * 8760
  $generator_to_grid_col = scenario_report.timeseries_csv.column_names.index('ElectricityProduced:Generator:ToGrid')
  if $generator_to_grid_col.nil?
    $generator_to_grid_col = scenario_report.timeseries_csv.column_names.length
    scenario_report.timeseries_csv.column_names.push('ElectricityProduced:Generator:ToGrid')
  end

  $pv_total = reopt_output['outputs']['Scenario']['Site']['PV']['year_one_power_production_series_kw'] || [0] * 8760
  $pv_total_col = scenario_report.timeseries_csv.column_names.index('ElectricityProduced:PV:Total')
  if $pv_total_col.nil?
    $pv_total_col = scenario_report.timeseries_csv.column_names.length
    scenario_report.timeseries_csv.column_names.push('ElectricityProduced:PV:Total')
  end

  $pv_to_battery = reopt_output['outputs']['Scenario']['Site']['PV']['year_one_to_battery_series_kw'] || [0] * 8760
  $pv_to_battery_col = scenario_report.timeseries_csv.column_names.index('ElectricityProduced:PV:ToBattery')
  if $pv_to_battery_col.nil?
    $pv_to_battery_col = scenario_report.timeseries_csv.column_names.length
    scenario_report.timeseries_csv.column_names.push('ElectricityProduced:PV:ToBattery')
  end

  $pv_to_load = reopt_output['outputs']['Scenario']['Site']['PV']['year_one_to_load_series_kw'] || [0] * 8760
  $pv_to_load_col = scenario_report.timeseries_csv.column_names.index('ElectricityProduced:PV:ToLoad')
  if $pv_to_load_col.nil?
    $pv_to_load_col = scenario_report.timeseries_csv.column_names.length
    scenario_report.timeseries_csv.column_names.push('ElectricityProduced:PV:ToLoad')
  end

  $pv_to_grid = reopt_output['outputs']['Scenario']['Site']['PV']['year_one_to_grid_series_kw'] || [0] * 8760
  $pv_to_grid_col = scenario_report.timeseries_csv.column_names.index('ElectricityProduced:PV:ToGrid')
  if $pv_to_grid_col.nil?
    $pv_to_grid_col = scenario_report.timeseries_csv.column_names.length
    scenario_report.timeseries_csv.column_names.push('ElectricityProduced:PV:ToGrid')
  end

  $wind_total = reopt_output['outputs']['Scenario']['Site']['Wind']['year_one_power_production_series_kw'] || [0] * 8760
  $wind_total_col = scenario_report.timeseries_csv.column_names.index('ElectricityProduced:Wind:Total')
  if $wind_total_col.nil?
    $wind_total_col = scenario_report.timeseries_csv.column_names.length
    scenario_report.timeseries_csv.column_names.push('ElectricityProduced:Wind:Total')
  end

  $wind_to_battery = reopt_output['outputs']['Scenario']['Site']['Wind']['year_one_to_battery_series_kw'] || [0] * 8760
  $wind_to_battery_col = scenario_report.timeseries_csv.column_names.index('ElectricityProduced:Wind:ToBattery')
  if $wind_to_battery_col.nil?
    $wind_to_battery_col = scenario_report.timeseries_csv.column_names.length
    scenario_report.timeseries_csv.column_names.push('ElectricityProduced:Wind:ToBattery')
  end

  $wind_to_load = reopt_output['outputs']['Scenario']['Site']['Wind']['year_one_to_load_series_kw'] || [0] * 8760
  $wind_to_load_col = scenario_report.timeseries_csv.column_names.index('ElectricityProduced:Wind:ToLoad')
  if $wind_to_load_col.nil?
    $wind_to_load_col = scenario_report.timeseries_csv.column_names.length
    scenario_report.timeseries_csv.column_names.push('ElectricityProduced:Wind:ToLoad')
  end

  $wind_to_grid = reopt_output['outputs']['Scenario']['Site']['Wind']['year_one_to_grid_series_kw'] || [0] * 8760
  $wind_to_grid_col = scenario_report.timeseries_csv.column_names.index('ElectricityProduced:Wind:ToGrid')
  if $wind_to_grid_col.nil?
    $wind_to_grid_col = scenario_report.timeseries_csv.column_names.length
    scenario_report.timeseries_csv.column_names.push('ElectricityProduced:Wind:ToGrid')
  end

  def modrow(x, i) # :nodoc:
    x[$generation_timeseries_kwh_col] = $generation_timeseries_kwh[i] || 0
    x[$load_col] = $load[i] || 0
    x[$utility_to_load_col] = $utility_to_load[i] || 0
    x[$utility_to_battery_col] = $utility_to_battery[i] || 0
    x[$storage_to_load_col] = $storage_to_load[i] || 0
    x[$storage_to_grid_col] = $storage_to_grid[i] || 0
    x[$storage_soc_col] = $storage_soc[i] || 0
    x[$generator_total_col] = $generator_total[i] || 0
    x[$generator_to_battery_col] = $generator_to_battery[i] || 0
    x[$generator_to_load_col] = $generator_to_load[i] || 0
    x[$generator_to_grid_col] = $generator_to_grid[i] || 0
    x[$pv_total_col] = $pv_total[i] || 0
    x[$pv_to_battery_col] = $pv_to_battery[i] || 0
    x[$pv_to_load_col] = $pv_to_load[i] || 0
    x[$pv_to_grid_col] = $pv_to_grid[i] || 0
    x[$wind_total_col] = $wind_total[i] || 0
    x[$wind_to_battery_col] = $wind_to_battery[i] || 0
    x[$wind_to_load_col] = $wind_to_load[i] || 0
    x[$wind_to_grid_col] = $wind_to_grid[i] || 0
    return x
  end

  old_data = CSV.open(scenario_report.timeseries_csv.path).read
  mod_data = old_data.map.with_index do |x, i|
    if i > 0
      modrow(x, i)
    else
      x
    end
  end
  mod_data[0] = scenario_report.timeseries_csv.column_names

  scenario_report.timeseries_csv.reload_data(mod_data)
  return scenario_report
end