Skip to content

Commit

Permalink
Try a different approach of returning the correct m_data.
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-robertson committed Jun 5, 2024
1 parent bbf02eb commit 97fb63c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
17 changes: 10 additions & 7 deletions src/utilities/filetypes/EpwFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3630,7 +3630,7 @@ std::vector<EpwDesignCondition> EpwFile::designConditions() {
return m_designs;
}

boost::optional<TimeSeries> EpwFile::getTimeSeries(const std::string& name, bool isActualOverride) {
boost::optional<TimeSeries> EpwFile::getTimeSeries(const std::string& name) {
if (m_data.empty()) {
if (!openstudio::filesystem::exists(m_path) || !openstudio::filesystem::is_regular_file(m_path)) {
LOG_AND_THROW("Path '" << m_path << "' is not an EPW file");
Expand All @@ -3656,7 +3656,6 @@ boost::optional<TimeSeries> EpwFile::getTimeSeries(const std::string& name, bool
LOG(Warn, "Unrecognized EPW data field '" << name << "'");
return boost::none;
}
DateTime feb29(Date(MonthOfYear::Feb, 29, 2012), Time(0, 0, 0, 0)); // year is arbitrary here since we won't be using it
if (!m_data.empty()) {
std::string units = EpwDataPoint::getUnits(id);
DateTimeVector dates;
Expand All @@ -3667,13 +3666,9 @@ boost::optional<TimeSeries> EpwFile::getTimeSeries(const std::string& name, bool
// Time time=m_data[i].time();
boost::optional<double> value = m_data[i].getField(id);
if (value) {
if (isActual() || isActualOverride) {
if (isActual()) {
dates.push_back(DateTime(dateTime));
} else {
if ((dateTime.date().monthOfYear() == feb29.date().monthOfYear()) && (dateTime.date().dayOfMonth() == feb29.date().dayOfMonth())
&& (dateTime.time() == feb29.time())) { // if we're here then assume we don't actually have a Feb 29
DateTime dateTime(Date(MonthOfYear::Mar, 1), dateTime.time());
}
// Strip year
dates.push_back(DateTime(Date(dateTime.date().monthOfYear(), dateTime.date().dayOfMonth()), dateTime.time()));
}
Expand Down Expand Up @@ -3953,6 +3948,14 @@ bool EpwFile::parse(std::istream& ifs, bool storeData) {
m_minutesMatch = false;
}
}

// Fix for #5214: for TMY files where Feb is from a leap year, we need xxxx-Mar-01 01:00:00 and not xxxx-Feb-29 00:00:00
if (!realYear && (month == 2) && (day == 28) && (hour == 24) && (currentMinute == 0)) {
if (Date(MonthOfYear::Jan, 1, year).isLeapYear()) {
day = 29;
}
}

boost::optional<EpwDataPoint> pt = EpwDataPoint::fromEpwStrings(year, month, day, hour, currentMinute, strings);
if (pt) {
m_data.push_back(pt.get());
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/filetypes/EpwFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ class UTILITIES_API EpwFile

/// get a time series of a particular weather field
// This will probably need to include the period at some point, but for now just dump everything into a time series
boost::optional<TimeSeries> getTimeSeries(const std::string& field, bool isActualOverride = false);
boost::optional<TimeSeries> getTimeSeries(const std::string& field);
/// get a time series of a computed quantity
boost::optional<TimeSeries> getComputedTimeSeries(const std::string& field);

Expand Down
4 changes: 3 additions & 1 deletion src/utilities/filetypes/test/EpwFile_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,10 @@ TEST(Filetypes, EpwFile_LeapTimeSeries_TMYLeapFebLeapDay) {
try {
path p = resourcesPath() / toPath("utilities/Filetypes/USA_CO_Golden-NREL.724666_TMY3-leapday.epw");
EpwFile epwFile(p);
boost::optional<TimeSeries> _t;
ASSERT_THROW(_t = epwFile.getTimeSeries("Dry Bulb Temperature"));
} catch (...) {
ASSERT_TRUE(true);
ASSERT_TRUE(false);
}
}

Expand Down

0 comments on commit 97fb63c

Please sign in to comment.