Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
9

Can you load Schedule:File in OpenStudio?

asked 2016-01-25 11:12:44 -0600

Can you load a Schedule:File object in OpenStudio?

If not what's the best way to translate a csv file into an OpenStudio schedule?

In my case I've got a 8760 schedule (and some 87600 ones) that I'm not going to consider creating by hand

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
9

answered 2016-01-27 03:24:02 -0600

updated 2019-04-23 09:38:06 -0600

Update: ScheduleFile was wrapped and available to use with the API in OpenStudio 2.7.0.


Here's an example on how to import an 8760-hour schedule in OpenStudio via Schedule:FixedInterval. It's a little bit awkward indeed to do, so I thought this could help some people. In my case I just ran it in command line, but it's easy to adapt that as a measure if you need it.

require 'csv'

# load the test model
translator = OpenStudio::OSVersion::VersionTranslator.new
path = OpenStudio::Path.new("./example_model.osm")
model = translator.loadModel(path)
model = model.get



def create_schedule_and_rename(timeseries, name, model)
  schedule = OpenStudio::Model::ScheduleInterval::fromTimeSeries(timeseries, model)
  if schedule.empty?
    puts "Could not create schedule '#{name}'. Skipping"
    return false
  else
    schedule = schedule.get
    schedule.setName(name)
    return schedule
  end
end

# Loading csv. In my case I have 4 columns timestamp, supply temp, supply flow, load
raw_data =  CSV.table('IT.csv')
# [88] Repiping(main)> raw_data.headers
#=> [:timestamp, :chw_itloopsecchwstemp, :chw_itloopsecchwrflow_cov, :w]


# Create Vectors to load the 8760 values.
it_supply_temp = OpenStudio::Vector.new(8760)
it_flow_fraction = OpenStudio::Vector.new(8760)
it_load = OpenStudio::Vector.new(8760)


# Loop on each row of the csv and load data in the OpenStudio::Vector objects
raw_data.each_with_index do |row, i|
  # Convert F to C on the fly
  it_supply_temp[i] = OpenStudio::convert(row[:chw_itloopsecchwstemp],'F','C').get
  # This is a fraction, no conversion needed
  it_flow_fraction[i] = row[:it_flow_fraction]
  # Load is already in Watts
  it_load[i] = row[:w]
end

# Get number of initial Schedule:FixedInterval for reporting
initial_number = model.getScheduleFixedIntervals.size

# To create timeSeries we need a start date (January 1st) and a time interval (hourly interval)
date = OpenStudio::Date.new(OpenStudio::MonthOfYear.new("Jan"), 1, 2009)
time = OpenStudio::Time.new(0,1,0,0)

# Create a timeSeries
it_supply_temp_timeSeries = OpenStudio::TimeSeries.new(date, time, it_supply_temp, "F")
# Convert to schedule and if it worked, rename. See function above
it_supply_temp_sch = create_schedule_and_rename(it_supply_temp_timeSeries, "IT ChW Supply Outlet Temp Schedule", model)


it_flow_fraction_timeSeries = OpenStudio::TimeSeries.new(date, time, it_flow_fraction, "Fraction")
it_flow_fraction_sch = create_schedule_and_rename(it_flow_fraction_timeSeries, "IT ChW Load Profile - Flow Fraction Schedule", model)

it_load_timeSeries = OpenStudio::TimeSeries.new(date, time, it_load, "W")
it_load_sch = create_schedule_and_rename(it_load_timeSeries, "IT ChW Load Profile - Load Schedule", model)


# Final Reporting
final_number = model.getScheduleFixedIntervals.size

puts "Model started with #{initial_number} Schedule:FixedInterval and ended with #{final_number}"

# to save:
# model.save(path, true)
edit flag offensive delete link more

Comments

1

Great work! I was able to incorporate in a measure to create a custom hourly fixed interval schedule from a CSV. Thanks for sharing.

Lyle K's avatar Lyle K  ( 2016-02-08 20:15:41 -0600 )edit

Hi, I have the same issue trying to upload a load profile into open studio. Where would I save the above script to? I'm new to open studio.

eddieb's avatar eddieb  ( 2016-12-01 19:41:03 -0600 )edit
2

I took Julien's code and put it into a measure. For the measure to work, the csv file must be formatted as specified in the instructions. It also must be saved in the same folder as the measure. You enter the name of the csv file as an input when you run the measure. I used this to build a load profile which I then used as the demand side for a district heating loop I modeled in OpenStudio.

Derek.Fehrer's avatar Derek.Fehrer  ( 2018-04-05 10:31:11 -0600 )edit
MatthewSteen's avatar MatthewSteen  ( 2018-06-13 12:05:01 -0600 )edit
4

answered 2016-01-25 11:45:32 -0600

Schedule:File is not currently supported by OpenStudio. OpenStudio 2.0 will have better support for external files; Schedule:File could be considered for integration after OpenStudio 2.0 is released. In the meantime, you can use the ScheduleInterval object in OpenStudio, this object pulls the information from the schedule into the OSM. You can create a ScheduleInterval from a TimeSeries object using ScheduleInterval.fromTimeSeries. You can create a TimeSeries using the Ruby API, this is probably the constructor you want. The constructor takes an OpenStudio::Vector object which is a little awkward to work with, here are some examples.

edit flag offensive delete link more

Comments

Dan, is schedule file now supported? Thanks!

VictoriaEagen's avatar VictoriaEagen  ( 2016-04-07 09:15:16 -0600 )edit

Not yet, won't be until after September

macumber's avatar macumber  ( 2016-04-07 13:01:08 -0600 )edit

Dan, I see that this is an old post, but I have the same question with OS 2.4. Is there a way to import an external schedule file into OS? Thanks!

kheine's avatar kheine  ( 2018-01-30 12:58:47 -0600 )edit

I have exactly the same question. Any updates on this? Thanks!

JohannesBk's avatar JohannesBk  ( 2018-02-02 02:09:27 -0600 )edit
2

We are actually planning to include Schedule:File in OS 2.6.0 due out in June 2018. I will update this thread with news as it is available.

macumber's avatar macumber  ( 2018-02-02 11:22:11 -0600 )edit

Your Answer

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

Add Answer

Training Workshops

Careers

Question Tools

7 followers

Stats

Asked: 2016-01-25 11:12:44 -0600

Seen: 2,060 times

Last updated: Apr 23 '19