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"
40 #include "boost/shared_ptr.hpp"
45 #include "lsst/afw/detection/FootprintArray.cc"
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,
129 _centroidExtractor(schema, name)
142 naiveCentroid(source, exposure, peaks[0].getI(), (peaks[0].getPeakValue() >= 0 ?
145 if (peaks.
size() > 1) {
146 naiveCentroid(source, exposure, peaks[1].getI(), (peaks[1].getPeakValue() >= 0 ?
163 ) : afw::detection::FootprintFunctor< afw::image::MaskedImage<float> >(mimage),
174 void operator()( afw::image::MaskedImage<float>::xy_locator loc,
259 virtual double operator()(std::vector<double>
const & params)
const {
268 if ((negFlux > 0.0) || (posFlux < 0.0)) {
273 posCenterX, posCenterY, posFlux);
274 double chi2 = fit.first;
275 int nPix = fit.second;
298 double negCenterX,
double negCenterY,
double negFlux,
299 double posCenterX,
double posCenterY,
double posFlux
318 footprint->getBBox());
326 int negXmin = std::max(negPsfBBox.getMinX(), negModelBBox.
getMinX());
327 int negYmin = std::max(negPsfBBox.getMinY(), negModelBBox.
getMinY());
328 int negXmax = std::min(negPsfBBox.getMaxX(), negModelBBox.
getMaxX());
329 int negYmax = std::min(negPsfBBox.getMaxY(), negModelBBox.
getMaxY());
334 negModelSubim += negSubim;
337 int posXmin = std::max(posPsfBBox.
getMinX(), posModelBBox.
getMinX());
338 int posYmin = std::max(posPsfBBox.
getMinY(), posModelBBox.
getMinY());
339 int posXmax = std::min(posPsfBBox.
getMaxX(), posModelBBox.
getMaxX());
340 int posYmax = std::min(posPsfBBox.
getMaxY(), posModelBBox.
getMaxY());
345 posModelSubim += posSubim;
350 residuals += posModel;
352 residuals *= residuals;
357 return std::pair<double,int>(
chi2, nPix);
382 if (peakCatalog.
size() == 0) {
386 else if (peakCatalog.
size() == 1) {
398 ROOT::Minuit2::MnUserParameters fitPar;
415 ROOT::Minuit2::MnMigrad migrad(minimizerFunc, fitPar);
422 float minChi2 = min.Fval();
423 bool const isValid = min.IsValid() &&
std::isfinite(minChi2);
425 if (
true || isValid) {
432 std::pair<double,int> fit =
chi2(source, exposure,
439 double evalChi2 = fit.first;
440 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" ;
double getValue(Property const prop=NOTHING) const
Return the value of the desired property (if specified in the constructor)
MaskedImageT getMaskedImage()
Return the MaskedImage.
ImagePtr getImage(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage's image.
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
Eigen matrix objects that present a view into an ndarray::Array.
float getFx() const
Convenience accessors for the keys in the minimal schema.
afw::table::Key< int > _numNegativeKey
afw::table::Key< CentroidElement > getY() const
Return a Key for the y coordinate.
definition of the Trace messaging facilities
MinimizeDipoleChi2(PsfDipoleFlux const &psfDipoleFlux, afw::table::SourceRecord &source, afw::image::Exposure< float > const &exposure)
void fail(afw::table::SourceRecord &measRecord, meas::base::MeasurementError *error=NULL) const
afw::table::CatalogT< PeakRecord > PeakCatalog
RecordId getId() const
Convenience accessors for the keys in the minimal reference schema.
meas::base::CentroidResultKey _negCentroid
find sum of pixels in the image
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.
boost::enable_if< typename ExpressionTraits< Scalar >::IsScalar, Scalar >::type sum(Scalar const &scalar)
ResultKey const & getNegativeKeys() const
PixelT Pixel
A pixel in this ImageBase.
An integer coordinate rectangle.
void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
table::Key< table::Array< Kernel::Pixel > > image
afw::image::Exposure< float > const & _exposure
int maxPixels
"Maximum number of pixels to apply the measurement to" ;
meas::base::CentroidResultKey _posCentroid
void setErrorDef(double def)
VariancePtr getVariance(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage's variance.
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
An include file to include the header files for lsst::afw::detection.
afw::table::Key< CentroidElement > getX() const
Return a Key for the x coordinate.
meas::base::FlagHandler _flagHandler
ResultKey const & getNegativeKeys() const
float getPeakValue() const
Convenience accessors for the keys in the minimal schema.
A class to manipulate images, masks, and variance as a single object.
virtual double operator()(std::vector< double > const ¶ms) const
reference back() const
Return the last record.
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" ;
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" ;
boost::shared_ptr< lsst::afw::detection::Psf > getPsf()
Return the Exposure's Psf object.
void fail(afw::table::SourceRecord &measRecord, meas::base::MeasurementError *error=NULL) const
#define LSST_EXCEPT(type,...)
meas::base::FlagHandler _flagHandler
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
boost::shared_ptr< Footprint > getFootprint() const
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
ResultKey const & getPositiveKeys() const
Return the standard centroid keys registered by this algorithm.
float getFy() const
Convenience accessors for the keys in the minimal schema.
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
void handleFailure(afw::table::BaseRecord &record, MeasurementError const *error=NULL) const
Record class that contains measurements made on a single exposure.
afw::table::SourceRecord & _source
afw::table::Key< int > _numPositiveKey
A polymorphic base class for representing an image's Point Spread Function.
Record class that represents a peak in a Footprint.
afw::table::Key< afw::table::Flag > _flagMaxPixelsKey
A class to represent a 2-dimensional array of pixels.
reference front() const
Return the first record.
Include files required for standard LSST Exception handling.
void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
size_type size() const
Return the number of elements in the catalog.