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

DM-38300: Stringification of an afwDetection.Threshold with stdev raises exception #681

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions python/lsst/afw/detection/_threshold.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ void wrapThreshold(utils::python::WrapperCollection& wrappers) {
std::ostringstream os;
std::string polarity = (self.getPolarity() == true) ? "positive" : "negative";
os << py::cast(self.getType()).attr("name").cast<std::string>() << std::setprecision(8)
<< " value=" << self.getValue() << " (" << polarity << ")";
<< " value=" << self.getValue(1.0) << " (" << polarity << ")";
if (self.getIncludeMultiplier() != 1.0) {
os << " multiplier=" << self.getIncludeMultiplier();
}
return os.str();
});
cls.def("__repr__", [](Threshold const& self) {
std::ostringstream os;
os << std::setprecision(16) << "Threshold(value=" << self.getValue()
os << std::setprecision(16) << "Threshold(value=" << self.getValue(1.0)
<< ", type=" << py::cast(self.getType()).attr("name").cast<std::string>()
<< ", polarity=" << self.getPolarity()
<< ", includeMultiplier=" << self.getIncludeMultiplier() << ")";
Expand Down
10 changes: 10 additions & 0 deletions tests/test_footprint1.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ def test_str(self):
self.assertEqual(repr(threshold),
"Threshold(value=2, type=VALUE, polarity=1, includeMultiplier=4)")

threshold = afwDetect.createThreshold(5, "stdev")
self.assertEqual(str(threshold), "STDEV value=5 (positive)")
self.assertEqual(repr(threshold),
"Threshold(value=5, type=STDEV, polarity=1, includeMultiplier=1)")

threshold = afwDetect.createThreshold(4, "variance")
self.assertEqual(str(threshold), "VARIANCE value=4 (positive)")
self.assertEqual(repr(threshold),
"Threshold(value=4, type=VARIANCE, polarity=1, includeMultiplier=1)")


class FootprintTestCase(lsst.utils.tests.TestCase):
"""A test case for Footprint"""
Expand Down