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

Issue running OSM through Ruby

asked 2016-08-24 16:54:41 -0500

jugonzal07's avatar

updated 2017-08-05 07:56:28 -0500

Hi all,

I'm working on a script that will grab all osm files in a directory and simulate them. I took some pointers from an example file called RunAllOSMs.rb but hit a snag. Mostly I'm finding it difficult to understand what exactly goes on throughout certain parts of that script. Below you'll find my attempt at modifying RunAllOSMs.rb to fit my needs:

Link to RunAllOSMs.rb

Relevant snippet from my ruby script:

#simulate all osms
puts "\nBeginning simulations..."

#set OS paths
output_os_path = OpenStudio::Path.new(output_dir)
weather_os_path = OpenStudio::system_complete(OpenStudio::Path.new(weather_file_dir))

#Create run manager
runManagerDBPath = output_os_path / OpenStudio::Path.new("RunManager.db")
puts "Creating RunManager database at " + runManagerDBPath.to_s + "."
OpenStudio::remove(runManagerDBPath) if (OpenStudio::exists(runManagerDBPath))
runManager = OpenStudio::Runmanager::RunManager.new(runManagerDBPath,true)

# find energyplus
ep_path = OpenStudio::Path.new('C:\EnergyPlusV8-5-0')
tools = OpenStudio::Runmanager::ConfigOptions::makeTools(ep_path.parent_path(),
                                                         OpenStudio::Path.new,
                                                         OpenStudio::Path.new,
                                                         OpenStudio::Path.new,
                                                         OpenStudio::Path.new)

#Loop through each osm in output directory and simulate them
Dir[output_dir + "/*.osm"].each do |osm_file|

  #Add osm to queue
  relative_file_path = OpenStudio::relativePath(OpenStudio::Path.new(osm_file),output_os_path)
  puts "Queuing simulation job for " + osm_file.to_s + "."

  osm_path = output_os_path/relative_file_path

  #create workflow
  workflow = OpenStudio::Runmanager::Workflow.new("modeltoidf->energyplus->openstudiopostprocess")
  workflow.setInputFiles(osm_path, weather_os_path)
  workflow.add(tools)

  # create and queue job
  jobDirectory = osm_path.parent_path() / OpenStudio::Path.new(osm_path.stem()) / OpenStudio::Path.new("/")
  puts "Job directory will be '" + jobDirectory.to_s + "'."
  job = workflow.create(jobDirectory)
  runManager.enqueue(job, true)
end

Here is the error I receive when running my script:

[utilities.idf.Workspace] <1> URL Found in IDF: file:files/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw but no source could be located.

This epw file is in the directory specified under weather_file_dir, so I'm confused as to why this happens. The line that causes this print out is the following:

job = workflow.create(jobDirectory)

From what I can tell, the directories are being assigned correctly, so I'm guessing it maybe due to my understanding of what happens with my workflow object? Do I have to somehow tell it to create that files directory and populate it with the epw file beforehand? Any advice would be greatly appreciated. I haven't had much success understanding the documentation.

Thanks!

~Update~ I noticed the job directory for the simulated osms APPEARS to find the epw file. I noticed a file called "in.epw" is placed into the ModelToIdf/EnergyPlus-0 directory that matches the epw file associated with the osm. Does this have to do with the constructor parameter I'm using for workflow? I.e. this line:

workflow = OpenStudio::Runmanager::Workflow.new("modeltoidf->energyplus->openstudiopostprocess")

The job types used in the parameter passed to the constructor I copied from the RunAllOSMs.rb file and they seem to match what I'm looking for. Anyhow, still stumped why i'm receiving the above error.

RESOLUTION: ep_path needs to be set directly to the Energy+.idd file, not just the E+ directory:

ep_path = OpenStudio::Path.new('C:/EnergyPlusV8-5-0/#Energy+.idd')

Though not ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
5

answered 2016-08-24 19:40:44 -0500

The really good news is that this task will be much easier with the OpenStudio Command Line Interface (CLI) coming out soon.

However, for your current script I think you may be calling the wrong version of the create method. I think you want to call this version of the create method:

  /// Creates a Job tree from the current workflow
  ///
  /// \param[in] outdir Output directory to be applied to the first job in the Workflow (child jobs inherit the outdir)
  /// \param[in] infile Input file to be attached to the first job in the workflow
  /// \param[in] epwdirorfile EPW file or directory containing EPW files to be search when looking for the appropriate
  ///                         EPW for energyplus simulation of infile
  /// \param[in] t_url_search_paths paths to search while normalizing any URLs in IDFs or OSMs that exist in the workflow
  openstudio::runmanager::Job create(
      const openstudio::path &outdir,
      const openstudio::path &infile,
      const openstudio::path &epwdirorfile = openstudio::path(),
      const std::vector<openstudio::URLSearchPath> &t_url_search_paths = std::vector<openstudio::URLSearchPath>());
edit flag offensive delete link more

Comments

Many thanks for your advice! Quick question-- in the example script it seems they set the osm path and epw file path in the workflow object by doing:

workflow.setInputFiles(osm_path,weather_os_path)

and then called the create function with only the outdir (ie this one).

Is there a difference in doing it one way than another? Also, I got the same error when attempting:

job = workflow.create(jobDirectory, osm_path,weather_os_path)

I noticed something new btw, see original post.

jugonzal07's avatar jugonzal07  ( 2016-08-25 09:36:15 -0500 )edit
1

What is your current error?

macumber's avatar macumber  ( 2016-08-25 11:39:05 -0500 )edit

Oh sorry, same error as before:

[utilities.idf.Workspace] <1> URL Found in IDF: file:files/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw but no source could be located.
jugonzal07's avatar jugonzal07  ( 2016-08-25 11:48:41 -0500 )edit
1

Hmm, I know that the Workflow::create method I pointed you to (with explicit argument for the weather file) overrides the EPW file path in the OSM (which is why I pointed you to that one). I would try removing/commenting out the WeatherFile object in your OSM and see if things work.

macumber's avatar macumber  ( 2016-08-25 12:22:32 -0500 )edit

So, I got it working after some issues. Now that I got it working, i'm not sure what I did to get the in.epw created, it's got me super stumped.

The good news: my issue was that weather_os_path pointed to the directory containing the epw file, not the epw file itself. Same for ep_path variable, that pointed to the directory with Energy+.idd but it needs to point directly to that file. Once I pointed those variables to the appropriate files, not just directories, the simulations ran just fine.

jugonzal07's avatar jugonzal07  ( 2016-08-25 14:07:16 -0500 )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

1 follower

Stats

Asked: 2016-08-24 16:54:41 -0500

Seen: 283 times

Last updated: Aug 25 '16