Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenstudioStandards.Weather.get_standards_weather_file_path error within OpenStudio CLI #1864

Closed
kbenne opened this issue Dec 12, 2024 · 1 comment · Fixed by #1866
Closed

Comments

@kbenne
Copy link
Contributor

kbenne commented Dec 12, 2024

I recently discovered that if you run an OpenStudio Workflow using the CLI and that workflow contains the create_DOE_prototype_building, an error will occur within OpenstudioStandards.Weather.get_standards_weather_file_path on this line of code.

The issue is that the code is attempting to create a new directory with a leading : in the path, because __dir__, which is the root of the path is an embedded file in this case.

I believe the desired behavior is for the path root to be Dir.pwd.

I implemented a work around by including the following code at the top of my Measure.

module OpenstudioStandards
  module Weather
    def self.get_standards_weather_file_path(weather_file_name)
      # Define where the weather files lives
      weather_dir = nil

      # load weather file from embedded files
      epw_string = File.read(":/ruby/3.2.0/gems/openstudio-standards-0.7.0/data/weather/#{weather_file_name}")
      ddy_string = File.read(":/ruby/3.2.0/gems/openstudio-standards-0.7.0/data/weather/#{weather_file_name.gsub('.epw', '.ddy')}")
      stat_string = File.read(":/ruby/3.2.0/gems/openstudio-standards-0.7.0/data/weather/#{weather_file_name.gsub('.epw', '.stat')}")

      # extract to local weather dir
      weather_dir = File.expand_path(File.join(Dir.pwd, 'extracted_files/weather/'))
      OpenStudio.logFree(OpenStudio::Info, 'openstudio.standards.Weather.information', "Extracting weather files from OpenStudio CLI to #{weather_dir}")
      FileUtils.mkdir_p(weather_dir)

      path_length = "#{weather_dir}/#{weather_file_name}".length
      if path_length > 260
        OpenStudio.logFree(OpenStudio::Warn, 'openstudio.standards.Weather.information', "Weather file path length #{path_length} is >260 characters and may cause issues in Windows environments.")
      end
      File.open("#{weather_dir}/#{weather_file_name}", 'wb') do |f|
        f.write(epw_string)
        #f.flush
      end
      File.open("#{weather_dir}/#{weather_file_name.gsub('.epw', '.ddy')}", 'wb') do |f|
        f.write(ddy_string)
        #f.flush
      end
      File.open("#{weather_dir}/#{weather_file_name.gsub('.epw', '.stat')}", 'wb') do |f|
        f.write(stat_string)
        #f.flush
      end

      # Add Weather File
      unless (Pathname.new weather_dir).absolute?
        weather_dir = File.expand_path(File.join(File.dirname(__FILE__), weather_dir))
      end

      weather_file_path = File.join(weather_dir, weather_file_name)

      return weather_file_path
    end
  end
end
@mdahlhausen
Copy link
Collaborator

Seems like this was an issue with Dir.pwd too per this error and changed in #1816.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants