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

EpwFile .getTimeSeries method fails if the weather file represents a leap year #3801

Closed
mdahlhausen opened this issue Dec 6, 2019 · 3 comments · Fixed by #3805
Closed

EpwFile .getTimeSeries method fails if the weather file represents a leap year #3801

mdahlhausen opened this issue Dec 6, 2019 · 3 comments · Fixed by #3805

Comments

@mdahlhausen
Copy link
Collaborator

Steps to recreate bug:

  1. get a weather file with a leap year (Feb 29)
  2. Run:
weather_file = 'path/to/weather_file.epw'
epw = OpenStudio::EpwFile.new(weather_file)
epw.getTimeSeries('Dry Bulb Temperature')

Error:

[utilities.time.Date] <2> Bad Date: year = 2009, month = Feb(2), day = 29. 
C:/Users/mdahlhau/Desktop/EULP/analyze_weather.rb:17:in `getTimeSeries': C:\Users\jenkins\git\OpenStudio\openstudiocore\src\utilities\time\Date.cpp@446 : Bad Date: year = 2009, month = Feb(2), day = 29.  (RuntimeError)
@jmarrec
Copy link
Collaborator

jmarrec commented Dec 9, 2019

EpwDataPoint doesn't include the year in its date() method (while it does store it correctly):

return Date(MonthOfYear(m_month), m_day); // , m_year);


Unrelated: found a couple of typos while investigating this:

int year = std::stoi(split[1]);

int year = std::stoi(split[1]);

@jmarrec
Copy link
Collaborator

jmarrec commented Dec 9, 2019

@mdahlhausen If you need a workaround immediately:

# id = OpenStudio::EpwDataField.new("Dry Bulb Temperature")
# units = OpenStudio::EpwDataPoint::getUnits(id)
units = 'C'
dates = OpenStudio::DateTimeVector.new()
values = []

epw.data.each do |pt|
  dates << OpenStudio::DateTime.new(OpenStudio::Date.new(OpenStudio::MonthOfYear.new(pt.month), pt.day, pt.year), pt.time)             
  values << pt.dryBulbTemperature.get
  # or
  # values << pt.getField(id).get
end  

t = OpenStudio::TimeSeries.new(dates, OpenStudio::createVector(values), units)

t.firstReportDateTime.to_s
=> "2012-Jan-01 01:00:00"

@mdahlhausen
Copy link
Collaborator Author

Thanks @jmarrec. I ended up just removing the leap year days from my weather files, but your method is more elegant.

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.

3 participants