Skip to content

Commit

Permalink
Add operator<< and __str__ for VisitInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
parejkoj committed Oct 31, 2017
1 parent 06fef9d commit b385a03
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/lsst/afw/image/VisitInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ class VisitInfo : public table::io::PersistableFacade<VisitInfo>, public table::
coord::Weather _weather;
};

std::ostream &operator<<(std::ostream &os, VisitInfo const &visitInfo);

namespace detail {

/**
Expand Down
6 changes: 6 additions & 0 deletions python/lsst/afw/image/visitInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ PYBIND11_PLUGIN(visitInfo) {
cls.def("getLocalEra", &VisitInfo::getLocalEra);
cls.def("getBoresightHourAngle", &VisitInfo::getBoresightHourAngle);

cls.def("__str__", [](VisitInfo const &self) {
std::stringstream os;
os << self;
return os.str();
});

/* Free Functions */
mod.def("setVisitInfoMetadata", &detail::setVisitInfoMetadata, "metadata"_a, "visitInfo"_a);
mod.def("stripVisitInfoKeywords", &detail::stripVisitInfoKeywords, "metadata"_a);
Expand Down
20 changes: 20 additions & 0 deletions src/image/VisitInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,26 @@ void VisitInfo::write(OutputArchiveHandle& handle) const {
geom::Angle VisitInfo::getLocalEra() const { return getEra() + getObservatory().getLongitude(); }

geom::Angle VisitInfo::getBoresightHourAngle() const { return getLocalEra() - getBoresightRaDec()[0]; }

std::ostream& operator<<(std::ostream& os, VisitInfo const& visitInfo) {
os << "VisitInfo(";
os << "exposureId=" << visitInfo.getExposureId() << ", ";
os << "exposureTime=" << visitInfo.getExposureTime() << ", ";
os << "darkTime=" << visitInfo.getDarkTime() << ", ";
os << "date=" << visitInfo.getDate().toString(daf::base::DateTime::TAI) << ", ";
os << "UT1=" << visitInfo.getUt1() << ", ";
os << "ERA=" << visitInfo.getEra() << ", ";
os << "boresightRaDec=" << visitInfo.getBoresightRaDec() << ", ";
os << "boresightAzAlt=" << visitInfo.getBoresightAzAlt() << ", ";
os << "boresightAirmass=" << visitInfo.getBoresightAirmass() << ", ";
os << "boresightRotAngle=" << visitInfo.getBoresightRotAngle() << ", ";
os << "rotType=" << static_cast<int>(visitInfo.getRotType()) << ", ";
os << "observatory=" << visitInfo.getObservatory() << ", ";
os << "weather=" << visitInfo.getWeather();
os << ")";
return os;
}

} // namespace image
} // namespace afw
} // namespace lsst
22 changes: 22 additions & 0 deletions tests/test_visitInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,28 @@ def testBadRotTypes(self):
with self.assertRaises(lsst.pex.exceptions.RuntimeError):
afwImage.VisitInfo(metadata)

def test_str(self):
"""Check that we get something reasonable for str()"""
visitInfo = afwImage.VisitInfo(self.data1.exposureId,
self.data1.exposureTime,
self.data1.darkTime,
self.data1.date,
self.data1.ut1,
self.data1.era,
self.data1.boresightRaDec,
self.data1.boresightAzAlt,
self.data1.boresightAirmass,
self.data1.boresightRotAngle,
self.data1.rotType,
self.data1.observatory,
self.data1.weather,
)
string = str(visitInfo)
self.assertIn("exposureId=10313423", string)
self.assertIn("exposureTime=10.01", string)
self.assertIn("darkTime=11.02", string)
self.assertIn("rotType=1", string)


def setup_module(module):
lsst.utils.tests.init()
Expand Down

0 comments on commit b385a03

Please sign in to comment.