35 # include "Minuit2/FCNBase.h"
36 # include "Minuit2/FunctionMinimum.h"
37 # include "Minuit2/MnMigrad.h"
38 # include "Minuit2/MnMinos.h"
39 # include "Minuit2/MnPrint.h"
42 #include "boost/shared_ptr.hpp"
47 #include "lsst/afw/detection/FootprintArray.cc"
55 namespace pexExceptions = lsst::pex::exceptions;
56 namespace pexLogging = lsst::pex::logging;
57 namespace afwDet = lsst::afw::detection;
59 namespace afwTable = lsst::afw::table;
60 namespace afwMath = lsst::afw::math;
61 namespace afwGeom = lsst::afw::geom;
62 namespace measAlgorithms = lsst::meas::algorithms;
88 template <
typename PixelT>
107 _numPositiveKey(schema.addField<int>(ctrl.name+
".npos",
"number of positive pixels",
"dn")),
108 _numNegativeKey(schema.addField<int>(ctrl.name+
".nneg",
"number of negative pixels",
"dn"))
112 template <
typename PixelT>
129 template<
typename PixelT>
141 int x = center.getX() - image.getX0();
142 int y = center.getY() - image.getY0();
144 if (x < 1 || x >= image.getWidth() - 1 || y < 1 || y >= image.getHeight() - 1) {
145 throw LSST_EXCEPT(lsst::pex::exceptions::LengthError,
146 (
boost::format(
"Object at (%d, %d) is too close to the edge")
150 typename ImageT::xy_locator im = image.xy_at(x, y);
153 (im(-1, 1) + im( 0, 1) + im( 1, 1) +
154 im(-1, 0) + im( 0, 0) + im( 1, 0) +
155 im(-1, -1) + im( 0, -1) + im( 1, -1));
165 -im(-1, 1) + im( 1, 1) +
166 -im(-1, 0) + im( 1, 0) +
167 -im(-1, -1) + im( 1, -1);
169 (im(-1, 1) + im( 0, 1) + im( 1, 1)) -
170 (im(-1, -1) + im( 0, -1) + im( 1, -1));
188 template<
typename PixelT>
199 naiveCentroid(source, exposure, peaks[0]->getI(), (peaks[0]->getPeakValue() >= 0 ?
202 if (peaks.size() > 1) {
203 naiveCentroid(source, exposure, peaks[1]->getI(), (peaks[1]->getPeakValue() >= 0 ?
212 return boost::make_shared<NaiveDipoleCentroidControl>(*this);
216 afw::table::Schema &
schema,
219 return boost::make_shared<NaiveDipoleCentroid>(*
this, boost::ref(schema));
226 template <
typename MaskedImageT>
229 explicit NaiveDipoleFootprinter(MaskedImageT
const& mimage
230 ) : afw::detection::FootprintFunctor<MaskedImageT>(mimage),
241 void operator()(
typename MaskedImageT::xy_locator loc,
245 typename MaskedImageT::Image::Pixel ival = loc.image(0, 0);
246 typename MaskedImageT::Image::Pixel vval = loc.variance(0, 0);
281 template<
typename PixelT>
292 NaiveDipoleFootprinter<MaskedImageT> functor(exposure.
getMaskedImage());
309 return boost::make_shared<NaiveDipoleFluxControl>(*this);
313 afw::table::Schema &
schema,
316 return boost::make_shared<NaiveDipoleFlux>(*
this, boost::ref(schema));
329 _chi2dofKey(schema.addField<float>(ctrl.name+
".chi2dof",
330 "chi2 per degree of freedom of fit")),
333 "average of the postive and negative lobe positions")),
336 "psf fitted center of negative lobe")),
339 "psf fitted center of positive lobe")),
341 "set if too large a footprint was sent to the algorithm"))
343 template <
typename PixelT>
346 double negCenterX,
double negCenterY,
double negFlux,
347 double posCenterX,
double poCenterY,
double posFlux
352 template <
typename PixelT>
372 template<
typename PixelT>
393 virtual double operator()(std::vector<double>
const & params)
const {
402 if ((negFlux > 0.0) || (posFlux < 0.0)) {
407 double chi2 = fit.first;
408 int nPix = fit.second;
427 template<
typename PixelT>
431 double negCenterX,
double negCenterY,
double negFlux,
432 double posCenterX,
double posCenterY,
double posFlux
450 footprint->getBBox());
452 footprint->getBBox());
468 negModelSubim += negSubim;
479 posModelSubim += posSubim;
484 residuals += posModel;
486 residuals *= residuals;
491 return std::pair<double,int>(
chi2, nPix);
494 template<
typename PixelT>
514 if (footprint->getArea() > ctrl.
maxPixels) {
523 if (peakList.size() == 0) {
527 else if (peakList.size() == 1) {
539 ROOT::Minuit2::MnUserParameters fitPar;
556 ROOT::Minuit2::MnMigrad migrad(minimizerFunc, fitPar);
561 ROOT::Minuit2::FunctionMinimum
min = migrad(ctrl.
maxFnCalls);
563 float minChi2 = min.Fval();
564 bool const isValid = min.IsValid() &&
std::isfinite(minChi2);
566 if (
true || isValid) {
573 std::pair<double,int> fit =
chi2(source, exposure,
577 double evalChi2 = fit.first;
578 int nPix = fit.second;
597 0.5*(minNegCentroid->getY() + minPosCentroid->getY())));
606 return boost::make_shared<PsfDipoleFluxControl>(*this);
610 afw::table::Schema &
schema,
613 return boost::make_shared<PsfDipoleFlux>(*
this, boost::ref(schema));
void setErrorDef(double def)
An include file to include the public header files for lsst::afw::math.
Defines the fields and offsets for a table.
afw::table::Key< float > _chi2dofKey
float stepSizeFlux
"Default initial step size for flux in non-linear fitter" ;
An include file to include the header files for lsst::afw::geom.
double indexToPosition(double ind)
Convert image index to image position.
Eigen matrix objects that present a view into an ndarray::Array.
afw::table::Key< int > _numNegativeKey
Class for storing ordered metadata with comments.
KeyTuple const & getNegativeKeys() const
C++ control object for naive dipole centroid.
NaiveDipoleCentroid(NaiveDipoleCentroidControl const &ctrl, afw::table::Schema &schema)
PsfDipoleFlux const & _psfDipoleFlux
definition of the Trace messaging facilities
KeyTuple const & getPositiveKeys() const
Return the standard centroid keys registered by this algorithm.
boost::shared_ptr< Footprint > getFootprint() const
ImagePtr getImage(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage's image.
LSST_MEAS_ALGORITHM_PRIVATE_INTERFACE(NaiveDipoleCentroid)
Key< Flag > flag
Failure bit; set if the measurement did not fully succeed.
void _apply(afw::table::SourceRecord &source, afw::image::Exposure< PixelT > const &exposure, afw::geom::Point2D const ¢er) const
C++ control object for PSF dipole fluxes.
afw::image::Exposure< PixelT > const & _exposure
void _apply(afw::table::SourceRecord &source, afw::image::Exposure< PixelT > const &exposure, afw::geom::Point2D const ¢er) const
LSST_MEAS_ALGORITHM_PRIVATE_IMPLEMENTATION(NaiveDipoleCentroid)
An integer coordinate rectangle.
LSST_MEAS_ALGORITHM_PRIVATE_INTERFACE(NaiveDipoleFlux)
VariancePtr getVariance(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage's variance.
table::Key< table::Array< Kernel::Pixel > > image
MeasurementT::MeasKey meas
Key used for the measured value.
int maxPixels
"Maximum number of pixels to apply the measurement to" ;
double getValue(Property const prop=NOTHING) const
Return the value of the desired property (if specified in the constructor)
An include file to include the header files for lsst::afw::image.
afw::table::KeyTuple< afw::table::Centroid > _posCentroid
Base class for source measurement algorithms.
PsfDipoleFlux(PsfDipoleFluxControl const &ctrl, afw::table::Schema &schema)
Base class for measurement algorithm control objects.
DipoleFluxControl const & getControl() const
Return a clone of the control object used to construct the algorithm.
Include files required for standard LSST Exception handling.
MaskedImageT getMaskedImage()
Return the MaskedImage.
virtual double operator()(std::vector< double > const ¶ms) const
An include file to include the header files for lsst::afw::detection.
void setMaxPix(int maxPix)
KeyTuple const & getNegativeKeys() const
LSST_MEAS_ALGORITHM_PRIVATE_INTERFACE(PsfDipoleFlux)
RecordId getId() const
Convenience accessors for the keys in the minimal reference schema.
double errorDef
"How many sigma the error bars of the non-linear fitter represent" ;
afw::table::SourceRecord & _source
Intermediate base class for algorithms that compute a flux.
Intermediate base class for algorithms that compute a centroid.
int maxFnCalls
"Maximum function calls for non-linear fitter; 0 = unlimited" ;
std::pair< double, int > chi2(afw::table::SourceRecord &source, afw::image::Exposure< PixelT > const &exposure, double negCenterX, double negCenterY, double negFlux, double posCenterX, double poCenterY, double posFlux) const
NaiveDipoleFlux(NaiveDipoleFluxControl const &ctrl, afw::table::Schema &schema)
boost::shared_ptr< lsst::afw::detection::Psf > getPsf()
Return the Exposure's Psf object.
#define LSST_EXCEPT(type,...)
afw::table::KeyTuple< afw::table::Centroid > _avgCentroid
float stepSizeCoord
"Default initial step size for coordinates in non-linear fitter" ;
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
KeyTuple< Centroid > addCentroidFields(Schema &schema, std::string const &name, std::string const &doc)
Convenience function to setup fields for centroid measurement algorithms.
Record class that contains measurements made on a single exposure.
void _apply(afw::table::SourceRecord &source, afw::image::Exposure< PixelT > const &exposure, afw::geom::Point2D const ¢er) const
afw::table::Key< int > _numPositiveKey
find sum of pixels in the image
KeyTuple const & getPositiveKeys() const
Return the standard flux keys registered by this algorithm.
afw::table::KeyTuple< afw::table::Centroid > _negCentroid
C++ control object for naive dipole fluxes.
A polymorphic base class for representing an image's Point Spread Function.
afw::table::Key< afw::table::Flag > _flagMaxPixelsKey
MinimizeDipoleChi2(PsfDipoleFlux const &psfDipoleFlux, afw::table::SourceRecord &source, afw::image::Exposure< PixelT > const &exposure)
A class to represent a 2-dimensional array of pixels.