Top Level Namespace
Defined Under Namespace
Modules: URBANopt
Instance Method Summary collapse
-
#convert_powerflow_resolution(timeseries_kw, original_res, destination_res) ⇒ Object
********************************************************************************* URBANopt (tm), Copyright © Alliance for Energy Innovation, LLC.
-
#reopt_timeseries_start_index(start_date, timesteps_per_hour) ⇒ Object
bug fix (#164) Start index into the full-year REopt array for the first CSV row.
Instance Method Details
#convert_powerflow_resolution(timeseries_kw, original_res, destination_res) ⇒ Object
********************************************************************************* URBANopt (tm), Copyright © Alliance for Energy Innovation, LLC. See also github.com/urbanopt/urbanopt-reopt-gem/blob/develop/LICENSE.md *********************************************************************************
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 |
# File 'lib/urbanopt/reopt/utilities.rb', line 6 def convert_powerflow_resolution(timeseries_kw, original_res, destination_res) if timeseries_kw.nil? return nil end if timeseries_kw.empty? return nil end if original_res > destination_res # Timesteps will be reduced, i.e. 35040 -> 8760 # This algorithm works by stepping along the origin timeseries at an interval equal to # one timestep in the destintion timeseries and then averaging all origin values that # coincide with the interval. Averages are weighted if a destination timestep # only partaially overlaps an origin timestep. # EX 1 # stepping interval 2 # origin stepping | 1 | 2 | 2 | 4 | # destination stepping | 1.5 | 3 | # EX 2 # stepping interval 2.5 # origin stepping | 1 | 1 | 4 | 2 | 2 | # destination stepping | 1.6 | 2.4 | result = [] stepping_interval = Float(original_res) / Float(destination_res) current_origin_ts = 0 # fraction stepped along the origin time series current_origin_idx = 0 # current integer index of the origin timeseries (0..(8760 * destination_res - 1)).each do |ts| next_stopping_ts = current_origin_ts + stepping_interval # stop at the next destination interval total_power = [] # create to store weighted origin timestep values to average while current_origin_ts != next_stopping_ts next_origin_ts_int = Integer(current_origin_ts) + 1 # Calc next stopping point that will being you to the next origin or destination time step next_origin_ts = [next_origin_ts_int, next_stopping_ts].min # Calc next step length delta_to_next_origin_ts = next_origin_ts - current_origin_ts # Add the proportional origin timestep value to the total power variable total_power.push(Float(timeseries_kw[current_origin_idx]) * delta_to_next_origin_ts) # Only move on to the next origin timestep if you are not ending mid way though an origin timestep # i.e in EX 2 above, the value 4 is needed in destination timestep 1 and 2 if next_origin_ts_int <= next_stopping_ts current_origin_idx += 1 end # Step to the next stopping point current_origin_ts += delta_to_next_origin_ts end # Add averaged total power variable for the destination time step result.push(Float(total_power.sum) / stepping_interval) end end if destination_res > original_res # Timesteps will be expanded, i.e. 8760 -> 35040 # This algorithm works by stepping along the destination timeseries. Steps are made to the next # destination or origin breakpoint, and at each step the proportional amount of the origin stepped # is added to the destination. For example, in in EX 1 below 4 steps are made each with adding the full amount of # the origin (1, 1, 2 and 2) since each in the destination overlaps perfectly with 2 origin # timesteps. In EX 2, the origin overlaps with the first 2 destination timesteps but the third # destination value much be compose of half the 1st origin timestep value and half the second # (i.e 4, 4, (4 * 1/2) + (3 * 1/2), 3, and 3 are added to the destination). # EX 1 # stepping interval 2 # origin stepping | 1 | 2 | # destination stepping | 1 | 1 | 2 | 2 | # EX 2 # stepping interval 2.5 # origin stepping | 4 | 3 | # destination stepping | 4 | 4 | 3.5 | 3 | 3 | result = [] stepping_interval = (Float(destination_res) / Float(original_res)) current_destination_ts = 0 # fraction stepped along the origin time series (0..(8760 * original_res - 1)).each do |original_ts| # keep track of step length along the destination time series original_indices_stepped = 0 # See if you are start in the middle of a destination time step and add the proportional # value to the most recent (and incomplete) destination value remainder = (current_destination_ts - Integer(current_destination_ts)) if remainder > 0 current_destination_ts += (1 - remainder) original_indices_stepped += (1 - remainder) result[-1] = result[-1] + (Float(timeseries_kw[original_ts]) * (1 - remainder)) end # Make whole steps along the destination timeseries that overlap perfectly with the # origin timeseries while (original_indices_stepped < stepping_interval) && ((original_indices_stepped + 1) <= stepping_interval) result.push(Float(timeseries_kw[original_ts])) original_indices_stepped += 1 current_destination_ts += 1 end # See if you need to end your step in the middle of a destination time step and # just add the proportional value from the current origin timestep remainder = (stepping_interval - original_indices_stepped) if remainder > 0 result.push((Float(timeseries_kw[original_ts]) * remainder)) current_destination_ts += remainder end end end if destination_res == original_res # No resolution conversion necessary result = timeseries_kw end return result end |
#reopt_timeseries_start_index(start_date, timesteps_per_hour) ⇒ Object
bug fix (#164) Start index into the full-year REopt array for the first CSV row. Timestamp is the interval END .… so back up one timestep (not by one hour) — fixes the sub-hourly shift. This is applied in the feature and scenario adapters.
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/urbanopt/reopt/utilities.rb', line 124 def reopt_timeseries_start_index(start_date, timesteps_per_hour) seconds_per_timestep = (60 / timesteps_per_hour) * 60 ( ( ((start_date.yday - 1) * 60.0 * 60.0 * 24) + (start_date.hour * 60.0 * 60.0) + (start_date.min * 60.0) + start_date.sec ) / seconds_per_timestep ).to_int - 1 end |