MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / getTimeSeries

Method getTimeSeries

src/utilities/filetypes/EpwFile.cpp:4526–4578  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4524}
4525
4526boost::optional<TimeSeries> EpwFile::getTimeSeries(const std::string& name) {
4527 if (m_data.empty()) {
4528 if (!openstudio::filesystem::exists(m_path) || !openstudio::filesystem::is_regular_file(m_path)) {
4529 LOG_AND_THROW("Path '" << m_path << "' is not an EPW file");
4530 }
4531
4532 // set checksum
4533 m_checksum = openstudio::checksum(m_path);
4534
4535 // open file
4536 std::ifstream ifs(openstudio::toSystemFilename(m_path));
4537
4538 if (!parse(ifs, true)) {
4539 ifs.close();
4540 LOG(Error, "EpwFile '" << toString(m_path) << "' cannot be processed");
4541 return boost::none;
4542 }
4543 ifs.close();
4544 }
4545 EpwDataField id;
4546 try {
4547 id = EpwDataField(name);
4548 } catch (...) {
4549 LOG(Warn, "Unrecognized EPW data field '" << name << "'");
4550 return boost::none;
4551 }
4552 if (!m_data.empty()) {
4553 std::string units = EpwDataPoint::getUnits(id);
4554 DateTimeVector dates;
4555 dates.push_back(DateTime()); // Use a placeholder to avoid an insert
4556 std::vector<double> values;
4557 for (unsigned int i = 0; i < m_data.size(); i++) {
4558 DateTime dateTime = m_data[i].dateTime();
4559 // Time time=m_data[i].time();
4560 boost::optional<double> value = m_data[i].getField(id);
4561 if (value) {
4562 if (isActual()) {
4563 dates.push_back(DateTime(dateTime));
4564 } else {
4565 // Strip year
4566 dates.push_back(DateTime(Date(dateTime.date().monthOfYear(), dateTime.date().dayOfMonth()), dateTime.time()));
4567 }
4568 values.push_back(value.get());
4569 }
4570 }
4571 if (!values.empty()) {
4572 DateTime start = dates[1] - Time(0, 0, 0, 3600 / m_recordsPerHour);
4573 dates[0] = start; // Overwrite the placeholder
4574 return boost::optional<TimeSeries>(TimeSeries(dates, openstudio::createVector(values), units));
4575 }
4576 }
4577 return boost::none;
4578}
4579
4580boost::optional<TimeSeries> EpwFile::getComputedTimeSeries(const std::string& name) {
4581 if (m_data.empty()) {

Callers 2

test_time_seriesMethod · 0.80
TESTFunction · 0.80

Calls 15

toSystemFilenameFunction · 0.85
createVectorFunction · 0.85
dateTimeMethod · 0.80
monthOfYearMethod · 0.80
DateTimeClass · 0.70
DateClass · 0.70
TimeClass · 0.70
TimeSeriesClass · 0.70
checksumFunction · 0.50
toStringFunction · 0.50
emptyMethod · 0.45
closeMethod · 0.45

Tested by 2

test_time_seriesMethod · 0.64
TESTFunction · 0.64