33 # include "Minuit2/FCNBase.h"
34 # include "Minuit2/FunctionMinimum.h"
35 # include "Minuit2/MnMigrad.h"
36 # include "Minuit2/MnMinos.h"
37 # include "Minuit2/MnPrint.h"
45 #include "lsst/afw/detection/FootprintArray.cc"
50 #include "ndarray/eigen.h"
52 namespace pexExceptions = lsst::pex::exceptions;
53 namespace afwDet = lsst::afw::detection;
55 namespace afwMath = lsst::afw::math;
56 namespace afwGeom = lsst::afw::geom;
58 namespace lsst {
namespace ip {
namespace diffim {
71 afw::table::SourceRecord & source,
72 afw::image::Exposure<float>
const& exposure,
74 meas::base::CentroidResultKey
const & keys
77 typedef afw::image::Image<float> ImageT;
78 ImageT
const&
image = *exposure.getMaskedImage().getImage();
80 source.set(keys.getX(), center.getX());
81 source.set(keys.getY(), center.getY());
83 int x = center.getX() - image.getX0();
84 int y = center.getY() - image.getY0();
86 if (x < 1 || x >= image.getWidth() - 1 || y < 1 || y >= image.getHeight() - 1) {
92 ImageT::xy_locator im = image.xy_at(x, y);
95 (im(-1, 1) + im( 0, 1) + im( 1, 1) +
96 im(-1, 0) + im( 0, 0) + im( 1, 0) +
97 im(-1, -1) + im( 0, -1) + im( 1, -1));
107 -im(-1, 1) + im( 1, 1) +
108 -im(-1, 0) + im( 1, 0) +
109 -im(-1, -1) + im( 1, -1);
111 (im(-1, 1) + im( 0, 1) + im( 1, 1)) -
112 (im(-1, -1) + im( 0, -1) + im( 1, -1));
116 source.set(keys.getX(), xx);
117 source.set(keys.getY(), yy);
124 Control
const & ctrl,
125 std::string
const &
name,
141 double posValue = peaks[posInd].getPeakValue(), negValue = 0;
143 posInd = peaks.
size() - 1;
144 posValue = peaks[posInd].getPeakValue();
146 naiveCentroid(source, exposure, peaks[posInd].getI(),
149 if (posValue > 0. && posInd == 0 && peaks.
size() > 1) {
150 int negInd = peaks.
size() - 1;
151 negValue = peaks[negInd].getPeakValue();
152 if (posValue > 0. && negValue < 0.) {
153 naiveCentroid(source, exposure, peaks[negInd].getI(),
163 double posValue,
double negValue)
const {
165 double pos_x, pos_y, pos_f;
166 double neg_x, neg_y, neg_f;
176 if(std::isfinite(pos_x) && std::isfinite(pos_y) &&
177 std::isfinite(neg_x) && std::isfinite(neg_y)) {
178 source.
set(
getCenterKeys().getX(), (pos_x * pos_f + neg_x * neg_f) / (pos_f + neg_f));
179 source.
set(
getCenterKeys().getY(), (pos_y * pos_f + neg_y * neg_f) / (pos_f + neg_f));
180 }
else if (std::isfinite(pos_x) && std::isfinite(pos_y)) {
200 ) : afw::detection::FootprintFunctor< afw::image::MaskedImage<float> >(mimage),
211 void operator()( afw::image::MaskedImage<float>::xy_locator loc,
296 virtual double operator()(std::vector<double>
const & params)
const {
305 if ((negFlux > 0.0) || (posFlux < 0.0)) {
310 posCenterX, posCenterY, posFlux);
311 double chi2 = fit.first;
312 int nPix = fit.second;
335 double negCenterX,
double negCenterY,
double negFlux,
336 double posCenterX,
double posCenterY,
double posFlux
355 footprint->getBBox());
363 int negXmin = std::max(negPsfBBox.getMinX(), negModelBBox.
getMinX());
364 int negYmin = std::max(negPsfBBox.getMinY(), negModelBBox.
getMinY());
365 int negXmax = std::min(negPsfBBox.getMaxX(), negModelBBox.
getMaxX());
366 int negYmax = std::min(negPsfBBox.getMaxY(), negModelBBox.
getMaxY());
371 negModelSubim += negSubim;
374 int posXmin = std::max(posPsfBBox.
getMinX(), posModelBBox.
getMinX());
375 int posYmin = std::max(posPsfBBox.
getMinY(), posModelBBox.
getMinY());
376 int posXmax = std::min(posPsfBBox.
getMaxX(), posModelBBox.
getMaxX());
377 int posYmax = std::min(posPsfBBox.
getMaxY(), posModelBBox.
getMaxY());
382 posModelSubim += posSubim;
387 residuals += posModel;
389 residuals *= residuals;
394 return std::pair<double,int>(
chi2, nPix);
412 if (peakCatalog.
size() == 0) {
416 else if (peakCatalog.
size() == 1) {
428 ROOT::Minuit2::MnUserParameters fitPar;
445 ROOT::Minuit2::MnMigrad migrad(minimizerFunc, fitPar);
452 float minChi2 = min.Fval();
453 bool const isValid = min.IsValid() && std::isfinite(minChi2);
455 if (
true || isValid) {
462 std::pair<double,int> fit =
chi2(source, exposure,
469 double evalChi2 = fit.first;
470 int nPix = fit.second;
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.
meas::base::CentroidResultKey _avgCentroid
double indexToPosition(double ind)
Convert image index to image position.
table::Key< std::string > name
void mergeCentroids(afw::table::SourceRecord &source, double posValue, double negValue) const
afw::table::Key< int > _numNegativeKey
ResultKey const & getCenterKeys() const
Return the standard centroid keys registered by this algorithm.
afw::table::Schema schema
definition of the Trace messaging facilities
PixelT Pixel
A pixel in this ImageBase.
MinimizeDipoleChi2(PsfDipoleFlux const &psfDipoleFlux, afw::table::SourceRecord &source, afw::image::Exposure< float > const &exposure)
boost::shared_ptr< Footprint > getFootprint() const
ImagePtr getImage(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage's image.
void fail(afw::table::SourceRecord &measRecord, meas::base::MeasurementError *error=NULL) const
meas::base::CentroidResultKey _negCentroid
PsfDipoleFlux const & _psfDipoleFlux
Exception to be thrown when a measurement algorithm experiences a known failure mode.
ResultKey const & getPositiveKeys() const
Return the standard flux keys registered by this algorithm.
size_type size() const
Return the number of elements in the catalog.
ResultKey const & getNegativeKeys() const
void handleFailure(afw::table::BaseRecord &record, MeasurementError const *error=NULL) const
An integer coordinate rectangle.
void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
VariancePtr getVariance(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage's variance.
table::Key< table::Array< Kernel::Pixel > > image
afw::image::Exposure< float > const & _exposure
meas::base::CentroidResultKey _posCentroid
void setErrorDef(double def)
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.
void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
afw::table::CatalogT< PeakRecord > PeakCatalog
MaskedImageT getMaskedImage()
Return the MaskedImage.
An include file to include the header files for lsst::afw::detection.
meas::base::FlagHandler _flagHandler
ResultKey const & getNegativeKeys() const
A class to manipulate images, masks, and variance as a single object.
virtual double operator()(std::vector< double > const ¶ms) const
afw::table::Key< CentroidElement > getX() const
Return a Key for the x coordinate.
RecordId getId() const
Convenience accessors for the keys in the minimal reference schema.
NaiveDipoleCentroid(Control const &ctrl, std::string const &name, afw::table::Schema &schema)
double errorDef
"How many sigma the error bars of the non-linear fitter represent" ;
afw::table::Key< CentroidElement > getY() const
Return a Key for the y coordinate.
void setMaxPix(int maxPix)
void fail(afw::table::SourceRecord &measRecord, meas::base::MeasurementError *error=NULL) const
Intermediate base class for algorithms that compute a centroid.
int maxFnCalls
"Maximum function calls for non-linear fitter; 0 = unlimited" ;
void fail(afw::table::SourceRecord &measRecord, meas::base::MeasurementError *error=NULL) const
boost::shared_ptr< lsst::afw::detection::Psf > getPsf()
Return the Exposure's Psf object.
#define LSST_EXCEPT(type,...)
meas::base::FlagHandler _flagHandler
float getFy() const
Convenience accessors for the keys in the minimal schema.
float stepSizeCoord
"Default initial step size for coordinates in non-linear fitter" ;
std::pair< double, int > chi2(afw::table::SourceRecord &source, afw::image::Exposure< float > const &exposure, double negCenterX, double negCenterY, double negFlux, double posCenterX, double poCenterY, double posFlux) const
reference back() const
Return the last record.
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
ResultKey const & getPositiveKeys() const
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
reference front() const
Return the first record.
float getPeakValue() const
Convenience accessors for the keys in the minimal schema.
Record class that contains measurements made on a single exposure.
float getFx() const
Convenience accessors for the keys in the minimal schema.
afw::table::SourceRecord & _source
afw::table::Key< int > _numPositiveKey
find sum of pixels in the image
Include files required for standard LSST Exception handling.
A polymorphic base class for representing an image's Point Spread Function.
Record class that represents a peak in a Footprint.
A class to represent a 2-dimensional array of pixels.
void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const