28 #include "ndarray/eigen.h"
35 namespace lsst {
namespace meas {
namespace base {
37 template <
typename MaskedImageT>
38 class FootprintBits :
public afw::detection::FootprintFunctor<MaskedImageT> {
40 explicit FootprintBits(MaskedImageT
const& mimage) :
41 afw::detection::FootprintFunctor<MaskedImageT>(mimage),
_bits(0)
51 void operator()(
typename MaskedImageT::xy_locator loc,
55 _bits |= loc.mask(0, 0);
59 typename MaskedImageT::Mask::Pixel getBits()
const {
return _bits; }
61 typename MaskedImageT::Mask::Pixel
_bits;
64 typedef afw::image::MaskedImage<float> MaskedImageF;
67 afw::table::SourceRecord & measRecord) {
68 for (
auto const & i: maskFlagToPixelFlag) {
70 if (func.getBits() & MaskedImageF::Mask::getPlaneBitMask(i.first)) {
71 measRecord.set(i.second,
true);
74 catch (pex::exceptions::InvalidParameterError & err) {
83 std::string
const &
name,
88 "general failure flag, set if anything went wring");
90 "Source center is off image");
93 "Source is outside usable exposure region (masked EDGE or NO_DATA)");
94 _anyKeys[
"INTRP"] = schema.
addField<afw::table::Flag>(name +
"_flag_interpolated",
95 "Interpolated pixel in the Source footprint");
96 _anyKeys[
"SAT"] = schema.
addField<afw::table::Flag>(name +
"_flag_saturated",
97 "Saturated pixel in the Source footprint");
98 _anyKeys[
"CR"] = schema.
addField<afw::table::Flag>(name +
"_flag_cr",
99 "Cosmic ray in the Source footprint");
100 _anyKeys[
"BAD"] = schema.
addField<afw::table::Flag>(name +
"_flag_bad",
101 "Bad pixel in the Source footprint");
102 _anyKeys[
"SUSPECT"] = schema.
addField<afw::table::Flag>(name +
"_flag_suspect",
103 "Source's footprint includes suspect pixels");
105 _centerKeys[
"INTRP"] = schema.
addField<afw::table::Flag>(name +
"_flag_interpolatedCenter",
106 "Interpolated pixel in the Source center");
107 _centerKeys[
"SAT"] = schema.
addField<afw::table::Flag>(name +
"_flag_saturatedCenter",
108 "Saturated pixel in the Source center");
109 _centerKeys[
"CR"] = schema.
addField<afw::table::Flag>(name +
"_flag_crCenter",
110 "Cosmic ray in the Source center");
111 _centerKeys[
"SUSPECT"] = schema.
addField<afw::table::Flag>(name +
"_flag_suspectCenter",
112 "Source's center is close to suspect pixels");
116 std::string maskName(i);
117 std::transform(maskName.begin(), maskName.end(), maskName.begin(), ::tolower);
118 _centerKeys[i] = schema.
addField<afw::table::Flag>(name +
"_flag_" + maskName +
"Center",
119 "Source center is close to "+ i +
" pixels");
123 std::string maskName(i);
124 std::transform(maskName.begin(), maskName.end(), maskName.begin(), ::tolower);
125 _anyKeys[i] = schema.
addField<afw::table::Flag>(name +
"_flag_" + maskName,
126 "Source footprint includes " + i +
" pixels");
136 FootprintBits<MaskedImageF> func(mimage);
140 if (measRecord.
getTable()->getCentroidKey().isValid()) {
143 if (std::isnan(center.getX()) || std::isnan(center.getY())) {
145 "Center point passed to PixelFlagsAlgorithm is NaN");
160 if (!footprint || footprint->getPeaks().empty()) {
161 throw LSST_EXCEPT(pex::exceptions::RuntimeError,
"No footprint, or no footprint peaks detected");
164 center.setX(footprint->getPeaks().front().getFx());
165 center.setY(footprint->getPeaks().front().getFy());
177 func.apply(footprint);
181 if (func.getBits() & MaskedImageF::Mask::getPlaneBitMask(
"NO_DATA")) {
184 }
catch (pex::exceptions::InvalidParameterError & err) {
185 throw LSST_EXCEPT(FatalAlgorithmError, err.what());
189 updateFlags(
_anyKeys, func, measRecord);
Defines the fields and offsets for a table.
table::Key< std::string > name
CentroidSlotDefinition::MeasValue getCentroid() const
Get the value of the Centroid slot measurement.
int positionToIndex(double pos)
Convert image position to nearest integer index.
std::map< std::string, afw::table::Key< afw::table::Flag > > KeyMap
MaskedImageT::Mask::Pixel _bits
afw::table::Schema schema
lsst::afw::detection::Footprint Footprint
afw::table::Key< afw::table::Flag > _generalFailureKey
Exception to be thrown when a measurement algorithm experiences a known failure mode.
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
An integer coordinate rectangle.
virtual void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
Called to measure a single child source in an image.
afw::table::Key< afw::table::Flag > _offImageKey
virtual void fail(afw::table::SourceRecord &measRecord, MeasurementError *error=NULL) const
Handle an exception thrown by the current algorithm by setting flags in the given record...
MaskedImageT getMaskedImage()
Return the MaskedImage.
PixelFlagsAlgorithm(Control const &ctrl, std::string const &name, afw::table::Schema &schema)
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
boost::shared_ptr< SourceTable const > getTable() const
A C++ control class to handle PixelFlagsAlgorithm's configuration.
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...
Key< T > addField(Field< T > const &field, bool doReplace=false)
Add a new field to the Schema, and return the associated Key.
Record class that contains measurements made on a single exposure.
This is the algorithm for PixelFlags.
std::vector< std::string > masksFpAnywhere
"List of mask planes to be searched for which occur anywhere within a footprint. " "If any of the pla...
boost::shared_ptr< Footprint > getFootprint() const