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

Cannot run an OS simulation with External:File schedule

asked 2020-06-23 05:51:09 -0500

Optimulate's avatar

updated 2020-06-23 09:36:17 -0500

Hi all,

I am trying to assign occupancy schedules to spaces with some Ruby code, taking inspiration from various posts and links here, amongst which these: - https://unmethours.com/question/36508... - https://unmethours.com/question/21623... - https://github.com/NREL/OpenStudio-re...

Problem: I have succeeded attaching a schedule from a csv file, but I cannot seem to get a simulation to run with it.

I have written a small script that opens an existing osm model, loads a csv schedule file, assigns it to a space and saves the resulting model to a new file. Note, it is not written as a measure, just as a separate script taking a file, altering it and saving it:

# Load the model
load_path = 'C:/Data/small_hotel.osm'
model = osload(load_path)    

# Do stuff: add an occupancy schedule to a room
space_name = 'GuestRoom101'
space = model.getSpaceByName(space_name)
if space.empty?
    raise "Troubles! space #{space_name} not found"
else
    space = space.get
end

# load schedule file
file_name = 'C:/Data/occupancy.csv'
file_name = File.realpath(file_name)
external_file = OpenStudio::Model::ExternalFile::getExternalFile(model, file_name)
external_file = external_file.get
schedule_file = OpenStudio::Model::ScheduleFile.new(external_file, 2, 1)

# assign schedule
space.setNumberOfPeople(2)
space.people.each do |people|
    puts "Setting schedule"
    people.setNumberofPeopleSchedule(schedule_file)
end    

# Save altered model to new file
save_openstudio_osm(model, {"osm_save_directory" => Dir.pwd, "osm_name" => "adjusted.osm"})

(the osload and save_openstudio_osm functions are borrowed from the second and third links above)

So far, so good. The new file 'adjusted.osm' is created. However, I cannot get it to simulate when loading it into the OpenStudio application. (the original file small_hotel.osm runs without issue). The error: **FATAL:Errors occurred on processing input file. Preceding condition(s) cause termination.

Inspection of eplusout.err shows: Last severe error=<root>[Schedule:File][Schedule File 1] - Missing required property 'file_name'.

The adjusted.osm file has the following on the external file:

OS:External:File,
  {5e1362cb-4ffd-4f21-ab35-f9cec70db42c}, !- Handle
  External File 1,                        !- Name
  occupancy.csv;                          !- File Name

OS:Schedule:File,
  {498a19ac-99d4-4840-8f04-5784ce6cc1e5}, !- Handle
  Schedule File 1,                        !- Name
  {64b87186-ef59-4b65-addf-7e476f6f2109}, !- Schedule Type Limits Name
  {5e1362cb-4ffd-4f21-ab35-f9cec70db42c}, !- External File Name
  2,                                      !- Column Number
  1;                                      !- Rows to Skip at Top

I think that the file 'occupance.csv' is not found, but I don't know how to solve this. I have tried replacing it with an absolute path, but that also does not work. Moving it to the same location as the weatherfile also doesn't help.

Would anyone know how to resolve this?

edit retag flag offensive close merge delete

Comments

Update: When I put my code into a measure, I can (fortunately) successfully add that to a simulation and hence simulate using the new schedule.

This solves my most urgent need. However, it would still be nice to be able to link such external files to osm files, so hoping someone has some insight on this.

Optimulate's avatar Optimulate  ( 2020-06-24 06:43:11 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-06-27 23:20:47 -0500

If you look at how ExternalFile works you will see that it looks for your CSV file in the model's OSW workflow paths. Most likely your osload command is not searching for an OSW and attaching it to the model using setWorkflow. OpenStudio considers the OSW to be part of the model so you should create one and save alongside your OSM file. There are some helper methods in FileOperations.hpp to help with this.

edit flag offensive delete link more

Comments

Thank you Macumber! That must indeed have been the issue. Thank you for pointing me to this information. With this I'm sure I can get it to work. (For now, I have switched to an approach to load the csv as a measure instead, which also gives me the required results)

Optimulate's avatar Optimulate  ( 2020-06-29 21:09:57 -0500 )edit

Your Answer

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

Add Answer

Careers

Question Tools

2 followers

Stats

Asked: 2020-06-23 05:51:09 -0500

Seen: 207 times

Last updated: Jun 27 '20