28#include "ndarray/eigen.h"
41template <
typename MaskedImageT>
44 explicit FootprintBits() : _bits(0) {}
47 void reset() { _bits = 0x0; }
60typedef 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);
168 auto fullSpans = footprint->getSpans();
172 fullSpans->clippedTo(mimage.getBBox())->applyFunctor(func, *(mimage.getMask()));
176 if (func.getBits() & MaskedImageF::Mask::getPlaneBitMask(
"NO_DATA")) {
177 measRecord.
set(_anyKeys.
at(
"EDGE"),
true);
184 updateFlags(_anyKeys, func, measRecord);
193 middle.
getSpans()->clippedTo(mimage.getBBox())->applyFunctor(func, *(mimage.getMask()));
196 updateFlags(_centerKeys, func, measRecord);
200 measRecord.
set(_generalFailureKey,
true);
table::Key< std::string > name
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
This is the algorithm for PixelFlags.
A class to contain the data, WCS, and other information needed to describe an image of the sky.
MaskedImageT getMaskedImage()
Return the MaskedImage.
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Defines the fields and offsets for a table.
Record class that contains measurements made on a single exposure.
CentroidSlotDefinition::MeasValue getCentroid() const
Get the value of the Centroid slot measurement.
std::shared_ptr< SourceTable const > getTable() const
std::shared_ptr< Footprint > getFootprint() const
An integer coordinate rectangle.
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
Return a character string summarizing this exception.
Reports invalid arguments.
Reports errors that are due to events beyond the control of the program.
int positionToIndex(double pos)
Convert image position to nearest integer index.
float Pixel
Typedefs to be used for pixel values.
A base class for image defects.