28 #include "ndarray/eigen.h"
41 template <
typename MaskedImageT>
44 explicit FootprintBits() : _bits(0) {}
47 void reset() { _bits = 0x0; }
49 void operator()(
geom::Point2I const& point,
typename MaskedImageT::Mask::Pixel
const& value) {
54 typename MaskedImageT::Mask::Pixel getBits()
const {
return _bits; }
57 typename MaskedImageT::Mask::Pixel _bits;
60 typedef afw::image::MaskedImage<float> MaskedImageF;
63 const FootprintBits<MaskedImageF>& func, afw::table::SourceRecord& measRecord) {
64 for (
auto const& i : maskFlagToPixelFlag) {
66 if (func.getBits() & MaskedImageF::Mask::getPlaneBitMask(i.first)) {
67 measRecord.set(i.second,
true);
69 }
catch (pex::exceptions::InvalidParameterError& err) {
80 _generalFailureKey =
schema.addField<afw::table::Flag>(
81 name +
"_flag",
"General failure flag, set if anything went wrong");
83 schema.addField<afw::table::Flag>(
name +
"_flag" +
"_offimage",
"Source center is off image");
85 _anyKeys[
"EDGE"] =
schema.addField<afw::table::Flag>(
86 name +
"_flag_edge",
"Source is outside usable exposure region (masked EDGE or NO_DATA)");
87 _anyKeys[
"INTRP"] =
schema.addField<afw::table::Flag>(
name +
"_flag_interpolated",
88 "Interpolated pixel in the Source footprint");
89 _anyKeys[
"SAT"] =
schema.addField<afw::table::Flag>(
name +
"_flag_saturated",
90 "Saturated pixel in the Source footprint");
92 schema.addField<afw::table::Flag>(
name +
"_flag_cr",
"Cosmic ray in the Source footprint");
94 schema.addField<afw::table::Flag>(
name +
"_flag_bad",
"Bad pixel in the Source footprint");
95 _anyKeys[
"SUSPECT"] =
schema.addField<afw::table::Flag>(
name +
"_flag_suspect",
96 "Source's footprint includes suspect pixels");
98 _centerKeys[
"INTRP"] =
schema.addField<afw::table::Flag>(
name +
"_flag_interpolatedCenter",
99 "Interpolated pixel in the Source center");
100 _centerKeys[
"SAT"] =
schema.addField<afw::table::Flag>(
name +
"_flag_saturatedCenter",
101 "Saturated pixel in the Source center");
103 schema.addField<afw::table::Flag>(
name +
"_flag_crCenter",
"Cosmic ray in the Source center");
104 _centerKeys[
"SUSPECT"] =
schema.addField<afw::table::Flag>(
name +
"_flag_suspectCenter",
105 "Source's center is close to suspect pixels");
111 _centerKeys[i] =
schema.addField<afw::table::Flag>(
name +
"_flag_" + maskName +
"Center",
112 "Source center is close to " + i +
" pixels");
118 _anyKeys[i] =
schema.addField<afw::table::Flag>(
name +
"_flag_" + maskName,
119 "Source footprint includes " + i +
" pixels");
126 FootprintBits<MaskedImageF> func;
130 if (measRecord.
getTable()->getCentroidSlot().getMeasKey().isValid()) {
135 "Center point passed to PixelFlagsAlgorithm is NaN");
140 measRecord.
set(_generalFailureKey,
true);
149 if (!footprint || footprint->getPeaks().empty()) {
152 center.setX(footprint->getPeaks().front().getFx());
153 center.setY(footprint->getPeaks().front().getFy());
159 measRecord.
set(_offImageKey,
true);
160 measRecord.
set(_anyKeys.
at(
"EDGE"),
true);
165 footprint.
getSpans()->clippedTo(mimage.getBBox())->applyFunctor(func, *(mimage.getMask()));
169 if (func.getBits() & MaskedImageF::Mask::getPlaneBitMask(
"NO_DATA")) {
170 measRecord.
set(_anyKeys.
at(
"EDGE"),
true);
177 updateFlags(_anyKeys, func, measRecord);
186 middle.
getSpans()->clippedTo(mimage.getBBox())->applyFunctor(func, *(mimage.getMask()));
189 updateFlags(_centerKeys, func, measRecord);
193 measRecord.
set(_generalFailureKey,
true);
#define LSST_EXCEPT(type,...)
This is the algorithm for PixelFlags.
MaskedImageT getMaskedImage()
void set(Key< T > const &key, U const &value)
std::shared_ptr< SourceTable const > getTable() const
CentroidSlotDefinition::MeasValue getCentroid() const
std::shared_ptr< Footprint > getFootprint() const
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...
virtual char const * what(void) const noexcept
int positionToIndex(double pos)