Question-and-Answer Resource for the Building Energy Modeling Community
Get s tarted with the Help page
Ask Your Question
2

how to add up multiple timeseries

asked 2020-12-14 10:59:52 -0500

mattkoch gravatar image

I am trying to add up time series of power values. For example, I will have a time series for the lighting power of a zone throughout the year, and I will have a time series for the equipment power of that zone throughout the year. What I want is the combined lighting and equipment power of that zone throughout the year. So say on March 3 at 5 PM, the lighting power is 500 W and the equipment power is 50 W, then I want the combined time series to show 350 W at that date and time.

I am trying to avoid a whole bunch of loops for now, as I noticed there was an operator+() method for time series in the OpenStudio SDK for version for 2.9.1. So say I have the following:

time_series_set = []

time_series = sql_file.timeSeries(run_period,"Zone Timestep","Zone Lights Electric Power","Zone 1")
if time_series.is_initialized then
  time_series_set << time_series.get
end

time_series = sql_file.timeSeries(run_period,"Zone Timestep","Zone Electric Equipment Electric Power","Zone 1")
if time_series.is_initialized then
  time_series_set << time_series.get
end

The above works just fine (notice how I gather the time_series into the array AFTER their .get). So then I did the following, just to make sure I get the right individual data.

time_series_set.each_with_index do |time_series,index|
  runner.registerInfo("Time Series (#{index}) = #{time_series.values()}")
end

This works well also. Then I was hoping the following would work:

time_series_set.each_with_index do |time_series,index|
  if index == 0 then
    time_series_total = time_series
  else
    time_series_total = time_series_total.operator+(time_series)
  end
end

However, this just seems to fail? I'd appreciate any thoughts about how to move this forward. Thank you.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-12-14 12:49:28 -0500

mattkoch gravatar image

It seems like the following line

time_series_total = time_series_total + time_series

instead of this line

time_series_total = time_series_total.operator+(time_series)

does the trick.

edit flag offensive delete link more

Comments

This is not particularly fast, though. In fact, it is quite slow. Is this vectorized internally? Is there a faster alternative?

mattkoch gravatar image mattkoch  ( 2020-12-14 14:08:43 -0500 )edit

OK, so while this may work, the speed - or rather slowness - of it makes it impractical. A better - and probably more correct - approach is discussed here.

mattkoch gravatar image mattkoch  ( 2021-01-14 10:24:02 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

 

Question Tools

2 followers

Stats

Asked: 2020-12-14 10:59:52 -0500

Seen: 31 times

Last updated: Dec 14 '20