-
Notifications
You must be signed in to change notification settings - Fork 193
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
Addresses #5214, EpwFile getTimeSeries fails for leap year weather file w/no leap day #5217
Conversation
After a bit of digging, it appears that Therefore we fall into this block instead of this one. If |
Ah ha, here's the core issue. For all 3 of the above scenarios,
This is the line that fails. The assumedYear in the Data ctor here is 2009, and so fails on the line above. Why doesn't the EpwDataPoint have a dateTime of Answer:
|
src/utilities/filetypes/EpwFile.cpp
Outdated
@@ -3967,6 +3974,31 @@ bool EpwFile::parse(std::istream& ifs, bool storeData) { | |||
} | |||
} | |||
|
|||
for (unsigned int i = 0; i < epw_strings.size(); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do this after the previous loop, instead of inside it, because we first need to get realYear
.
The fix looks good. I tried it on Windows with a couple of different weather files that had the issue before and everything seems to work. Thanks for resolving this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @joseph-robertson. I left a few pedantic comments about coding nitpicks. You can take them or leave them.
I like the additional unit test coverage, otherwise I'd have a hard time knowing for sure that the approach works.
src/utilities/filetypes/EpwFile.cpp
Outdated
@@ -3887,6 +3887,17 @@ bool EpwFile::parse(std::istream& ifs, bool storeData) { | |||
return false; | |||
} | |||
|
|||
struct epw_string | |||
{ | |||
int lineNumber; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps these can be const based on your use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed int
to const int
.
src/utilities/filetypes/EpwFile.cpp
Outdated
@@ -3887,6 +3887,17 @@ bool EpwFile::parse(std::istream& ifs, bool storeData) { | |||
return false; | |||
} | |||
|
|||
struct epw_string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a type, wouldn't it be more aligned with our conventions to call it EPWString
, or otherwise start with an uppercase letter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed epw_string
to EPWString
.
src/utilities/filetypes/EpwFile.cpp
Outdated
return false; | ||
} | ||
epw_string epw_s = {lineNumber, year, month, day, hour, currentMinute, strings}; | ||
epw_strings.push_back(epw_s); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could save a copy by doing the construction in place. push_back
will perform move and save a copy. Here it doesn't matter that much because the copy is presumably super cheap. Something like this...
epw_strings.push_back({lineNumber, year, month, day, hour, currentMinute, strings});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
epw_strings.emplace_back(lineNumber, year, month, day, hour, currentMinute, std::move(strings));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably do epw_strings.reserve(8760)
before looping?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A benchmark: https://github.com/jmarrec/CppBenchmarks/blob/main/bench_EPWStrings.cpp
For the 8760 records case (most common), time in nanoseconds:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/utilities/filetypes/EpwFile.cpp
Outdated
@@ -3967,6 +3974,31 @@ bool EpwFile::parse(std::istream& ifs, bool storeData) { | |||
} | |||
} | |||
|
|||
for (unsigned int i = 0; i < epw_strings.size(); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't
for (const auto &epw_string: epw_strings) {
...
...
}
be a bit more modern? I don't believe you need the index, unless I missed it.
src/utilities/filetypes/EpwFile.cpp
Outdated
int month = epw_strings[i].month; | ||
int day = epw_strings[i].day; | ||
int hour = epw_strings[i].hour; | ||
int currentMinute = epw_strings[i].currentMinute; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making these copies seems superfluous. Perhaps you could just use epw_string.currentMinute
when you need to access these members. At minimum they could be const.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving all epw_string.month
, epw_string.day
, etc to where they are used below.
|
||
boost::optional<EpwDataPoint> pt = EpwDataPoint::fromEpwStrings(year, month, day, hour, currentMinute, epw_strings[i].strings); | ||
if (pt) { | ||
m_data.push_back(pt.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the temporary pt
makes sense to me since you have the push_back
protected by a conditional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m_data.emplace_back(std::move(*pt))
src/utilities/filetypes/EpwFile.cpp
Outdated
if ((!realYear) && (month == 2) && (day == 28) && (hour == 24) && (currentMinute == 0)) { | ||
Date date(month, day, year); | ||
if (date.isLeapYear()) { | ||
day = 29; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main fix, right in here.
src/utilities/filetypes/EpwFile.cpp
Outdated
@@ -3967,6 +3974,31 @@ bool EpwFile::parse(std::istream& ifs, bool storeData) { | |||
} | |||
} | |||
|
|||
for (unsigned int i = 0; i < epw_strings.size(); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this PR might increase slightly the EpwFile::parse time. This is because we now essentially have 2 loops that run through epw lines. I'm open to suggestions here for a better approach...
src/utilities/filetypes/EpwFile.cpp
Outdated
@@ -3887,6 +3887,17 @@ bool EpwFile::parse(std::istream& ifs, bool storeData) { | |||
return false; | |||
} | |||
|
|||
struct epw_string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed epw_string
to EPWString
.
src/utilities/filetypes/EpwFile.cpp
Outdated
@@ -3887,6 +3887,17 @@ bool EpwFile::parse(std::istream& ifs, bool storeData) { | |||
return false; | |||
} | |||
|
|||
struct epw_string | |||
{ | |||
int lineNumber; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed int
to const int
.
|
||
boost::optional<EpwDataPoint> pt = EpwDataPoint::fromEpwStrings(year, month, day, hour, currentMinute, epw_strings[i].strings); | ||
if (pt) { | ||
m_data.push_back(pt.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No action.
src/utilities/filetypes/EpwFile.cpp
Outdated
int month = epw_strings[i].month; | ||
int day = epw_strings[i].day; | ||
int hour = epw_strings[i].hour; | ||
int currentMinute = epw_strings[i].currentMinute; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving all epw_string.month
, epw_string.day
, etc to where they are used below.
CI Results for 15e17d3:
|
Pull request overview
As far as I can tell, the
Bad Date: year = 2009, month = Feb(2), day = 29.
error is thrown for each of the following scenarios:Possible solutions:
isActualOverride
bool supplied toEpwFile::getTimeSeries
(demonstrated in this PR)m_data
to change xxxx-Feb-29 00:00:00 to xxxx-Mar-01 00:00:00 for TMY with leap FebPull Request Author
src/model/test
)src/energyplus/Test
)src/osversion/VersionTranslator.cpp
)Labels:
IDDChange
APIChange
Pull Request - Ready for CI
so that CI builds your PRReview Checklist
This will not be exhaustively relevant to every PR.