urbanopt-reopt 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,111 @@
1
+ def convert_powerflow_resolution(timeseries_kw, original_res, destination_res)
2
+ if timeseries_kw.nil?
3
+ return nil
4
+ end
5
+
6
+ if timeseries_kw.length == 0
7
+ return nil
8
+ end
9
+
10
+ if original_res > destination_res
11
+ # Timesteps will be reduced, i.e. 35040 -> 8760
12
+
13
+ # This algorithm works by stepping along the origin timeseries at an interval equal to
14
+ # one timestep in the destintion timeseries and then averaging all origin values that
15
+ # coincide with the interval. Averages are weighted if a destination timestep
16
+ # only partaially overlaps an origin timestep.
17
+
18
+ # EX 1
19
+ # stepping interval 2
20
+ # origin stepping | 1 | 2 | 2 | 4 |
21
+ # destination stepping | 1.5 | 3 |
22
+
23
+ # EX 2
24
+ # stepping interval 2.5
25
+ # origin stepping | 1 | 1 | 4 | 2 | 2 |
26
+ # destination stepping | 1.6 | 2.4 |
27
+
28
+ result = []
29
+ stepping_interval = Float(original_res) / Float(destination_res)
30
+ current_origin_ts = 0 # fraction stepped along the origin time series
31
+ current_origin_idx = 0 # current integer index of the origin timeseries
32
+ (0..(8760*destination_res-1)).each do |ts|
33
+ next_stopping_ts = current_origin_ts + stepping_interval #stop at the next destination interval
34
+ total_power = [] #create to store wieghted origin timestep values to average
35
+ while current_origin_ts != next_stopping_ts do
36
+ next_origin_ts_int = Integer(current_origin_ts) + 1
37
+ # Calc next stopping point that will being you to the next origin or destination time step
38
+ next_origin_ts = [next_origin_ts_int, next_stopping_ts].min
39
+ # Calc next step length
40
+ delta_to_next_origin_ts = next_origin_ts - current_origin_ts
41
+ # Add the proportional origin timestep value to the total power variable
42
+ total_power.push(Float(timeseries_kw[current_origin_idx]) * delta_to_next_origin_ts)
43
+ # Only move on to the next origin timestep if you are not ending mid way though an origin timestep
44
+ # i.e in EX 2 above, the value 4 is needed in destination timestep 1 and 2
45
+ if next_origin_ts_int <= next_stopping_ts
46
+ current_origin_idx += 1
47
+ end
48
+ # Step to the next stopping point
49
+ current_origin_ts += delta_to_next_origin_ts
50
+ end
51
+ # Add averaged total power variable for the destination time step
52
+ result.push(Float(total_power.sum) / stepping_interval)
53
+ end
54
+ end
55
+ if destination_res > original_res
56
+ #Timesteps will be expanded, i.e. 8760 -> 35040
57
+
58
+ # This algorithm works by stepping along the destination timeseries. Steps are made to the next
59
+ # destination or origin breakpoint, and at each step the propotional amount of the origin stepped
60
+ # is added to the destination. For example, in in EX 1 below 4 steps are made each with adding the full amount of
61
+ # the origin (1, 1, 2 and 2) since each in the destination overlaps perfectly with 2 origin
62
+ # timesteps. In EX 2, the origin overlaps with the first 2 destination timesteps but the third
63
+ # destination value much be compose of half the 1st origin timestep value and half the second
64
+ # (i.e 4, 4, (4 * 1/2) + (3 * 1/2), 3, and 3 are added to the destination).
65
+
66
+ # EX 1
67
+ # stepping interval 2
68
+ # origin stepping | 1 | 2 |
69
+ # destination stepping | 1 | 1 | 2 | 2 |
70
+
71
+ # EX 2
72
+ # stepping interval 2.5
73
+ # origin stepping | 4 | 3 |
74
+ # destination stepping | 4 | 4 | 3.5 | 3 | 3 |
75
+
76
+ result = []
77
+ stepping_interval = (Float(destination_res) / Float(original_res))
78
+ current_destination_ts = 0 # fraction stepped along the origin time series
79
+ (0..(8760*original_res-1)).each do |original_ts|
80
+ # keep track of step length along the destination time series
81
+ original_indices_stepped = 0
82
+ # See if you are start in the middle of a destination time step and add the proportional
83
+ # value to the most recent (and incomplete) destination value
84
+ remainder = (current_destination_ts - Integer(current_destination_ts))
85
+ if remainder > 0
86
+ current_destination_ts += (1 - remainder)
87
+ original_indices_stepped += (1 - remainder)
88
+ result[-1] = result[-1] + (Float(timeseries_kw[original_ts])*(1-remainder))
89
+ end
90
+ # Make whole steps along the destination timeseries that overlap perfectly with the
91
+ # origin timeseries
92
+ while (original_indices_stepped < stepping_interval) and ((original_indices_stepped + 1) <= stepping_interval)
93
+ result.push(Float(timeseries_kw[original_ts]))
94
+ original_indices_stepped += 1
95
+ current_destination_ts += 1
96
+ end
97
+ # See if you need to end your step in the middle of a destination time step and
98
+ # just add the proportional value from the current origin timestep
99
+ remainder = (stepping_interval - original_indices_stepped)
100
+ if remainder > 0
101
+ result.push((Float(timeseries_kw[original_ts]) * remainder))
102
+ current_destination_ts += remainder
103
+ end
104
+ end
105
+ end
106
+ if destination_res == original_res
107
+ #No resolution conversion necessary
108
+ result = timeseries_kw
109
+ end
110
+ return result
111
+ 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.
@@ -30,6 +40,6 @@
30
40
 
31
41
  module URBANopt # :nodoc:
32
42
  module REopt # :nodoc:
33
- VERSION = '0.5.0'.freeze
43
+ VERSION = '0.6.0'.freeze
34
44
  end
35
45
  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.
@@ -23,9 +23,9 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ['lib']
25
25
 
26
- spec.required_ruby_version = '~> 2.5.0'
26
+ spec.required_ruby_version = '~> 2.7.0'
27
27
 
28
- spec.add_development_dependency 'bundler', '~> 2.1'
28
+ spec.add_development_dependency 'bundler', '>= 2.1.0'
29
29
  spec.add_development_dependency 'rake', '~> 13.0'
30
30
  spec.add_development_dependency 'rspec', '~> 3.7'
31
31
  spec.add_development_dependency 'rubocop', '~> 0.54.0'
@@ -33,6 +33,6 @@ Gem::Specification.new do |spec|
33
33
 
34
34
  spec.add_dependency 'certified', '~> 1'
35
35
  spec.add_dependency 'json_pure', '~> 2'
36
- spec.add_dependency 'urbanopt-scenario', '~> 0.5.0'
36
+ spec.add_dependency 'urbanopt-scenario', '~> 0.6.0'
37
37
 
38
38
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: urbanopt-reopt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-11 00:00:00.000000000 Z
11
+ date: 2021-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2.1'
19
+ version: 2.1.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '2.1'
26
+ version: 2.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.5.0
117
+ version: 0.6.0
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 0.5.0
124
+ version: 0.6.0
125
125
  description: Classes and measures for utilizing the REopt Lite API within OpenStudio
126
126
  workflows.
127
127
  email:
@@ -146,7 +146,6 @@ files:
146
146
  - RDOC_MAIN.md
147
147
  - README.md
148
148
  - Rakefile
149
- - a.txt
150
149
  - deploy_docs.sh
151
150
  - developer_nrel_key.rb
152
151
  - doc_templates/LICENSE.md
@@ -183,6 +182,7 @@ files:
183
182
  - lib/urbanopt/reopt/reopt_schema/reopt_output_schema.json
184
183
  - lib/urbanopt/reopt/scenario/reopt_scenario_csv.rb
185
184
  - lib/urbanopt/reopt/scenario_report_adapter.rb
185
+ - lib/urbanopt/reopt/utilities.rb
186
186
  - lib/urbanopt/reopt/version.rb
187
187
  - lib/urbanopt/reopt_scenario.rb
188
188
  - urbanopt-reopt.gemspec
@@ -198,7 +198,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - "~>"
200
200
  - !ruby/object:Gem::Version
201
- version: 2.5.0
201
+ version: 2.7.0
202
202
  required_rubygems_version: !ruby/object:Gem::Requirement
203
203
  requirements:
204
204
  - - ">="
data/a.txt DELETED
@@ -1 +0,0 @@
1
- 123