urbanopt-reopt 0.5.0 → 0.5.4

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,107 @@
1
+ def convert_powerflow_resolution(timeseries_kw, original_res, destination_res)
2
+ if timeseries_kw.length == 0
3
+ return nil
4
+ end
5
+
6
+ if original_res > destination_res
7
+ # Timesteps will be reduced, i.e. 35040 -> 8760
8
+
9
+ # This algorithm works by stepping along the origin timeseries at an interval equal to
10
+ # one timestep in the destintion timeseries and then averaging all origin values that
11
+ # coincide with the interval. Averages are weighted if a destination timestep
12
+ # only partaially overlaps an origin timestep.
13
+
14
+ # EX 1
15
+ # stepping interval 2
16
+ # origin stepping | 1 | 2 | 2 | 4 |
17
+ # destination stepping | 1.5 | 3 |
18
+
19
+ # EX 2
20
+ # stepping interval 2.5
21
+ # origin stepping | 1 | 1 | 4 | 2 | 2 |
22
+ # destination stepping | 1.6 | 2.4 |
23
+
24
+ result = []
25
+ stepping_interval = Float(original_res) / Float(destination_res)
26
+ current_origin_ts = 0 # fraction stepped along the origin time series
27
+ current_origin_idx = 0 # current integer index of the origin timeseries
28
+ (0..(8760*destination_res-1)).each do |ts|
29
+ next_stopping_ts = current_origin_ts + stepping_interval #stop at the next destination interval
30
+ total_power = [] #create to store wieghted origin timestep values to average
31
+ while current_origin_ts != next_stopping_ts do
32
+ next_origin_ts_int = Integer(current_origin_ts) + 1
33
+ # Calc next stopping point that will being you to the next origin or destination time step
34
+ next_origin_ts = [next_origin_ts_int, next_stopping_ts].min
35
+ # Calc next step length
36
+ delta_to_next_origin_ts = next_origin_ts - current_origin_ts
37
+ # Add the proportional origin timestep value to the total power variable
38
+ total_power.push(Float(timeseries_kw[current_origin_idx]) * delta_to_next_origin_ts)
39
+ # Only move on to the next origin timestep if you are not ending mid way though an origin timestep
40
+ # i.e in EX 2 above, the value 4 is needed in destination timestep 1 and 2
41
+ if next_origin_ts_int <= next_stopping_ts
42
+ current_origin_idx += 1
43
+ end
44
+ # Step to the next stopping point
45
+ current_origin_ts += delta_to_next_origin_ts
46
+ end
47
+ # Add averaged total power variable for the destination time step
48
+ result.push(Float(total_power.sum) / stepping_interval)
49
+ end
50
+ end
51
+ if destination_res > original_res
52
+ #Timesteps will be expanded, i.e. 8760 -> 35040
53
+
54
+ # This algorithm works by stepping along the destination timeseries. Steps are made to the next
55
+ # destination or origin breakpoint, and at each step the propotional amount of the origin stepped
56
+ # is added to the destination. For example, in in EX 1 below 4 steps are made each with adding the full amount of
57
+ # the origin (1, 1, 2 and 2) since each in the destination overlaps perfectly with 2 origin
58
+ # timesteps. In EX 2, the origin overlaps with the first 2 destination timesteps but the third
59
+ # destination value much be compose of half the 1st origin timestep value and half the second
60
+ # (i.e 4, 4, (4 * 1/2) + (3 * 1/2), 3, and 3 are added to the destination).
61
+
62
+ # EX 1
63
+ # stepping interval 2
64
+ # origin stepping | 1 | 2 |
65
+ # destination stepping | 1 | 1 | 2 | 2 |
66
+
67
+ # EX 2
68
+ # stepping interval 2.5
69
+ # origin stepping | 4 | 3 |
70
+ # destination stepping | 4 | 4 | 3.5 | 3 | 3 |
71
+
72
+ result = []
73
+ stepping_interval = (Float(destination_res) / Float(original_res))
74
+ current_destination_ts = 0 # fraction stepped along the origin time series
75
+ (0..(8760*original_res-1)).each do |original_ts|
76
+ # keep track of step length along the destination time series
77
+ original_indices_stepped = 0
78
+ # See if you are start in the middle of a destination time step and add the proportional
79
+ # value to the most recent (and incomplete) destination value
80
+ remainder = (current_destination_ts - Integer(current_destination_ts))
81
+ if remainder > 0
82
+ current_destination_ts += (1 - remainder)
83
+ original_indices_stepped += (1 - remainder)
84
+ result[-1] = result[-1] + (Float(timeseries_kw[original_ts])*(1-remainder))
85
+ end
86
+ # Make whole steps along the destination timeseries that overlap perfectly with the
87
+ # origin timeseries
88
+ while (original_indices_stepped < stepping_interval) and ((original_indices_stepped + 1) <= stepping_interval)
89
+ result.push(Float(timeseries_kw[original_ts]))
90
+ original_indices_stepped += 1
91
+ current_destination_ts += 1
92
+ end
93
+ # See if you need to end your step in the middle of a destination time step and
94
+ # just add the proportional value from the current origin timestep
95
+ remainder = (stepping_interval - original_indices_stepped)
96
+ if remainder > 0
97
+ result.push((Float(timeseries_kw[original_ts]) * remainder))
98
+ current_destination_ts += remainder
99
+ end
100
+ end
101
+ end
102
+ if destination_res == original_res
103
+ #No resolution conversion necessary
104
+ result = timeseries_kw
105
+ end
106
+ return result
107
+ end
@@ -30,6 +30,6 @@
30
30
 
31
31
  module URBANopt # :nodoc:
32
32
  module REopt # :nodoc:
33
- VERSION = '0.5.0'.freeze
33
+ VERSION = '0.5.4'.freeze
34
34
  end
35
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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.5.4
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-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -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
data/a.txt DELETED
@@ -1 +0,0 @@
1
- 123