28#include "ndarray/eigen.h"
41template <
typename MaskedImageT>
44 explicit FootprintBits() : _anyBits(0), _allBits(~static_cast<typename MaskedImageT::Mask::Pixel>(0x0)) {}
49 _allBits = ~static_cast<typename MaskedImageT::Mask::Pixel>(0x0);
52 void operator()(
geom::Point2I const& point,
typename MaskedImageT::Mask::Pixel
const& value) {
58 typename MaskedImageT::Mask::Pixel getAnyBits()
const {
return _anyBits; }
60 typename MaskedImageT::Mask::Pixel getAllBits()
const {
return _allBits; }
63 typename MaskedImageT::Mask::Pixel _anyBits;
64 typename MaskedImageT::Mask::Pixel _allBits;
67typedef afw::image::MaskedImage<float> MaskedImageF;
71 const FootprintBits<MaskedImageF>& func, afw::table::SourceRecord& measRecord) {
72 for (
auto const& i : maskFlagToPixelFlag) {
74 if (func.getAnyBits() & MaskedImageF::Mask::getPlaneBitMask(i.first)) {
75 measRecord.set(i.second,
true);
77 }
catch (pex::exceptions::InvalidParameterError& err) {
85 const FootprintBits<MaskedImageF>& func, afw::table::SourceRecord& measRecord) {
86 for (
auto const& i : maskFlagToPixelFlag) {
88 if (func.getAllBits() & MaskedImageF::Mask::getPlaneBitMask(i.first)) {
89 measRecord.set(i.second,
true);
91 }
catch (pex::exceptions::InvalidParameterError& err) {
103 _generalFailureKey = schema.addField<afw::table::Flag>(
104 name +
"_flag",
"General failure flag, set if anything went wrong");
106 schema.addField<afw::table::Flag>(name +
"_flag" +
"_offimage",
"Source center is off image");
108 _anyKeys[
"EDGE"] = schema.addField<afw::table::Flag>(
110 "Source is outside usable exposure region (masked EDGE or NO_DATA, or centroid off image)");
111 _anyKeys[
"INTRP"] = schema.addField<afw::table::Flag>(name +
"_flag_interpolated",
112 "Interpolated pixel in the Source footprint");
113 _anyKeys[
"SAT"] = schema.addField<afw::table::Flag>(name +
"_flag_saturated",
114 "Saturated pixel in the Source footprint");
116 schema.addField<afw::table::Flag>(name +
"_flag_cr",
"Cosmic ray in the Source footprint");
118 schema.addField<afw::table::Flag>(name +
"_flag_bad",
"Bad pixel in the Source footprint");
119 _anyKeys[
"SUSPECT"] = schema.addField<afw::table::Flag>(name +
"_flag_suspect",
120 "Source's footprint includes suspect pixels");
122 _centerKeys[
"INTRP"] = schema.addField<afw::table::Flag>(
123 name +
"_flag_interpolatedCenter",
"Interpolated pixel in the 3x3 region around the centroid.");
124 _centerKeys[
"SAT"] = schema.addField<afw::table::Flag>(
125 name +
"_flag_saturatedCenter",
"Saturated pixel in the 3x3 region around the centroid.");
126 _centerKeys[
"CR"] = schema.addField<afw::table::Flag>(
127 name +
"_flag_crCenter",
"Cosmic ray in the 3x3 region around the centroid.");
128 _centerKeys[
"BAD"] = schema.addField<afw::table::Flag>(name +
"_flag_badCenter",
129 "Bad pixel in the 3x3 region around the centroid");
130 _centerKeys[
"SUSPECT"] = schema.addField<afw::table::Flag>(
131 name +
"_flag_suspectCenter",
"Suspect pixel in the 3x3 region around the centroid.");
134 _centerAllKeys[
"INTRP"] = schema.addField<afw::table::Flag>(
135 name +
"_flag_interpolatedCenterAll",
136 "All pixels in the 3x3 region around the centroid are interpolated.");
137 _centerAllKeys[
"SAT"] = schema.addField<afw::table::Flag>(
138 name +
"_flag_saturatedCenterAll",
139 "All pixels in the 3x3 region around the centroid are saturated.");
140 _centerAllKeys[
"CR"] = schema.addField<afw::table::Flag>(
141 name +
"_flag_crCenterAll",
142 "All pixels in the 3x3 region around the centroid have the cosmic ray mask bit.");
143 _centerAllKeys[
"BAD"] = schema.addField<afw::table::Flag>(
144 name +
"_flag_badCenterAll",
"All pixels in the 3x3 region around the centroid are bad.");
145 _centerAllKeys[
"SUSPECT"] = schema.addField<afw::table::Flag>(
146 name +
"_flag_suspectCenterAll",
"All pixels in the 3x3 region around the centroid are suspect.");
152 _centerKeys[
i] = schema.addField<afw::table::Flag>(
153 name +
"_flag_" +
maskName +
"Center",
"3x3 region around the centroid has " +
i +
" pixels");
158 _centerAllKeys[
i] = schema.addField<afw::table::Flag>(
159 name +
"_flag_" +
maskName +
"CenterAll",
160 "All pixels in the 3x3 region around the source centroid are " +
i +
" pixels");
166 _anyKeys[
i] = schema.addField<afw::table::Flag>(name +
"_flag_" +
maskName,
167 "Source footprint includes " +
i +
" pixels");
178 if (
measRecord.getTable()->getCentroidSlot().getMeasKey().isValid()) {
192 if (!footprint || footprint->getPeaks().empty()) {
195 center.setX(footprint->getPeaks().front().getFx());
196 center.setY(footprint->getPeaks().front().getFy());
203 if (!
bbox.contains(center)) {
212 (boost::format(
"Source id %d has no footprint.") %
measRecord.getId()).str());
218 (boost::format(
"Source id %d has no spans in footprint.") %
measRecord.getId()).str());
224 if (
func.getAnyBits() & MaskedImageF::Mask::getPlaneBitMask(
"NO_DATA")) {
236 (boost::format(
"Centroid of source id %d passed to PixelFlags is non-finite; "
237 "footprint-based flags have been set, but centroid-based flags will not be.") %
#define LSST_EXCEPT(type,...)
This is the algorithm for PixelFlags.
Exception to be thrown when a measurement algorithm experiences a fatal error.
Exception to be thrown when a measurement algorithm experiences a known failure mode.
std::map< std::string, afw::table::Key< afw::table::Flag > > KeyMap
virtual void fail(afw::table::SourceRecord &measRecord, MeasurementError *error=nullptr) const
Handle an exception thrown by the current algorithm by setting flags in the given record.
PixelFlagsAlgorithm(Control const &ctrl, std::string const &name, afw::table::Schema &schema)
virtual void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
Called to measure a single child source in an image.
A C++ control class to handle PixelFlagsAlgorithm's configuration.
std::vector< std::string > masksFpAnywhere
"List of mask planes to be searched for which occur anywhere within a footprint. " "If any of the pla...
std::vector< std::string > masksFpCenter
"List of mask planes to be searched for which occur in the center of a footprint. " "If any of the pl...
int positionToIndex(double pos)