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>(
109 name +
"_flag_edge",
"Source is outside usable exposure region (masked EDGE or NO_DATA)");
110 _anyKeys[
"INTRP"] =
schema.addField<afw::table::Flag>(
name +
"_flag_interpolated",
111 "Interpolated pixel in the Source footprint");
112 _anyKeys[
"SAT"] =
schema.addField<afw::table::Flag>(
name +
"_flag_saturated",
113 "Saturated pixel in the Source footprint");
115 schema.addField<afw::table::Flag>(
name +
"_flag_cr",
"Cosmic ray in the Source footprint");
117 schema.addField<afw::table::Flag>(
name +
"_flag_bad",
"Bad pixel in the Source footprint");
118 _anyKeys[
"SUSPECT"] =
schema.addField<afw::table::Flag>(
name +
"_flag_suspect",
119 "Source's footprint includes suspect pixels");
121 _centerKeys[
"INTRP"] =
schema.addField<afw::table::Flag>(
122 name +
"_flag_interpolatedCenter",
"Interpolated pixel in the 3x3 region around the centroid.");
123 _centerKeys[
"SAT"] =
schema.addField<afw::table::Flag>(
124 name +
"_flag_saturatedCenter",
"Saturated pixel in the 3x3 region around the centroid.");
125 _centerKeys[
"CR"] =
schema.addField<afw::table::Flag>(
126 name +
"_flag_crCenter",
"Cosmic ray in the 3x3 region around the centroid.");
127 _centerKeys[
"BAD"] =
schema.addField<afw::table::Flag>(
name +
"_flag_badCenter",
128 "Bad pixel in the 3x3 region around the centroid");
129 _centerKeys[
"SUSPECT"] =
schema.addField<afw::table::Flag>(
130 name +
"_flag_suspectCenter",
"Suspect pixel in the 3x3 region around the centroid.");
133 _centerAllKeys[
"INTRP"] =
schema.addField<afw::table::Flag>(
134 name +
"_flag_interpolatedCenterAll",
135 "All pixels in the 3x3 region around the centroid are interpolated.");
136 _centerAllKeys[
"SAT"] =
schema.addField<afw::table::Flag>(
137 name +
"_flag_saturatedCenterAll",
138 "All pixels in the 3x3 region around the centroid are saturated.");
139 _centerAllKeys[
"CR"] =
schema.addField<afw::table::Flag>(
140 name +
"_flag_crCenterAll",
141 "All pixels in the 3x3 region around the centroid have the cosmic ray mask bit.");
142 _centerAllKeys[
"BAD"] =
schema.addField<afw::table::Flag>(
143 name +
"_flag_badCenterAll",
"All pixels in the 3x3 region around the centroid are bad.");
144 _centerAllKeys[
"SUSPECT"] =
schema.addField<afw::table::Flag>(
145 name +
"_flag_suspectCenterAll",
"All pixels in the 3x3 region around the centroid are suspect.");
151 _centerKeys[
i] =
schema.addField<afw::table::Flag>(
152 name +
"_flag_" +
maskName +
"Center",
"3x3 region around the centroid has " +
i +
" pixels");
157 _centerAllKeys[
i] =
schema.addField<afw::table::Flag>(
159 "All pixels in the 3x3 region around the source centroid are " +
i +
" pixels");
166 "Source footprint includes " +
i +
" pixels");
177 if (
measRecord.getTable()->getCentroidSlot().getMeasKey().isValid()) {
182 "Center point passed to PixelFlagsAlgorithm is NaN");
196 if (!footprint || footprint->getPeaks().empty()) {
199 center.setX(footprint->getPeaks().front().getFx());
200 center.setY(footprint->getPeaks().front().getFy());
223 if (
func.getAnyBits() & MaskedImageF::Mask::getPlaneBitMask(
"NO_DATA")) {
table::Key< std::string > name
#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)