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
Public Member Functions | Private Member Functions | Private Attributes | List of all members
lsst::ip::diffim::PsfDipoleFlux Class Reference
Inheritance diagram for lsst::ip::diffim::PsfDipoleFlux:
lsst::ip::diffim::DipoleFluxAlgorithm lsst::meas::algorithms::Algorithm

Public Member Functions

 PsfDipoleFlux (PsfDipoleFluxControl const &ctrl, afw::table::Schema &schema)
 
template<typename PixelT >
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
 
- Public Member Functions inherited from lsst::ip::diffim::DipoleFluxAlgorithm
DipoleFluxControl const & getControl () const
 Return a clone of the control object used to construct the algorithm. More...
 
KeyTuple const & getPositiveKeys () const
 Return the standard flux keys registered by this algorithm. More...
 
KeyTuple const & getNegativeKeys () const
 
- Public Member Functions inherited from lsst::meas::algorithms::Algorithm
 Algorithm (AlgorithmControl const &ctrl)
 
virtual ~Algorithm ()
 
AlgorithmControl const & getControl () const
 Return a clone of the control object used to construct the algorithm. More...
 
template<typename PixelT >
void apply (afw::table::SourceRecord &source, afw::image::Exposure< PixelT > const &exposure, afw::geom::Point2D const &center) const
 Run the algorithm, filling appropriate fields in the given source. More...
 

Private Member Functions

template<typename PixelT >
void _apply (afw::table::SourceRecord &source, afw::image::Exposure< PixelT > const &exposure, afw::geom::Point2D const &center) const
 
 LSST_MEAS_ALGORITHM_PRIVATE_INTERFACE (PsfDipoleFlux)
 

Private Attributes

afw::table::Key< float > _chi2dofKey
 
afw::table::KeyTuple
< afw::table::Centroid
_avgCentroid
 
afw::table::KeyTuple
< afw::table::Centroid
_negCentroid
 
afw::table::KeyTuple
< afw::table::Centroid
_posCentroid
 
afw::table::Key< afw::table::Flag > _flagMaxPixelsKey
 

Additional Inherited Members

- Public Types inherited from lsst::ip::diffim::DipoleFluxAlgorithm
typedef afw::table::KeyTuple
< afw::table::Flux
KeyTuple
 Tuple type that holds the keys that define a standard flux algorithm. More...
 
- Protected Member Functions inherited from lsst::ip::diffim::DipoleFluxAlgorithm
 DipoleFluxAlgorithm (DipoleFluxControl const &ctrl, KeyTuple const &positiveKeys, KeyTuple const &negativeKeys)
 Initialize with a manually-constructed key tuple. More...
 
 DipoleFluxAlgorithm (DipoleFluxControl const &ctrl, afw::table::Schema &schema, char const *doc)
 Initialize using afw::table::addFlux field to fill out repetitive descriptions. More...
 
- Protected Member Functions inherited from lsst::meas::algorithms::Algorithm
template<typename PixelT >
void _apply (afw::table::SourceRecord &source, afw::image::Exposure< PixelT > const &exposure, afw::geom::Point2D const &center) const
 Simulated virtual function that all algorithms must implement. More...
 

Detailed Description

Implementation of Psf dipole flux

Definition at line 324 of file dipoleAlgorithm.cc.

Constructor & Destructor Documentation

lsst::ip::diffim::PsfDipoleFlux::PsfDipoleFlux ( PsfDipoleFluxControl const &  ctrl,
afw::table::Schema schema 
)
inline

Definition at line 327 of file dipoleAlgorithm.cc.

327  :
328  DipoleFluxAlgorithm(ctrl, schema, "jointly fitted psf flux counts"),
329  _chi2dofKey(schema.addField<float>(ctrl.name+".chi2dof",
330  "chi2 per degree of freedom of fit")),
331  _avgCentroid(
332  addCentroidFields(schema, ctrl.name+".centroid",
333  "average of the postive and negative lobe positions")),
334  _negCentroid(
335  addCentroidFields(schema, ctrl.name+".neg.centroid",
336  "psf fitted center of negative lobe")),
337  _posCentroid(
338  addCentroidFields(schema, ctrl.name+".pos.centroid",
339  "psf fitted center of positive lobe")),
340  _flagMaxPixelsKey(schema.addField<afw::table::Flag>(ctrl.name+".flags.maxpix",
341  "set if too large a footprint was sent to the algorithm"))
342  {}
afw::table::Key< float > _chi2dofKey
afw::table::KeyTuple< afw::table::Centroid > _posCentroid
DipoleFluxAlgorithm(DipoleFluxControl const &ctrl, KeyTuple const &positiveKeys, KeyTuple const &negativeKeys)
Initialize with a manually-constructed key tuple.
tbl::Schema schema
Definition: CoaddPsf.cc:324
afw::table::KeyTuple< afw::table::Centroid > _avgCentroid
KeyTuple< Centroid > addCentroidFields(Schema &schema, std::string const &name, std::string const &doc)
Convenience function to setup fields for centroid measurement algorithms.
afw::table::KeyTuple< afw::table::Centroid > _negCentroid
afw::table::Key< afw::table::Flag > _flagMaxPixelsKey

Member Function Documentation

template<typename PixelT >
void lsst::ip::diffim::PsfDipoleFlux::_apply ( afw::table::SourceRecord source,
afw::image::Exposure< PixelT > const &  exposure,
afw::geom::Point2D const &  center 
) const
private

Definition at line 495 of file dipoleAlgorithm.cc.

499  {
500 
501  source.set(getPositiveKeys().flag, true); // say we've failed so that's the result if we throw
502  source.set(getNegativeKeys().flag, true); // say we've failed so that's the result if we throw
503  source.set(_flagMaxPixelsKey, true);
504 
505  typedef typename afw::image::Exposure<PixelT>::MaskedImageT MaskedImageT;
506 
507  CONST_PTR(afw::detection::Footprint) footprint = source.getFootprint();
508  if (!footprint) {
509  throw LSST_EXCEPT(pex::exceptions::RuntimeError,
510  (boost::format("No footprint for source %d") % source.getId()).str());
511  }
512 
513  PsfDipoleFluxControl const & ctrl = static_cast<PsfDipoleFluxControl const &>(getControl());
514  if (footprint->getArea() > ctrl.maxPixels) {
515  // Too big
516  return;
517  }
518  source.set(_flagMaxPixelsKey, false);
519 
521  afw::detection::Footprint::PeakList(footprint->getPeaks());
522 
523  if (peakList.size() == 0) {
524  throw LSST_EXCEPT(pex::exceptions::RuntimeError,
525  (boost::format("No peak for source %d") % source.getId()).str());
526  }
527  else if (peakList.size() == 1) {
528  // No deblending to do
529  return;
530  }
531 
532  // For N>=2, just measure the brightest-positive and brightest-negative
533  // peaks. peakList is automatically ordered by peak flux, with the most
534  // positive one (brightest) being first
535  PTR(afw::detection::Peak) positivePeak = peakList.front();
536  PTR(afw::detection::Peak) negativePeak = peakList.back();
537 
538  // Set up fit parameters and param names
539  ROOT::Minuit2::MnUserParameters fitPar;
540 
541  fitPar.Add((boost::format("P%d")%NEGCENTXPAR).str(), negativePeak->getFx(), ctrl.stepSizeCoord);
542  fitPar.Add((boost::format("P%d")%NEGCENTYPAR).str(), negativePeak->getFy(), ctrl.stepSizeCoord);
543  fitPar.Add((boost::format("P%d")%NEGFLUXPAR).str(), negativePeak->getPeakValue(), ctrl.stepSizeFlux);
544  fitPar.Add((boost::format("P%d")%POSCENTXPAR).str(), positivePeak->getFx(), ctrl.stepSizeCoord);
545  fitPar.Add((boost::format("P%d")%POSCENTYPAR).str(), positivePeak->getFy(), ctrl.stepSizeCoord);
546  fitPar.Add((boost::format("P%d")%POSFLUXPAR).str(), positivePeak->getPeakValue(), ctrl.stepSizeFlux);
547 
548  // Create the minuit object that knows how to minimise our functor
549  //
550  MinimizeDipoleChi2<PixelT> minimizerFunc(*this, source, exposure);
551  minimizerFunc.setErrorDef(ctrl.errorDef);
552 
553  //
554  // tell minuit about it
555  //
556  ROOT::Minuit2::MnMigrad migrad(minimizerFunc, fitPar);
557 
558  //
559  // And let it loose
560  //
561  ROOT::Minuit2::FunctionMinimum min = migrad(ctrl.maxFnCalls);
562 
563  float minChi2 = min.Fval();
564  bool const isValid = min.IsValid() && std::isfinite(minChi2);
565 
566  if (true || isValid) { // calculate coeffs even in minuit is unhappy
567 
568  /* I need to call chi2 one more time to grab nPix to calculate chi2/dof.
569  Turns out that the Minuit operator method has to be const, and the
570  measurement _apply method has to be const, so I can't store nPix as a
571  private member variable anywhere. Consted into a corner.
572  */
573  std::pair<double,int> fit = chi2(source, exposure,
574  min.UserState().Value(NEGCENTXPAR), min.UserState().Value(NEGCENTYPAR),
575  min.UserState().Value(NEGFLUXPAR), min.UserState().Value(POSCENTXPAR),
576  min.UserState().Value(POSCENTYPAR), min.UserState().Value(POSFLUXPAR));
577  double evalChi2 = fit.first;
578  int nPix = fit.second;
579 
580  PTR(afw::geom::Point2D) minNegCentroid(new afw::geom::Point2D(min.UserState().Value(NEGCENTXPAR),
581  min.UserState().Value(NEGCENTYPAR)));
582  source.set(getNegativeKeys().meas, min.UserState().Value(NEGFLUXPAR));
583  source.set(getNegativeKeys().err, min.UserState().Error(NEGFLUXPAR));
584  source.set(getNegativeKeys().flag, false);
585 
586  PTR(afw::geom::Point2D) minPosCentroid(new afw::geom::Point2D(min.UserState().Value(POSCENTXPAR),
587  min.UserState().Value(POSCENTYPAR)));
588  source.set(getPositiveKeys().meas, min.UserState().Value(POSFLUXPAR));
589  source.set(getPositiveKeys().err, min.UserState().Error(POSFLUXPAR));
590  source.set(getPositiveKeys().flag, false);
591 
592  source.set(_chi2dofKey, evalChi2 / (nPix - minimizerFunc.getNpar()));
593  source.set(_negCentroid.meas, *minNegCentroid);
594  source.set(_posCentroid.meas, *minPosCentroid);
595  source.set(_avgCentroid.meas,
596  afw::geom::Point2D(0.5*(minNegCentroid->getX() + minPosCentroid->getX()),
597  0.5*(minNegCentroid->getY() + minPosCentroid->getY())));
598 
599  }
600 
601 }
afw::table::Key< float > _chi2dofKey
int const NEGFLUXPAR(2)
#define PTR(...)
Definition: base.h:41
KeyTuple const & getNegativeKeys() const
int const NEGCENTXPAR(0)
Point< double, 2 > Point2D
Definition: Point.h:277
std::vector< Peak::Ptr > PeakList
Definition: Footprint.h:83
MaskedImage< PixelT, lsst::afw::image::MaskPixel, lsst::afw::image::VariancePixel > MaskedImageT
Definition: Exposure.h:51
double min
Definition: attributes.cc:216
int const POSCENTXPAR(3)
int d
Definition: KDTree.cc:89
afw::table::KeyTuple< afw::table::Centroid > _posCentroid
DipoleFluxControl const & getControl() const
Return a clone of the control object used to construct the algorithm.
int const POSCENTYPAR(4)
#define CONST_PTR(...)
Definition: base.h:47
int isfinite(T t)
Definition: ieee.h:100
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
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
int const POSFLUXPAR(5)
afw::table::KeyTuple< afw::table::Centroid > _avgCentroid
int const NEGCENTYPAR(1)
lsst::afw::detection::Footprint Footprint
Definition: Source.h:61
KeyTuple const & getPositiveKeys() const
Return the standard flux keys registered by this algorithm.
afw::table::KeyTuple< afw::table::Centroid > _negCentroid
afw::table::Key< afw::table::Flag > _flagMaxPixelsKey
template<typename PixelT >
std::pair< double, int > lsst::ip::diffim::PsfDipoleFlux::chi2 ( afw::table::SourceRecord source,
afw::image::Exposure< PixelT > const &  exposure,
double  negCenterX,
double  negCenterY,
double  negFlux,
double  posCenterX,
double  poCenterY,
double  posFlux 
) const

Definition at line 428 of file dipoleAlgorithm.cc.

433  {
434 
435  afw::geom::Point2D negCenter(negCenterX, negCenterY);
436  afw::geom::Point2D posCenter(posCenterX, posCenterY);
437 
438  CONST_PTR(afw::detection::Footprint) footprint = source.getFootprint();
439 
440  /* Fit for the superposition of Psfs at the two centroids.
441  *
442  */
443  CONST_PTR(afwDet::Psf) psf = exposure.getPsf();
444  PTR(afwImage::Image<afwMath::Kernel::Pixel>) negPsf = psf->computeImage(negCenter);
445  PTR(afwImage::Image<afwMath::Kernel::Pixel>) posPsf = psf->computeImage(posCenter);
446 
447  afwImage::Image<double> negModel(footprint->getBBox());
448  afwImage::Image<double> posModel(footprint->getBBox());
449  afwImage::Image<PixelT> data(*(exposure.getMaskedImage().getImage()),
450  footprint->getBBox());
451  afwImage::Image<afwImage::VariancePixel> var(*(exposure.getMaskedImage().getVariance()),
452  footprint->getBBox());
453 
454  afwGeom::Box2I negPsfBBox = negPsf->getBBox();
455  afwGeom::Box2I posPsfBBox = posPsf->getBBox();
456  afwGeom::Box2I negModelBBox = negModel.getBBox();
457  afwGeom::Box2I posModelBBox = posModel.getBBox();
458 
459  // Portion of the negative Psf that overlaps the model
460  int negXmin = std::max(negPsfBBox.getMinX(), negModelBBox.getMinX());
461  int negYmin = std::max(negPsfBBox.getMinY(), negModelBBox.getMinY());
462  int negXmax = std::min(negPsfBBox.getMaxX(), negModelBBox.getMaxX());
463  int negYmax = std::min(negPsfBBox.getMaxY(), negModelBBox.getMaxY());
464  afwGeom::Box2I negBBox = afwGeom::Box2I(afwGeom::Point2I(negXmin, negYmin),
465  afwGeom::Point2I(negXmax, negYmax));
466  afwImage::Image<afwMath::Kernel::Pixel> negSubim(*negPsf, negBBox);
467  afwImage::Image<double> negModelSubim(negModel, negBBox);
468  negModelSubim += negSubim;
469 
470  // Portion of the positive Psf that overlaps the model
471  int posXmin = std::max(posPsfBBox.getMinX(), posModelBBox.getMinX());
472  int posYmin = std::max(posPsfBBox.getMinY(), posModelBBox.getMinY());
473  int posXmax = std::min(posPsfBBox.getMaxX(), posModelBBox.getMaxX());
474  int posYmax = std::min(posPsfBBox.getMaxY(), posModelBBox.getMaxY());
475  afwGeom::Box2I posBBox = afwGeom::Box2I(afwGeom::Point2I(posXmin, posYmin),
476  afwGeom::Point2I(posXmax, posYmax));
477  afwImage::Image<afwMath::Kernel::Pixel> posSubim(*posPsf, posBBox);
478  afwImage::Image<double> posModelSubim(posModel, posBBox);
479  posModelSubim += posSubim;
480 
481  negModel *= negFlux; // scale negative model to image
482  posModel *= posFlux; // scale positive model to image
483  afwImage::Image<double> residuals(negModel, true); // full model contains negative lobe...
484  residuals += posModel; // plus positive lobe...
485  residuals -= data; // minus the data...
486  residuals *= residuals;// squared...
487  residuals /= var; // divided by the variance : [(model-data)/sigma]**2
488  afwMath::Statistics stats = afwMath::makeStatistics(residuals, afwMath::SUM | afwMath::NPOINT);
489  double chi2 = stats.getValue(afwMath::SUM);
490  int nPix = stats.getValue(afwMath::NPOINT);
491  return std::pair<double,int>(chi2, nPix);
492 }
#define PTR(...)
Definition: base.h:41
Point< double, 2 > Point2D
Definition: Point.h:277
Point< int, 2 > Point2I
Definition: Point.h:274
double min
Definition: attributes.cc:216
double max
Definition: attributes.cc:218
number of sample points
Definition: Statistics.h:66
#define CONST_PTR(...)
Definition: base.h:47
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
lsst::afw::detection::Footprint Footprint
Definition: Source.h:61
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
Definition: Statistics.cc:1023
find sum of pixels in the image
Definition: Statistics.h:78
float VariancePixel
! default type for Masks and MaskedImage Masks
lsst::ip::diffim::PsfDipoleFlux::LSST_MEAS_ALGORITHM_PRIVATE_INTERFACE ( PsfDipoleFlux  )
private

Member Data Documentation

afw::table::KeyTuple<afw::table::Centroid> lsst::ip::diffim::PsfDipoleFlux::_avgCentroid
private

Definition at line 362 of file dipoleAlgorithm.cc.

afw::table::Key<float> lsst::ip::diffim::PsfDipoleFlux::_chi2dofKey
private

Definition at line 361 of file dipoleAlgorithm.cc.

afw::table::Key< afw::table::Flag > lsst::ip::diffim::PsfDipoleFlux::_flagMaxPixelsKey
private

Definition at line 366 of file dipoleAlgorithm.cc.

afw::table::KeyTuple<afw::table::Centroid> lsst::ip::diffim::PsfDipoleFlux::_negCentroid
private

Definition at line 363 of file dipoleAlgorithm.cc.

afw::table::KeyTuple<afw::table::Centroid> lsst::ip::diffim::PsfDipoleFlux::_posCentroid
private

Definition at line 364 of file dipoleAlgorithm.cc.


The documentation for this class was generated from the following file: