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
NaiveCentroid.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 #include "ndarray/eigen.h"
24 #include "lsst/afw/table/Source.h"
26 
27 
28 namespace lsst { namespace meas { namespace base {
29 
31  Control const & ctrl,
32  std::string const & name,
34 ) : _ctrl(ctrl),
36  CentroidResultKey::addFields(schema, name, "centroid from Naive Centroid algorithm", SIGMA_ONLY)
37  ),
38  _centroidExtractor(schema, name, true)
39 {
40  static boost::array<FlagDefinition,N_FLAGS> const flagDefs = {{
41  {"flag", "general failure flag, set if anything went wrong"},
42  {"flag_noCounts", "Object to be centroided has no counts"},
43  {"flag_edge", "Object too close to edge"}
44  }};
45  _flagHandler = FlagHandler::addFields(schema, name, flagDefs.begin(), flagDefs.end());
46 }
47 
49  afw::table::SourceRecord & measRecord,
50  afw::image::Exposure<float> const & exposure
51 ) const {
52 
54  CentroidResult result;
55  result.x = center.getX();
56  result.y = center.getY();
57  measRecord.set(_centroidKey, result); // better than NaN
58 
59  typedef afw::image::Image<float> ImageT;
60  ImageT const& image = *exposure.getMaskedImage().getImage();
61 
62  int x = center.getX(); // FIXME: this is different from GaussianCentroid and SdssCentroid here,
63  int y = center.getY(); // and probably shouldn't be.
64 
65  x -= image.getX0(); // work in image Pixel coordinates
66  y -= image.getY0();
67 
68  if (x < 1 || x >= image.getWidth() - 1 || y < 1 || y >= image.getHeight() - 1) {
69 
70  throw LSST_EXCEPT(
73  EDGE
74  );
75  }
76 
77  ImageT::xy_locator im = image.xy_at(x, y);
78 
79  double const sum =
80  (im(-1, 1) + im( 0, 1) + im( 1, 1) +
81  im(-1, 0) + im( 0, 0) + im( 1, 0) +
82  im(-1, -1) + im( 0, -1) + im( 1, -1))
83  - 9 * _ctrl.background;
84 
85  if (sum == 0.0) {
86  throw LSST_EXCEPT(
89  NO_COUNTS
90  );
91  }
92 
93  double const sum_x =
94  -im(-1, 1) + im( 1, 1) +
95  -im(-1, 0) + im( 1, 0) +
96  -im(-1, -1) + im( 1, -1);
97  double const sum_y =
98  (im(-1, 1) + im( 0, 1) + im( 1, 1)) -
99  (im(-1, -1) + im( 0, -1) + im( 1, -1));
100 
101  result.x = lsst::afw::image::indexToPosition(x + image.getX0()) + sum_x / sum;
102  result.y = lsst::afw::image::indexToPosition(y + image.getY0()) + sum_y / sum;
103  measRecord.set(_centroidKey, result);
104  _flagHandler.setValue(measRecord, FAILURE, false); // if we had a suspect flag, we'd set that instead
105 }
106 
107 
109  _flagHandler.handleFailure(measRecord, error);
110 }
111 
112 }}} // namespace lsst::meas::base
113 
114 
Defines the fields and offsets for a table.
Definition: Schema.h:46
virtual void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
NaiveCentroidAlgorithm(Control const &ctrl, std::string const &name, afw::table::Schema &schema)
virtual void fail(afw::table::SourceRecord &measRecord, MeasurementError *error=NULL) const
double indexToPosition(double ind)
Convert image index to image position.
Definition: ImageUtils.h:54
Eigen matrix objects that present a view into an ndarray::Array.
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
A reusable struct for centroid measurements.
CentroidElement x
x (column) coordinate of the measured position
Exception to be thrown when a measurement algorithm experiences a known failure mode.
Definition: exceptions.h:48
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
FlagDefinition getDefinition(int i) const
Definition: FlagHandler.h:66
MaskedImageT getMaskedImage()
Return the MaskedImage.
Definition: Exposure.h:150
tbl::Schema schema
Definition: CoaddPsf.cc:324
int x
void setValue(afw::table::BaseRecord &record, int i, bool value) const
Definition: FlagHandler.h:72
double sum
Definition: NaiveFlux.cc:137
afw::table::Centroid::MeasKey _centroidKey
Definition: GaussianFlux.cc:75
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
double background
&quot;Value to subtract from the image pixel values&quot; ;
Definition: NaiveCentroid.h:44
A FunctorKey for CentroidResult.
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Definition: BaseRecord.h:136
CentroidElement y
y (row) coordinate of the measured position
void handleFailure(afw::table::BaseRecord &record, MeasurementError const *error=NULL) const
Definition: FlagHandler.cc:59
A C++ control class to handle NaiveCentroidAlgorithm&#39;s configuration.
Definition: NaiveCentroid.h:42
Record class that contains measurements made on a single exposure.
Definition: Source.h:81
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:415
static FlagHandler addFields(afw::table::Schema &schema, std::string const &prefix, FlagDefinition const *begin, FlagDefinition const *end)
Definition: FlagHandler.cc:28