urbanopt-scenario 0.4.4 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +1,31 @@
1
1
  # *********************************************************************************
2
- # URBANopt (tm), Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
2
+ # URBANopt™, Copyright (c) 2019-2021, Alliance for Sustainable Energy, LLC, and other
3
3
  # contributors. All rights reserved.
4
- #
4
+
5
5
  # Redistribution and use in source and binary forms, with or without modification,
6
6
  # are permitted provided that the following conditions are met:
7
- #
7
+
8
8
  # Redistributions of source code must retain the above copyright notice, this list
9
9
  # of conditions and the following disclaimer.
10
- #
10
+
11
11
  # Redistributions in binary form must reproduce the above copyright notice, this
12
12
  # list of conditions and the following disclaimer in the documentation and/or other
13
13
  # materials provided with the distribution.
14
- #
14
+
15
15
  # Neither the name of the copyright holder nor the names of its contributors may be
16
16
  # used to endorse or promote products derived from this software without specific
17
17
  # prior written permission.
18
- #
18
+
19
+ # Redistribution of this software, without modification, must refer to the software
20
+ # by the same designation. Redistribution of a modified version of this software
21
+ # (i) may not refer to the modified version by the same designation, or by any
22
+ # confusingly similar designation, and (ii) must refer to the underlying software
23
+ # originally provided by Alliance as “URBANopt”. Except to comply with the foregoing,
24
+ # the term “URBANopt”, or any confusingly similar designation may not be used to
25
+ # refer to any modified version of this software or any modified version of the
26
+ # underlying software originally provided by Alliance without the prior written
27
+ # consent of Alliance.
28
+
19
29
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
30
  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
31
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -32,8 +42,6 @@ require 'urbanopt/scenario/scenario_post_processor_base'
32
42
  require 'urbanopt/reporting/default_reports'
33
43
 
34
44
  require 'csv'
35
- require 'json'
36
- require 'fileutils'
37
45
  require 'sqlite3'
38
46
 
39
47
  module URBANopt
@@ -109,7 +117,7 @@ module URBANopt
109
117
  feature_list = Pathname.new(@initialization_hash[:directory_name]).children.select(&:directory?) # Folders in the run/scenario directory
110
118
 
111
119
  # get scenario CSV
112
- scenario_csv = File.join(@initialization_hash[:root_dir], @initialization_hash[:name] + '.csv')
120
+ scenario_csv = File.join(@initialization_hash[:root_dir], "#{@initialization_hash[:name]}.csv")
113
121
  if File.exist?(scenario_csv)
114
122
  # csv found
115
123
  feature_ids = CSV.read(scenario_csv, headers: true)
@@ -151,7 +159,7 @@ module URBANopt
151
159
  # running sum
152
160
  arr_match[:elec_val] += Float(row[7])
153
161
  end
154
- end # End elec_query
162
+ end
155
163
  elec_query.close
156
164
 
157
165
  gas_query = feature_db.query "SELECT ReportData.TimeIndex, Time.Year, Time.Month, Time.Day, Time.Hour,
@@ -174,10 +182,10 @@ module URBANopt
174
182
  # running sum
175
183
  arr_match[:gas_val] += Float(row[7])
176
184
  end
177
- end # End gas_query
185
+ end
178
186
  gas_query.close
179
187
  feature_db.close
180
- end # End feature_list loop
188
+ end
181
189
 
182
190
  elec_sql = []
183
191
  gas_sql = []
@@ -1,21 +1,31 @@
1
1
  # *********************************************************************************
2
- # URBANopt (tm), Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
2
+ # URBANopt™, Copyright (c) 2019-2021, Alliance for Sustainable Energy, LLC, and other
3
3
  # contributors. All rights reserved.
4
- #
4
+
5
5
  # Redistribution and use in source and binary forms, with or without modification,
6
6
  # are permitted provided that the following conditions are met:
7
- #
7
+
8
8
  # Redistributions of source code must retain the above copyright notice, this list
9
9
  # of conditions and the following disclaimer.
10
- #
10
+
11
11
  # Redistributions in binary form must reproduce the above copyright notice, this
12
12
  # list of conditions and the following disclaimer in the documentation and/or other
13
13
  # materials provided with the distribution.
14
- #
14
+
15
15
  # Neither the name of the copyright holder nor the names of its contributors may be
16
16
  # used to endorse or promote products derived from this software without specific
17
17
  # prior written permission.
18
- #
18
+
19
+ # Redistribution of this software, without modification, must refer to the software
20
+ # by the same designation. Redistribution of a modified version of this software
21
+ # (i) may not refer to the modified version by the same designation, or by any
22
+ # confusingly similar designation, and (ii) must refer to the underlying software
23
+ # originally provided by Alliance as “URBANopt”. Except to comply with the foregoing,
24
+ # the term “URBANopt”, or any confusingly similar designation may not be used to
25
+ # refer to any modified version of this software or any modified version of the
26
+ # underlying software originally provided by Alliance without the prior written
27
+ # consent of Alliance.
28
+
19
29
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
30
  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
31
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -34,7 +44,6 @@ require 'urbanopt/reporting/default_reports'
34
44
  require 'csv'
35
45
  require 'json'
36
46
  require 'fileutils'
37
- require 'pathname'
38
47
 
39
48
  module URBANopt
40
49
  module Scenario
@@ -71,7 +80,7 @@ module URBANopt
71
80
  # load building features data
72
81
  @scenario_report.feature_reports.each do |feature_report|
73
82
  # read results from opendss
74
- opendss_csv = CSV.read(File.join(@opendss_results_dir, 'results', 'Features', feature_report.id + '.csv'))
83
+ opendss_csv = CSV.read(File.join(@opendss_results_dir, 'results', 'Features', "#{feature_report.id}.csv"))
75
84
  # add results to data
76
85
  @opendss_data[feature_report.id] = opendss_csv
77
86
  end
@@ -93,7 +102,7 @@ module URBANopt
93
102
  # add transformer results to @opendss_data
94
103
  transformer_ids.each do |id|
95
104
  # read results from transformers
96
- transformer_csv = CSV.read(File.join(tf_results_path, id + '.csv'))
105
+ transformer_csv = CSV.read(File.join(tf_results_path, "#{id}.csv"))
97
106
  # add results to data
98
107
  @opendss_data[id] = transformer_csv
99
108
  end
@@ -124,7 +133,7 @@ module URBANopt
124
133
  if row.include? 'Datetime'
125
134
  row.map { |header| header.prepend('opendss_') }
126
135
  end
127
- csv << (feature_report_data[i] + row[1..-1])
136
+ csv << (feature_report_data[i] + row[1..])
128
137
  end
129
138
  end
130
139
 
@@ -133,7 +142,7 @@ module URBANopt
133
142
 
134
143
  # add feature reports for transformers
135
144
  def save_transformers_reports
136
- @opendss_data.keys.each do |k|
145
+ @opendss_data.each_key do |k|
137
146
  if k.include? 'Transformer'
138
147
 
139
148
  # create transformer directory
@@ -162,7 +171,7 @@ module URBANopt
162
171
  end
163
172
 
164
173
  # save transformer CSV report
165
- File.write(File.join(transformer_dir, 'feature_reports', 'default_feature_report_opendss' + '.csv'), transformer_csv)
174
+ File.write(File.join(transformer_dir, 'feature_reports', 'default_feature_report_opendss.csv'), transformer_csv)
166
175
 
167
176
  # create transformer report
168
177
  transformer_report = URBANopt::Reporting::DefaultReports::FeatureReport.new(id: k, name: k, directory_name: transformer_dir, feature_type: 'Transformer',
@@ -178,7 +187,7 @@ module URBANopt
178
187
  transformer_hash = transformer_report.to_hash
179
188
  # transformer_hash.delete_if { |k, v| v.nil? }
180
189
 
181
- json_name_path = File.join(transformer_dir, 'feature_reports', 'default_feature_report_opendss' + '.json')
190
+ json_name_path = File.join(transformer_dir, 'feature_reports', 'default_feature_report_opendss.json')
182
191
 
183
192
  # save the json file
184
193
  File.open(json_name_path, 'w') do |f|
@@ -268,7 +277,8 @@ module URBANopt
268
277
  save_transformers_reports
269
278
 
270
279
  # save the updated scenario reports
271
- @scenario_report.save(file_name = 'scenario_report_opendss')
280
+ # set save_feature_reports to false since only the scenario reports should be saved now
281
+ @scenario_report.save(file_name = 'scenario_report_opendss', save_feature_reports = false)
272
282
  end
273
283
  end
274
284
  end
@@ -1,21 +1,31 @@
1
1
  # *********************************************************************************
2
- # URBANopt (tm), Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
2
+ # URBANopt™, Copyright (c) 2019-2021, Alliance for Sustainable Energy, LLC, and other
3
3
  # contributors. All rights reserved.
4
- #
4
+
5
5
  # Redistribution and use in source and binary forms, with or without modification,
6
6
  # are permitted provided that the following conditions are met:
7
- #
7
+
8
8
  # Redistributions of source code must retain the above copyright notice, this list
9
9
  # of conditions and the following disclaimer.
10
- #
10
+
11
11
  # Redistributions in binary form must reproduce the above copyright notice, this
12
12
  # list of conditions and the following disclaimer in the documentation and/or other
13
13
  # materials provided with the distribution.
14
- #
14
+
15
15
  # Neither the name of the copyright holder nor the names of its contributors may be
16
16
  # used to endorse or promote products derived from this software without specific
17
17
  # prior written permission.
18
- #
18
+
19
+ # Redistribution of this software, without modification, must refer to the software
20
+ # by the same designation. Redistribution of a modified version of this software
21
+ # (i) may not refer to the modified version by the same designation, or by any
22
+ # confusingly similar designation, and (ii) must refer to the underlying software
23
+ # originally provided by Alliance as “URBANopt”. Except to comply with the foregoing,
24
+ # the term “URBANopt”, or any confusingly similar designation may not be used to
25
+ # refer to any modified version of this software or any modified version of the
26
+ # underlying software originally provided by Alliance without the prior written
27
+ # consent of Alliance.
28
+
19
29
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
30
  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
31
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -1,21 +1,31 @@
1
1
  # *********************************************************************************
2
- # URBANopt (tm), Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
2
+ # URBANopt™, Copyright (c) 2019-2021, Alliance for Sustainable Energy, LLC, and other
3
3
  # contributors. All rights reserved.
4
- #
4
+
5
5
  # Redistribution and use in source and binary forms, with or without modification,
6
6
  # are permitted provided that the following conditions are met:
7
- #
7
+
8
8
  # Redistributions of source code must retain the above copyright notice, this list
9
9
  # of conditions and the following disclaimer.
10
- #
10
+
11
11
  # Redistributions in binary form must reproduce the above copyright notice, this
12
12
  # list of conditions and the following disclaimer in the documentation and/or other
13
13
  # materials provided with the distribution.
14
- #
14
+
15
15
  # Neither the name of the copyright holder nor the names of its contributors may be
16
16
  # used to endorse or promote products derived from this software without specific
17
17
  # prior written permission.
18
- #
18
+
19
+ # Redistribution of this software, without modification, must refer to the software
20
+ # by the same designation. Redistribution of a modified version of this software
21
+ # (i) may not refer to the modified version by the same designation, or by any
22
+ # confusingly similar designation, and (ii) must refer to the underlying software
23
+ # originally provided by Alliance as “URBANopt”. Except to comply with the foregoing,
24
+ # the term “URBANopt”, or any confusingly similar designation may not be used to
25
+ # refer to any modified version of this software or any modified version of the
26
+ # underlying software originally provided by Alliance without the prior written
27
+ # consent of Alliance.
28
+
19
29
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
30
  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
31
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -123,11 +133,12 @@ module URBANopt
123
133
  # add each osw file to its corresponding group id +simulation_dir+ is out_of_date
124
134
  if simulation_dir.out_of_date?
125
135
 
126
- if feature_type == 'Building'
136
+ case feature_type
137
+ when 'Building'
127
138
  building_osws << simulation_dir.in_osw_path
128
- elsif feature_type == 'District System'
139
+ when 'District System'
129
140
  district_system_osws << simulation_dir.in_osw_path
130
- elsif feature_type == 'Transformer'
141
+ when 'Transformer'
131
142
  transformer_osws << simulation_dir.in_osw_path
132
143
  else
133
144
  raise "ScenarioRunnerOSW does not know how to run a #{feature_type} feature"
@@ -1,21 +1,31 @@
1
1
  # *********************************************************************************
2
- # URBANopt (tm), Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
2
+ # URBANopt™, Copyright (c) 2019-2021, Alliance for Sustainable Energy, LLC, and other
3
3
  # contributors. All rights reserved.
4
- #
4
+
5
5
  # Redistribution and use in source and binary forms, with or without modification,
6
6
  # are permitted provided that the following conditions are met:
7
- #
7
+
8
8
  # Redistributions of source code must retain the above copyright notice, this list
9
9
  # of conditions and the following disclaimer.
10
- #
10
+
11
11
  # Redistributions in binary form must reproduce the above copyright notice, this
12
12
  # list of conditions and the following disclaimer in the documentation and/or other
13
13
  # materials provided with the distribution.
14
- #
14
+
15
15
  # Neither the name of the copyright holder nor the names of its contributors may be
16
16
  # used to endorse or promote products derived from this software without specific
17
17
  # prior written permission.
18
- #
18
+
19
+ # Redistribution of this software, without modification, must refer to the software
20
+ # by the same designation. Redistribution of a modified version of this software
21
+ # (i) may not refer to the modified version by the same designation, or by any
22
+ # confusingly similar designation, and (ii) must refer to the underlying software
23
+ # originally provided by Alliance as “URBANopt”. Except to comply with the foregoing,
24
+ # the term “URBANopt”, or any confusingly similar designation may not be used to
25
+ # refer to any modified version of this software or any modified version of the
26
+ # underlying software originally provided by Alliance without the prior written
27
+ # consent of Alliance.
28
+
19
29
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
30
  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
31
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -31,21 +41,23 @@
31
41
  require 'csv'
32
42
  require 'date'
33
43
  require 'json'
34
- require 'fileutils'
35
44
 
36
45
  module URBANopt
37
46
  module Scenario
38
47
  class ResultVisualization
39
- def self.create_visualization(run_dir, feature = true)
48
+ def self.create_visualization(run_dir, feature = true, feature_names = false)
40
49
  @all_results = []
41
- run_dir.each do |folder|
42
- name = folder.split('/')[-1]
43
50
 
51
+ run_dir.each do |folder|
44
52
  # create visualization for scenarios
45
- if feature == false
53
+ case feature
54
+ when false
55
+ name = folder.split('/')[-1]
46
56
  csv_dir = File.join(folder, 'default_scenario_report.csv')
47
57
  # create visualization for features
48
- elsif feature == true
58
+ when true
59
+ index = run_dir.index(folder)
60
+ name = "#{folder.split('/')[-1]}-#{feature_names[index]}"
49
61
  csv_dir = File.join(folder, 'feature_reports/default_feature_report.csv')
50
62
  end
51
63
 
@@ -181,13 +193,12 @@ module URBANopt
181
193
  monthly_sum_dec += v.to_f
182
194
  i += 1
183
195
  end
184
-
185
196
  end
186
197
  end
187
198
 
188
199
  # sum up monthly values for annual aggregate
189
200
  annual_sum = monthly_sum_jan + monthly_sum_feb + monthly_sum_mar + monthly_sum_apr + monthly_sum_may + monthly_sum_jun + monthly_sum_jul + monthly_sum_aug + monthly_sum_sep + monthly_sum_oct + monthly_sum_nov + monthly_sum_dec
190
-
201
+
191
202
  # store headers as key and monthly sums as values for each header
192
203
  monthly_totals[headers_unitless[j]] = [monthly_sum_jan, monthly_sum_feb, monthly_sum_mar, monthly_sum_apr, monthly_sum_may, monthly_sum_jun, monthly_sum_jul, monthly_sum_aug, monthly_sum_sep, monthly_sum_oct, monthly_sum_nov, monthly_sum_dec]
193
204
 
@@ -230,6 +241,6 @@ module URBANopt
230
241
  file << "var scenarioData = #{JSON.pretty_generate(@all_results)};"
231
242
  end
232
243
  end
233
- end # ResultVisualization
234
- end # Scenario
235
- end # URBANopt
244
+ end
245
+ end
246
+ end
@@ -1,21 +1,31 @@
1
1
  # *********************************************************************************
2
- # URBANopt (tm), Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
2
+ # URBANopt™, Copyright (c) 2019-2021, Alliance for Sustainable Energy, LLC, and other
3
3
  # contributors. All rights reserved.
4
- #
4
+
5
5
  # Redistribution and use in source and binary forms, with or without modification,
6
6
  # are permitted provided that the following conditions are met:
7
- #
7
+
8
8
  # Redistributions of source code must retain the above copyright notice, this list
9
9
  # of conditions and the following disclaimer.
10
- #
10
+
11
11
  # Redistributions in binary form must reproduce the above copyright notice, this
12
12
  # list of conditions and the following disclaimer in the documentation and/or other
13
13
  # materials provided with the distribution.
14
- #
14
+
15
15
  # Neither the name of the copyright holder nor the names of its contributors may be
16
16
  # used to endorse or promote products derived from this software without specific
17
17
  # prior written permission.
18
- #
18
+
19
+ # Redistribution of this software, without modification, must refer to the software
20
+ # by the same designation. Redistribution of a modified version of this software
21
+ # (i) may not refer to the modified version by the same designation, or by any
22
+ # confusingly similar designation, and (ii) must refer to the underlying software
23
+ # originally provided by Alliance as “URBANopt”. Except to comply with the foregoing,
24
+ # the term “URBANopt”, or any confusingly similar designation may not be used to
25
+ # refer to any modified version of this software or any modified version of the
26
+ # underlying software originally provided by Alliance without the prior written
27
+ # consent of Alliance.
28
+
19
29
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
30
  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
31
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -44,11 +54,7 @@ module URBANopt
44
54
  @feature_names = feature_names
45
55
  end
46
56
 
47
- attr_reader :scenario #:nodoc:
48
-
49
- attr_reader :features #:nodoc:
50
-
51
- attr_reader :feature_names #:nodoc:
57
+ attr_reader :scenario, :features, :feature_names #:nodoc: #:nodoc: #:nodoc:
52
58
 
53
59
  ##
54
60
  # Return the directory that this simulation will run in
@@ -1,21 +1,31 @@
1
1
  # *********************************************************************************
2
- # URBANopt (tm), Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
2
+ # URBANopt™, Copyright (c) 2019-2021, Alliance for Sustainable Energy, LLC, and other
3
3
  # contributors. All rights reserved.
4
- #
4
+
5
5
  # Redistribution and use in source and binary forms, with or without modification,
6
6
  # are permitted provided that the following conditions are met:
7
- #
7
+
8
8
  # Redistributions of source code must retain the above copyright notice, this list
9
9
  # of conditions and the following disclaimer.
10
- #
10
+
11
11
  # Redistributions in binary form must reproduce the above copyright notice, this
12
12
  # list of conditions and the following disclaimer in the documentation and/or other
13
13
  # materials provided with the distribution.
14
- #
14
+
15
15
  # Neither the name of the copyright holder nor the names of its contributors may be
16
16
  # used to endorse or promote products derived from this software without specific
17
17
  # prior written permission.
18
- #
18
+
19
+ # Redistribution of this software, without modification, must refer to the software
20
+ # by the same designation. Redistribution of a modified version of this software
21
+ # (i) may not refer to the modified version by the same designation, or by any
22
+ # confusingly similar designation, and (ii) must refer to the underlying software
23
+ # originally provided by Alliance as “URBANopt”. Except to comply with the foregoing,
24
+ # the term “URBANopt”, or any confusingly similar designation may not be used to
25
+ # refer to any modified version of this software or any modified version of the
26
+ # underlying software originally provided by Alliance without the prior written
27
+ # consent of Alliance.
28
+
19
29
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
30
  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
31
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -61,13 +71,15 @@ module URBANopt
61
71
  end
62
72
 
63
73
  attr_reader :mapper_class, :feature_id
74
+
64
75
  ##
65
76
  # Return the directory that this simulation will run in.
66
77
  ##
67
78
  def run_dir
68
79
  raise 'Feature ID not set' if @feature_id.nil?
69
80
  raise 'Scenario run dir not set' if scenario.run_dir.nil?
70
- return File.join(scenario.run_dir, @feature_id + '/')
81
+
82
+ return File.join(scenario.run_dir, "#{@feature_id}/")
71
83
  end
72
84
 
73
85
  ##