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/how-to-create-measure-for-replacing-occupancy-schedule-with-csv-file/ - https://unmethours.com/question/21623/openstudio-measure-interactive-debugging/ - https://github.com/NREL/OpenStudio-resources/blob/develop/model/simulationtests/schedule_file.rb#L47-L52
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?