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

Revision history [back]

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)

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)