LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
LSSTDataManagementBasePackage
PixelFlags.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008-2013 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 
24 #include "ndarray/eigen.h"
25 
26 #include "lsst/afw/detection/Psf.h"
28 #include "lsst/afw/table/Source.h"
30 
31 namespace lsst { namespace meas { namespace base {
32 namespace {
33 
34 template <typename MaskedImageT>
35 class FootprintBits : public afw::detection::FootprintFunctor<MaskedImageT> {
36 public:
37  explicit FootprintBits(MaskedImageT const& mimage) :
38  afw::detection::FootprintFunctor<MaskedImageT>(mimage), _bits(0)
39  {}
40 
42  void reset() {
43  _bits = 0x0;
44  }
45  virtual void reset(afw::detection::Footprint const&) {}
46 
48  void operator()(typename MaskedImageT::xy_locator loc,
49  int x,
50  int y
51  ) {
52  _bits |= loc.mask(0, 0);
53  }
54 
56  typename MaskedImageT::Mask::Pixel getBits() const { return _bits; }
57 private:
58  typename MaskedImageT::Mask::Pixel _bits;
59 };
60 } // end anonymous namespace
62  Control const & ctrl,
63  std::string const & name,
65 ) : _ctrl(ctrl),
67  CentroidResultKey::addFields(schema, name, "centroid from Naive Centroid algorithm", SIGMA_ONLY)
68  ),
69  _centroidExtractor(schema, name)
70 {
71  static boost::array<FlagDefinition,N_FLAGS> const flagDefs = {{
72  {"flag", "general failure flag, set if anything went wrong"},
73  {"flag_edge", "Could not use full PSF model image in fit because of proximity to exposure border"},
74  {"flag_interpolated", "Interpolated pixel in the source footprint"},
75  {"flag_interpolatedCenter", "Interpolated pixel in the source center"},
76  {"flag_saturated", "Saturated pixel in the source footprint"},
77  {"flag_saturatedCenter", "Saturated pixel in the source center"},
78  {"flag_cr", "Cosmic ray in the source footprint"},
79  {"flag_crCenter", "Cosmic ray in the source center"},
80  {"flag_bad", "Bad pixel in the source footprint"}
81  }};
82  _flagHandler = FlagHandler::addFields(schema, name, flagDefs.begin(), flagDefs.end());
83 }
84 
86  afw::table::SourceRecord & measRecord,
87  afw::image::Exposure<float> const & exposure
88 ) const {
89 
91  typedef afw::image::MaskedImage<float> MaskedImageT;
92  MaskedImageT mimage = exposure.getMaskedImage();
93 
94  FootprintBits<MaskedImageT> func(mimage);
95 
96 // Catch NAN in centroid estimate
97  if (lsst::utils::isnan(center.getX()) || lsst::utils::isnan(center.getY())) {
98  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
99  "Center point passed to PixelFlagsALgorithm is NaN");
100  }
101 // Catch centroids off the image
102  if (!mimage.getBBox().contains(afw::geom::Point2I(center))) {
103  _flagHandler.setValue(measRecord, EDGE, true);
104  }
105  // Check for bits set in the source's Footprint
106  afw::detection::Footprint const & footprint(*measRecord.getFootprint());
107  func.apply(footprint);
108  if (func.getBits() & MaskedImageT::Mask::getPlaneBitMask("EDGE")) {
109  _flagHandler.setValue(measRecord, EDGE, true);
110  }
111  if (func.getBits() & MaskedImageT::Mask::getPlaneBitMask("BAD")) {
112  _flagHandler.setValue(measRecord, BAD, true);
113  }
114  if (func.getBits() & MaskedImageT::Mask::getPlaneBitMask("INTRP")) {
115  _flagHandler.setValue(measRecord, INTERPOLATED, true);
116  }
117  if (func.getBits() & MaskedImageT::Mask::getPlaneBitMask("SAT")) {
118  _flagHandler.setValue(measRecord, SATURATED, true);
119  }
120  if (func.getBits() & MaskedImageT::Mask::getPlaneBitMask("CR")) {
121  _flagHandler.setValue(measRecord, CR, true);
122  }
123 
124  // Check for bits set in the 3x3 box around the center
125  afw::geom::Point2I llc(afw::image::positionToIndex(center.getX())-1, afw::image::positionToIndex(center.getY()) - 1);
126 
127  afw::detection::Footprint const middle(afw::geom::BoxI(llc, afw::geom::ExtentI(3))); // central 3x3
128  func.apply(middle);
129  if (func.getBits() & MaskedImageT::Mask::getPlaneBitMask("INTRP")) {
130  _flagHandler.setValue(measRecord, INTERPOLATED_CENTER, true);
131  }
132  if (func.getBits() & MaskedImageT::Mask::getPlaneBitMask("SAT")) {
133  _flagHandler.setValue(measRecord, SATURATED_CENTER, true);
134  }
135  if (func.getBits() & MaskedImageT::Mask::getPlaneBitMask("CR")) {
136  _flagHandler.setValue(measRecord, CR_CENTER, true);
137  }
138  _flagHandler.setValue(measRecord, FAILURE, false);
139 }
140 
142  _flagHandler.handleFailure(measRecord, error);
143 }
144 
145 }}} // namespace lsst::meas::base
146 
Defines the fields and offsets for a table.
Definition: Schema.h:46
Eigen matrix objects that present a view into an ndarray::Array.
int positionToIndex(double pos)
Convert image position to nearest integer index.
Definition: ImageUtils.h:69
int y
A class to contain the data, WCS, and other information needed to describe an image of the sky...
Definition: Exposure.h:48
Only the diagonal elements of the covariance matrix are provided.
Definition: constants.h:43
MaskedImageT::Mask::Pixel _bits
Definition: PixelFlags.cc:58
boost::shared_ptr< Footprint > getFootprint() const
Definition: Source.h:89
Exception to be thrown when a measurement algorithm experiences a known failure mode.
Definition: exceptions.h:48
int isnan(T t)
Definition: ieee.h:110
An integer coordinate rectangle.
Definition: Box.h:53
virtual void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
Definition: PixelFlags.cc:85
virtual void fail(afw::table::SourceRecord &measRecord, MeasurementError *error=NULL) const
Definition: PixelFlags.cc:141
MaskedImageT getMaskedImage()
Return the MaskedImage.
Definition: Exposure.h:150
tbl::Schema schema
Definition: CoaddPsf.cc:324
int x
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:77
PixelFlagsAlgorithm(Control const &ctrl, std::string const &name, afw::table::Schema &schema)
Definition: PixelFlags.cc:61
void setValue(afw::table::BaseRecord &record, int i, bool value) const
Definition: FlagHandler.h:72
A set of pixels in an Image.
Definition: Footprint.h:73
afw::table::Centroid::MeasKey _centroidKey
Definition: GaussianFlux.cc:75
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
A C++ control class to handle PixelFlagsAlgorithm&#39;s configuration.
Definition: PixelFlags.h:45
lsst::afw::detection::Footprint Footprint
Definition: Source.h:61
A FunctorKey for CentroidResult.
void handleFailure(afw::table::BaseRecord &record, MeasurementError const *error=NULL) const
Definition: FlagHandler.cc:59
Record class that contains measurements made on a single exposure.
Definition: Source.h:81
static FlagHandler addFields(afw::table::Schema &schema, std::string const &prefix, FlagDefinition const *begin, FlagDefinition const *end)
Definition: FlagHandler.cc:28
SafeCentroidExtractor _centroidExtractor
Definition: PixelFlags.h:107