-
Notifications
You must be signed in to change notification settings - Fork 16
/
Rakefile
797 lines (650 loc) · 28.8 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
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
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
# *********************************************************************************
# URBANopt (tm), Copyright (c) Alliance for Sustainable Energy, LLC.
# See also https://github.com/urbanopt/urbanopt-example-geojson-project/blob/develop/LICENSE.md
# *********************************************************************************
require 'openstudio/extension'
require 'openstudio/extension/rake_task'
require 'rubocop/rake_task'
require 'urbanopt/scenario'
require 'urbanopt/geojson'
require 'urbanopt/reopt'
require 'urbanopt/reopt_scenario'
require_relative 'developer_nrel_key'
RuboCop::RakeTask.new
module URBANopt
module ExampleGeoJSONProject
class ExampleGeoJSONProject < OpenStudio::Extension::Extension
# number of datapoints(features) you want to run in parallel
# based on the number of available processors on your local machine.
# This does not seem to function, instead added line to code for runner.config file
# OpenStudio::Extension::Extension::NUM_PARALLEL = 7
# set MAX_DATAPOINTS
OpenStudio::Extension::Extension::MAX_DATAPOINTS = 1000
def initialize
super
@root_dir = File.absolute_path(File.join(File.dirname(__FILE__), 'example_project'))
end
# Return the absolute path of the measures or empty string if there is none, can be used when configuring OSWs
def measures_dir
''
end
# Relevant files such as weather data, design days, etc.
# Return the absolute path of the files or nil if there is none, used when configuring OSWs
def files_dir
return File.absolute_path(File.join(@root_dir, 'weather'))
end
end
end
end
def root_dir
return File.join(File.dirname(__FILE__), 'example_project')
end
def baseline_scenario(json, csv)
name = 'Baseline Scenario'
scenario = File.basename(csv, '.csv')
run_dir = File.join(root_dir, "run/#{scenario}/")
feature_file_path = File.join(root_dir, json)
csv_file = File.join(root_dir, csv)
mapper_files_dir = File.join(root_dir, 'mappers/')
num_header_rows = 1
feature_file = URBANopt::GeoJSON::GeoFile.from_file(feature_file_path)
scenario = URBANopt::Scenario::ScenarioCSV.new(name, root_dir, run_dir, feature_file, mapper_files_dir, csv_file, num_header_rows)
return scenario
end
def high_efficiency_scenario(json, csv)
name = 'High Efficiency Scenario'
run_dir = File.join(root_dir, 'run/high_efficiency_scenario/')
feature_file_path = File.join(root_dir, json)
csv_file = File.join(root_dir, csv)
mapper_files_dir = File.join(root_dir, 'mappers/')
num_header_rows = 1
feature_file = URBANopt::GeoJSON::GeoFile.from_file(feature_file_path)
scenario = URBANopt::Scenario::ScenarioCSV.new(name, root_dir, run_dir, feature_file, mapper_files_dir, csv_file, num_header_rows)
return scenario
end
def thermal_storage_scenario(json, csv)
name = 'Thermal Storage Scenario'
run_dir = File.join(root_dir, 'run/thermal_storage_scenario/')
feature_file_path = File.join(root_dir, json)
csv_file = File.join(root_dir, csv)
mapper_files_dir = File.join(root_dir, 'mappers/')
num_header_rows = 1
feature_file = URBANopt::GeoJSON::GeoFile.from_file(feature_file_path)
scenario = URBANopt::Scenario::ScenarioCSV.new(name, root_dir, run_dir, feature_file, mapper_files_dir, csv_file, num_header_rows)
return scenario
end
def flexible_hot_water_scenario(json, csv)
name = 'Flexible Hot Water Scenario'
run_dir = File.join(root_dir, 'run/flexible_hot_water_scenario/')
feature_file_path = File.join(root_dir, json)
csv_file = File.join(root_dir, csv)
mapper_files_dir = File.join(root_dir, 'mappers/')
num_header_rows = 1
feature_file = URBANopt::GeoJSON::GeoFile.from_file(feature_file_path)
scenario = URBANopt::Scenario::ScenarioCSV.new(name, root_dir, run_dir, feature_file, mapper_files_dir, csv_file, num_header_rows)
return scenario
end
def mixed_scenario(json, csv)
name = 'Mixed Scenario'
run_dir = File.join(root_dir, 'run/mixed_scenario/')
feature_file_path = File.join(root_dir, json)
csv_file = File.join(root_dir, csv)
mapper_files_dir = File.join(root_dir, 'mappers/')
num_header_rows = 1
feature_file = URBANopt::GeoJSON::GeoFile.from_file(feature_file_path)
scenario = URBANopt::Scenario::ScenarioCSV.new(name, root_dir, run_dir, feature_file, mapper_files_dir, csv_file, num_header_rows)
return scenario
end
def reopt_scenario(json, csv)
name = 'REopt Scenario'
run_dir = File.join(root_dir, 'run/reopt_scenario/')
feature_file_path = File.join(root_dir, json)
csv_file = File.join(root_dir, csv)
mapper_files_dir = File.join(root_dir, 'mappers/')
reopt_files_dir = File.join(root_dir, 'reopt/')
scenario_reopt_assumptions_file_name = 'base_assumptions.json'
num_header_rows = 1
feature_file = URBANopt::GeoJSON::GeoFile.from_file(feature_file_path)
scenario = URBANopt::Scenario::REoptScenarioCSV.new(name, root_dir, run_dir, feature_file, mapper_files_dir, csv_file, num_header_rows, reopt_files_dir, scenario_reopt_assumptions_file_name)
return scenario
end
def chilled_water_storage_scenario(json, csv)
name = 'Chilled Water Storage Scenario'
run_dir = File.join(root_dir, 'run/chilled_water_storage_scenario/')
feature_file_path = File.join(root_dir, json)
csv_file = File.join(root_dir, csv)
mapper_files_dir = File.join(root_dir, 'mappers/')
num_header_rows = 1
feature_file = URBANopt::GeoJSON::GeoFile.from_file(feature_file_path)
scenario = URBANopt::Scenario::ScenarioCSV.new(name, root_dir, run_dir, feature_file, mapper_files_dir, csv_file, num_header_rows)
return scenario
end
def peak_hours_mels_shedding_scenario(json, csv)
name = 'Peak Hours MELs Shedding Scenario'
run_dir = File.join(root_dir, 'run/peak_hours_mels_shedding_scenario/')
feature_file_path = File.join(root_dir, json)
csv_file = File.join(root_dir, csv)
mapper_files_dir = File.join(root_dir, 'mappers/')
num_header_rows = 1
feature_file = URBANopt::GeoJSON::GeoFile.from_file(feature_file_path)
scenario = URBANopt::Scenario::ScenarioCSV.new(name, root_dir, run_dir, feature_file, mapper_files_dir, csv_file, num_header_rows)
return scenario
end
def peak_hours_thermostat_adjust_scenario(json, csv)
name = 'Peak Hours Thermostat Adjust Scenario'
run_dir = File.join(root_dir, 'run/peak_hours_thermostat_adjust_scenario/')
feature_file_path = File.join(root_dir, json)
csv_file = File.join(root_dir, csv)
mapper_files_dir = File.join(root_dir, 'mappers/')
num_header_rows = 1
feature_file = URBANopt::GeoJSON::GeoFile.from_file(feature_file_path)
scenario = URBANopt::Scenario::ScenarioCSV.new(name, root_dir, run_dir, feature_file, mapper_files_dir, csv_file, num_header_rows)
return scenario
end
def configure_project
# write a runner.conf in project dir if it does not exist
# delete runner.conf to automatically regenerate it
options = { gemfile_path: File.join(root_dir, 'Gemfile'), bundle_install_path: File.join(root_dir, '.bundle/install'), num_parallel: 7 }
# write a runner.conf in project dir (if it does not already exist)
if !File.exist?(File.join(root_dir, 'runner.conf'))
puts 'GENERATING runner.conf file'
OpenStudio::Extension::RunnerConfig.init(root_dir) # itinialize the file with default values
run_config = OpenStudio::Extension::RunnerConfig.new(root_dir) # get the configs
# update paths
options.each do |key, val|
run_config.update_config(key, val) # update gemfile_path
end
# save back to disk
run_config.save
else
puts 'USING existing runner.conf file'
end
end
def visualize_scenarios
name = 'Visualize Scenario Results'
run_dir = File.join(root_dir, 'run')
scenario_folders = []
scenario_report_exists = false
Dir.glob(File.join(run_dir, '/*_scenario')) do |scenario_folder|
scenario_report = File.join(scenario_folder, 'scenario_optimization.csv')
# Check if Scenario Optimization REopt file exists and add that
if File.exist?(File.join(scenario_folder, 'scenario_optimization.csv'))
scenario_folders << File.join(scenario_folder, 'scenario_optimization.csv')
scenario_report_exists = true
# Check if Default Feature Report exists and add that
elsif File.exist?(File.join(scenario_folder, 'default_scenario_report.csv'))
scenario_folders << File.join(scenario_folder, 'default_scenario_report.csv')
scenario_report_exists = true
else puts "\nERROR: Default reports not created for #{scenario_folder}. Please use 'process --default' to create default post processing reports for all scenarios first. Visualization not generated for #{scenario_folder}.\n"
end
end
if scenario_report_exists == true
puts "\nCreating visualizations for all Scenario results\n"
URBANopt::Scenario::ResultVisualization.create_visualization(scenario_folders, false)
html_in_path = File.join(root_dir, 'visualization', 'input_visualization_scenario.html')
html_out_path = File.join(run_dir, 'scenario_comparison.html')
FileUtils.cp(html_in_path, html_out_path)
puts "\nDone\n"
end
end
def visualize_features(scenario_file)
name = 'Visualize Feature Results'
scenario_name = File.basename(scenario_file, File.extname(scenario_file))
run_dir = File.join(root_dir, 'run', scenario_name.downcase)
feature_report_exists = false
csv = CSV.read(File.join(root_dir, scenario_file), headers: true)
feature_names = csv['Feature Name']
feature_folders = []
# loop through building feature ids from scenario csv
csv['Feature Id'].each do |feature|
# Check if Feature Optimization REopt file exists and add that
if File.exist?(File.join(run_dir, feature, 'feature_reports/feature_optimization.csv'))
feature_report_exists = true
feature_folders << File.join(run_dir, feature, 'feature_reports/feature_optimization.csv')
elsif File.exist?(File.join(run_dir, feature, 'feature_reports/default_feature_report.csv'))
feature_report_exists = true
feature_folders << File.join(run_dir, feature, 'feature_reports/default_feature_report.csv')
else puts "\nERROR: Default reports not created for #{feature}. Please use 'process --default' to create default post processing reports for all features first. Visualization not generated for #{feature}.\n"
end
end
if feature_report_exists == true
puts "\nCreating visualizations for Feature results in the Scenario\n"
URBANopt::Scenario::ResultVisualization.create_visualization(feature_folders, true, feature_names)
html_in_path = File.join(root_dir, 'visualization', 'input_visualization_feature.html')
html_out_path = File.join(root_dir, 'run', scenario_name, 'feature_comparison.html')
FileUtils.cp(html_in_path, html_out_path)
puts "\nDone\n"
end
end
# Load in the rake tasks from the base extension gem
rake_task = OpenStudio::Extension::RakeTask.new
rake_task.set_extension_class(URBANopt::ExampleGeoJSONProject::ExampleGeoJSONProject)
### Baseline
desc 'Clear Baseline Scenario'
task :clear_baseline, [:json, :csv] do |t, args|
puts "\nClearing Baseline Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'baseline_scenario.csv' if csv.nil?
baseline_scenario(json, csv).clear
end
desc 'Run Baseline Scenario'
task :run_baseline, [:json, :csv] do |t, args|
puts "\nRunning Baseline Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'baseline_scenario.csv' if csv.nil?
configure_project
scenario_runner = URBANopt::Scenario::ScenarioRunnerOSW.new
scenario_runner.run(baseline_scenario(json, csv))
end
desc 'Post Process Baseline Scenario'
task :post_process_baseline, [:json, :csv] do |t, args|
puts "\nPost Processing Baseline Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'baseline_scenario.csv' if csv.nil?
default_post_processor = URBANopt::Scenario::ScenarioDefaultPostProcessor.new(baseline_scenario(json, csv))
scenario_result = default_post_processor.run
# save scenario reports
scenario_result.save
# save feature reports
scenario_result.feature_reports.each(&:save_json_report)
scenario_result.feature_reports.each(&:save_csv_report)
end
### High Efficiency
desc 'Clear High Efficiency Scenario'
task :clear_high_efficiency, [:json, :csv] do |t, args|
puts "\nClearing High Efficiency Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'high_efficiency_scenario.csv' if csv.nil?
high_efficiency_scenario(json, csv).clear
end
desc 'Run High Efficiency Scenario'
task :run_high_efficiency, [:json, :csv] do |t, args|
puts "\nRunning High Efficiency Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'high_efficiency_scenario.csv' if csv.nil?
configure_project
scenario_runner = URBANopt::Scenario::ScenarioRunnerOSW.new
scenario_runner.run(high_efficiency_scenario(json, csv))
end
desc 'Post Process High Efficiency Scenario'
task :post_process_high_efficiency, [:json, :csv] do |t, args|
puts "\nPost Processing High Efficiency Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'high_efficiency_scenario.csv' if csv.nil?
default_post_processor = URBANopt::Scenario::ScenarioDefaultPostProcessor.new(high_efficiency_scenario(json, csv))
scenario_result = default_post_processor.run
# save scenario reports
scenario_result.save
# save feature reports
scenario_result.feature_reports.each(&:save_json_report)
scenario_result.feature_reports.each(&:save_csv_report)
end
### Chilled Water Storage
desc 'Clear Chilled Water Storage Scenario'
task :clear_chilled_water_storage, [:json, :csv] do |t, args|
puts "\nClearing Chilled Water Storage Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'chilled_water_storage_scenario.csv' if csv.nil?
chilled_water_storage_scenario(json, csv).clear
end
desc 'Run Chilled Water Storage Scenario'
task :run_chilled_water_storage, [:json, :csv] do |t, args|
puts "\nRunning Chilled Water Storage Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'chilled_water_storage_scenario.csv' if csv.nil?
configure_project
scenario_runner = URBANopt::Scenario::ScenarioRunnerOSW.new
scenario_runner.run(chilled_water_storage_scenario(json, csv))
end
desc 'Post Process Chilled Water Storage Scenario'
task :post_process_chilled_water_storage, [:json, :csv] do |t, args|
puts "\nPost Processing Chilled Water Storage Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'chilled_water_storage_scenario.csv' if csv.nil?
default_post_processor = URBANopt::Scenario::ScenarioDefaultPostProcessor.new(chilled_water_storage_scenario(json, csv))
scenario_result = default_post_processor.run
# save scenario reports
scenario_result.save
# save feature reports
scenario_result.feature_reports.each(&:save_json_report)
scenario_result.feature_reports.each(&:save_csv_report)
end
### Peak Hours MELs Shedding
desc 'Clear Peak Hours MELs Shedding Scenario'
task :clear_peak_hours_mels_shedding, [:json, :csv] do |t, args|
puts "\nClearing Peak Hours MELs Shedding Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'peak_hours_mels_shedding_scenario.csv' if csv.nil?
peak_hours_mels_shedding_scenario(json, csv).clear
end
desc 'Run Peak Hours MELs Shedding Scenario'
task :run_peak_hours_mels_shedding, [:json, :csv] do |t, args|
puts "\nRunning Peak Hours MELs Shedding Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'peak_hours_mels_shedding_scenario.csv' if csv.nil?
configure_project
scenario_runner = URBANopt::Scenario::ScenarioRunnerOSW.new
scenario_runner.run(peak_hours_mels_shedding_scenario(json, csv))
end
desc 'Post Process Peak Hours MELs Shedding Scenario'
task :post_process_peak_hours_mels_shedding, [:json, :csv] do |t, args|
puts "\nPost Processing Peak Hours MELs Shedding Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'peak_hours_mels_shedding_scenario.csv' if csv.nil?
default_post_processor = URBANopt::Scenario::ScenarioDefaultPostProcessor.new(peak_hours_mels_shedding_scenario(json, csv))
scenario_result = default_post_processor.run
# save scenario reports
scenario_result.save
# save feature reports
scenario_result.feature_reports.each(&:save_json_report)
scenario_result.feature_reports.each(&:save_csv_report)
end
### Peak Hours Thermostat Adjust
desc 'Clear Peak Hours Thermostat Adjust Scenario'
task :clear_peak_hours_thermostat_adjust, [:json, :csv] do |t, args|
puts "\nClearing Peak Hours Thermostat Adjust Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'peak_hours_thermostat_adjust_scenario.csv' if csv.nil?
peak_hours_thermostat_adjust_scenario(json, csv).clear
end
desc 'Run Peak Hours Thermostat Adjust Scenario'
task :run_peak_hours_thermostat_adjust, [:json, :csv] do |t, args|
puts "\nRunning Peak Hours Thermostat Adjust Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'peak_hours_thermostat_adjust_scenario.csv' if csv.nil?
configure_project
scenario_runner = URBANopt::Scenario::ScenarioRunnerOSW.new
scenario_runner.run(peak_hours_thermostat_adjust_scenario(json, csv))
end
desc 'Post Process Peak Hours Thermostat Adjust Scenario'
task :post_process_peak_hours_thermostat_adjust, [:json, :csv] do |t, args|
puts "\nPost Processing Peak Hours Thermostat Adjust Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'peak_hours_thermostat_adjust_scenario.csv' if csv.nil?
default_post_processor = URBANopt::Scenario::ScenarioDefaultPostProcessor.new(peak_hours_thermostat_adjust_scenario(json, csv))
scenario_result = default_post_processor.run
# save scenario reports
scenario_result.save
# save feature reports
scenario_result.feature_reports.each(&:save_json_report)
scenario_result.feature_reports.each(&:save_csv_report)
end
### Thermal Storage
desc 'Clear Thermal Storage Scenario'
task :clear_thermal_storage, [:json, :csv] do |t, args|
puts "\nClearing Thermal Storage Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'thermal_storage_scenario.csv' if csv.nil?
thermal_storage_scenario(json, csv).clear
end
desc 'Run Thermal Storage Scenario'
task :run_thermal_storage, [:json, :csv] do |t, args|
puts "\nRunning Thermal Storage Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'thermal_storage_scenario.csv' if csv.nil?
configure_project
scenario_runner = URBANopt::Scenario::ScenarioRunnerOSW.new
scenario_runner.run(thermal_storage_scenario(json, csv))
end
desc 'Post Process Thermal Storage Scenario'
task :post_process_thermal_storage, [:json, :csv] do |t, args|
puts "\nPost Processing Thermal Storage Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'thermal_storage_scenario.csv' if csv.nil?
default_post_processor = URBANopt::Scenario::ScenarioDefaultPostProcessor.new(thermal_storage_scenario(json, csv))
scenario_result = default_post_processor.run
# save scenario reports
scenario_result.save
# save feature reports
scenario_result.feature_reports.each(&:save_json_report)
scenario_result.feature_reports.each(&:save_csv_report)
end
### Flexible Hot Water
desc 'Clear Flexible Hot Water Scenario'
task :clear_flexible_hot_water, [:json, :csv] do |t, args|
puts "\nClearing Flexible Hot Water Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'flexible_hot_water_scenario.csv' if csv.nil?
flexible_hot_water_scenario(json, csv).clear
end
desc 'Run Flexible Hot Water Scenario'
task :run_flexible_hot_water, [:json, :csv] do |t, args|
puts "\nRunning Flexible Hot Water Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'flexible_hot_water_scenario.csv' if csv.nil?
configure_project
scenario_runner = URBANopt::Scenario::ScenarioRunnerOSW.new
scenario_runner.run(flexible_hot_water_scenario(json, csv))
end
desc 'Post Process Flexible Hot Water Scenario'
task :post_process_flexible_hot_water, [:json, :csv] do |t, args|
puts "\nPost Processing Flexible Hot Water Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'flexible_hot_water_scenario.csv' if csv.nil?
default_post_processor = URBANopt::Scenario::ScenarioDefaultPostProcessor.new(flexible_hot_water_scenario(json, csv))
scenario_result = default_post_processor.run
# save scenario reports
scenario_result.save
# save feature reports
scenario_result.feature_reports.each(&:save_json_report)
scenario_result.feature_reports.each(&:save_csv_report)
end
### REopt
desc 'Clear REopt Scenario'
task :clear_reopt, [:json, :csv] do |t, args|
puts "\nClearing REopt Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_with_PV.json' if json.nil?
csv = 'reopt_scenario.csv' if csv.nil?
reopt_scenario(json, csv).clear
end
desc 'Run REopt Scenario'
task :run_reopt, [:json, :csv] do |t, args|
puts "\nRunning REopt Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_with_PV.json' if json.nil?
csv = 'reopt_scenario.csv' if csv.nil?
configure_project
scenario_runner = URBANopt::Scenario::ScenarioRunnerOSW.new
scenario_runner.run(reopt_scenario(json, csv))
end
desc 'Post Process REopt Scenario'
task :post_process_reopt, [:json, :csv] do |t, args|
puts "\nPost Processing REopt Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_with_PV.json' if json.nil?
csv = 'reopt_scenario.csv' if csv.nil?
default_post_processor = URBANopt::Scenario::ScenarioDefaultPostProcessor.new(reopt_scenario(json, csv))
scenario_report = default_post_processor.run
# save scenario reports
scenario_report.save
# save feature reports
scenario_report.feature_reports.each(&:save_json_report)
scenario_report.feature_reports.each(&:save_csv_report)
scenario_base = default_post_processor.scenario_base
reopt_post_processor = URBANopt::REopt::REoptPostProcessor.new(scenario_report, scenario_base.scenario_reopt_assumptions_file, scenario_base.reopt_feature_assumptions, DEVELOPER_NREL_KEY)
community_photovoltaic = []
groundmount_photovoltaic = {}
feature_file = JSON.parse(File.read(File.join(root_dir, json)), symbolize_names: true)
feature_file[:features].each do |feature|
# Add community photovoltaic if present in the Feature File
case feature[:properties][:district_system_type]
when 'Community Photovoltaic'
community_photovoltaic << feature
# Add groundmount photovoltaic if present in the Feature File
when 'Ground Mount Photovoltaic'
groundmount_photovoltaic[feature[:properties][:associated_building_id]] = feature[:properties][:footprint_area]
end
rescue StandardError
end
# Run Aggregate Scenario
scenario_report_scenario = reopt_post_processor.run_scenario_report(scenario_report: scenario_report, save_name: 'scenario_report_reopt_global_optimization', run_resilience: false, community_photovoltaic: community_photovoltaic)
# Run features individually - this is an alternative approach to the previous step, in your analysis depending on project ojectives you maye only need to run one
scenario_report_features = reopt_post_processor.run_scenario_report_features(scenario_report: scenario_report, save_names_feature_reports: ['feature_report_reopt'] * scenario_report.feature_reports.length, save_name_scenario_report: 'scenario_report_reopt_local_optimization', run_resilience: false,
keep_existing_output: false, groundmount_photovoltaic: groundmount_photovoltaic)
end
### Mixed
desc 'Clear Mixed Scenario'
task :clear_mixed, [:json, :csv] do |t, args|
puts "\nClearing Mixed Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'mixed_scenario.csv' if csv.nil?
mixed_scenario(json, csv).clear
end
desc 'Run Mixed Scenario'
task :run_mixed, [:json, :csv] do |t, args|
puts "\nRunning Mixed Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'mixed_scenario.csv' if csv.nil?
configure_project
scenario_runner = URBANopt::Scenario::ScenarioRunnerOSW.new
scenario_runner.run(mixed_scenario(json, csv))
end
desc 'Post Process Mixed Scenario'
task :post_process_mixed, [:json, :csv] do |t, args|
puts "\nPost Processing Mixed Scenario..."
json = args[:json]
csv = args[:csv]
json = 'example_project_combined.json' if json.nil?
csv = 'mixed_scenario.csv' if csv.nil?
default_post_processor = URBANopt::Scenario::ScenarioDefaultPostProcessor.new(mixed_scenario(json, csv))
scenario_result = default_post_processor.run
# save scenario reports
scenario_result.save
# save feature reports
scenario_result.feature_reports.each(&:save_json_report)
scenario_result.feature_reports.each(&:save_csv_report)
end
### Visualize scenario results
desc 'Visualize and compare results for all Scenarios'
task :visualize_scenarios do
puts "\nVisualizing results for all Scenarios..."
visualize_scenarios
end
## Visualize feature results
desc 'Visualize and compare results for all Features in a Scenario'
task :visualize_features, [:csv] do |t, args|
puts "\nVisualizing results for all Features in the Scenario..."
csv = args[:csv]
csv = 'baseline_scenario.csv' if args[:csv].nil?
visualize_features(csv)
end
### All
desc 'Clear all scenarios'
task clear_all: [:clear_baseline, :clear_high_efficiency, :clear_chilled_water_storage, :clear_thermal_storage, :clear_flexible_hot_water, :clear_reopt, :clear_mixed] do
# clear all the scenarios
end
desc 'Run all scenarios'
task run_all: [:run_baseline, :run_high_efficiency, :run_chilled_water_storage, :run_thermal_storage, :run_flexible_hot_water, :run_reopt, :run_mixed] do
# run all the scenarios
end
desc 'Post process all scenarios'
task post_process_all: [:post_process_baseline, :post_process_high_efficiency, :post_process_chilled_water_storage, :post_process_thermal_storage, :post_process_flexible_hot_water, :post_process_reopt, :post_process_mixed] do
# post_process all the scenarios
end
desc 'Visualize all scenarios'
task :visualize_all do
# visualize all features within each scenario, then visualize across all scenarios
Rake::Task['visualize_features'].invoke('baseline_scenario.csv')
Rake::Task['visualize_features'].reenable
Rake::Task['visualize_features'].invoke('high_efficiency_scenario.csv')
Rake::Task['visualize_features'].reenable
Rake::Task['visualize_features'].invoke('thermal_storage_scenario.csv')
Rake::Task['visualize_features'].reenable
Rake::Task['visualize_features'].invoke('flexible_hot_water_scenario.csv')
Rake::Task['visualize_features'].reenable
Rake::Task['visualize_features'].invoke('reopt_scenario.csv')
Rake::Task['visualize_features'].reenable
Rake::Task['visualize_features'].invoke('mixed_scenario.csv')
Rake::Task['visualize_features'].reenable
Rake::Task['visualize_features'].invoke('chilled_water_storage_scenario.csv')
Rake::Task['visualize_scenarios'].invoke
end
desc 'Run and post process all scenarios'
task update_all: [:run_all, :post_process_all, :visualize_all] do
# run and post_process all the scenarios
end
desc 'Run residential tasks'
namespace :residential do
desc 'Update residential resources'
task :update_resources do
prefix = 'example_project/resources/residential-measures'
repository = 'https://github.com/NREL/resstock.git'
branch_or_tag = 'v3.2.0' # update this when pulling in updated ResStock
FileUtils.rm_rf(prefix)
system("git clone --depth 1 --branch #{branch_or_tag} #{repository} #{prefix}")
folders_to_remove = [
'.git',
'.github',
'.gitignore',
'docs',
'project_testing',
'resources/data',
'test/base_results/baseline/timeseries',
'test/base_results/upgrades',
'test/SetSpaceInfiltrationPerExteriorArea',
'test/tests_buildstock_csvs',
'test/tests_housing_characteristics',
'test/tests_yml_files'
]
folders_to_remove.each do |f|
FileUtils.rm_rf(File.join(prefix, f))
end
end
desc 'Run residential measure tests'
Rake::TestTask.new('measure_tests') do |t|
t.test_files = Dir['example_project/measures/*/tests/*.rb']
t.warning = false
t.verbose = true
end
end
task default: :update_all