LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Private Attributes | List of all members
lsst::meas::base::SdssCentroidAlgorithm Class Reference

The Sdss Centroid Algorithm. More...

#include <SdssCentroid.h>

Inheritance diagram for lsst::meas::base::SdssCentroidAlgorithm:
lsst::meas::base::SimpleAlgorithm lsst::meas::base::SingleFrameAlgorithm lsst::meas::base::ForcedAlgorithm lsst::meas::base::BaseAlgorithm lsst::meas::base::BaseAlgorithm

Public Types

enum  {
  FAILURE =FlagHandler::FAILURE, EDGE, NO_SECOND_DERIVATIVE, ALMOST_NO_SECOND_DERIVATIVE,
  NOT_AT_MAXIMUM, N_FLAGS
}
 
typedef SdssCentroidControl Control
 

Public Member Functions

 SdssCentroidAlgorithm (Control const &ctrl, std::string const &name, afw::table::Schema &schema)
 
virtual void measure (afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
 
virtual void fail (afw::table::SourceRecord &measRecord, MeasurementError *error=NULL) const
 
- Public Member Functions inherited from lsst::meas::base::SimpleAlgorithm
virtual void measureForced (afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure, afw::table::SourceRecord const &refRecord, afw::image::Wcs const &refWcs) const
 
virtual void measureNForced (afw::table::SourceCatalog const &measCat, afw::image::Exposure< float > const &exposure, afw::table::SourceCatalog const &refRecord, afw::image::Wcs const &refWcs) const
 
- Public Member Functions inherited from lsst::meas::base::SingleFrameAlgorithm
virtual void measureN (afw::table::SourceCatalog const &measCat, afw::image::Exposure< float > const &exposure) const
 
- Public Member Functions inherited from lsst::meas::base::BaseAlgorithm
virtual ~BaseAlgorithm ()
 

Private Attributes

Control _ctrl
 
CentroidResultKey _centroidKey
 
FlagHandler _flagHandler
 
SafeCentroidExtractor _centroidExtractor
 

Detailed Description

The Sdss Centroid Algorithm.

Definition at line 65 of file SdssCentroid.h.

Member Typedef Documentation

A typedef to the Control object for this algorithm, defined above. The control object contains the configuration parameters for this algorithm.

Definition at line 79 of file SdssCentroid.h.

Member Enumeration Documentation

anonymous enum

Constructor & Destructor Documentation

lsst::meas::base::SdssCentroidAlgorithm::SdssCentroidAlgorithm ( Control const &  ctrl,
std::string const &  name,
afw::table::Schema schema 
)

Definition at line 423 of file SdssCentroid.cc.

427  : _ctrl(ctrl),
428  _centroidKey(
429  CentroidResultKey::addFields(schema, name, "centroid from Sdss Centroid algorithm", SIGMA_ONLY)
430  ),
432 {
434  getFlagDefinitions().begin(), getFlagDefinitions().end());
435 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
afw::table::Schema schema
Definition: GaussianPsf.cc:41
Only the diagonal elements of the covariance matrix are provided.
Definition: constants.h:43
SafeCentroidExtractor _centroidExtractor
Definition: SdssCentroid.h:98
static CentroidResultKey addFields(afw::table::Schema &schema, std::string const &name, std::string const &doc, UncertaintyEnum uncertainty)
Add the appropriate fields to a Schema, and return a CentroidResultKey that manages them...
static FlagHandler addFields(afw::table::Schema &schema, std::string const &prefix, FlagDefinition const *begin, FlagDefinition const *end)
Definition: FlagHandler.cc:28

Member Function Documentation

void lsst::meas::base::SdssCentroidAlgorithm::fail ( afw::table::SourceRecord measRecord,
MeasurementError error = NULL 
) const
virtual

Handle an exception thrown by the current algorithm by setting flags in the given record.

fail() is called by the measurement framework when an exception is allowed to propagate out of one the algorithm's measure() methods. It should generally set both a general failure flag for the algorithm as well as a specific flag indicating the error condition, if possible. To aid in this, if the exception was an instance of MeasurementError, it will be passed in, carrying information about what flag to set.

An algorithm can also to chose to set flags within its own measure() methods, and then just return, rather than throw an exception. However, fail() should be implemented even when all known failure modes do not throw exceptions, to ensure that unexpected exceptions thrown in lower-level code are properly handled.

Implements lsst::meas::base::BaseAlgorithm.

Definition at line 536 of file SdssCentroid.cc.

536  {
537  _flagHandler.handleFailure(measRecord, error);
538 }
def error
Definition: log.py:108
void handleFailure(afw::table::BaseRecord &record, MeasurementError const *error=NULL) const
Definition: FlagHandler.cc:59
void lsst::meas::base::SdssCentroidAlgorithm::measure ( afw::table::SourceRecord measRecord,
afw::image::Exposure< float > const &  exposure 
) const
virtual

Called to measure a single child source in an image.

Before this method is called, all neighbors will be replaced with noise, using the outputs of the deblender. Outputs should be saved in the given SourceRecord, which can also be used to obtain centroid (see SafeCentroidExtractor) and shape (see SafeShapeExtractor) information.

Implements lsst::meas::base::SingleFrameAlgorithm.

Definition at line 436 of file SdssCentroid.cc.

439  {
440 
441  // get our current best guess about the centroid: either a centroider measurement or peak.
442  afw::geom::Point2D center = _centroidExtractor(measRecord, _flagHandler);
443  CentroidResult result;
444  result.x = center.getX();
445  result.y = center.getY();
446  measRecord.set(_centroidKey, result); // better than NaN
447 
448  typedef afw::image::Exposure<float>::MaskedImageT MaskedImageT;
449  typedef MaskedImageT::Image ImageT;
450  typedef MaskedImageT::Variance VarianceT;
451 
452  MaskedImageT const& mimage = exposure.getMaskedImage();
453  ImageT const& image = *mimage.getImage();
454  CONST_PTR(lsst::afw::detection::Psf) psf = exposure.getPsf();
455 
456  int const x = image.positionToIndex(center.getX(), lsst::afw::image::X).first;
457  int const y = image.positionToIndex(center.getY(), lsst::afw::image::Y).first;
458 
459  if (!image.getBBox().contains(lsst::afw::geom::Extent2I(x,y) + image.getXY0())) {
460  throw LSST_EXCEPT(
463  EDGE
464  );
465  }
466 
467  // Algorithm uses a least-squares fit (implemented via a convolution) to a symmetrized PSF model.
468  // If you don't have a Psf, you need to use another centroider, such as GaussianCentroider.
469  if (!psf) {
470  throw LSST_EXCEPT(
471  FatalAlgorithmError,
472  "SdssCentroid algorithm requires a Psf with every exposure"
473  );
474  }
475 
476  int binX = 1;
477  int binY = 1;
478  double xc=0., yc=0., dxc=0., dyc=0.; // estimated centre and error therein
479  for(int binsize = 1; binsize <= _ctrl.binmax; binsize *= 2) {
480  std::pair<MaskedImageT, double> result = smoothAndBinImage(psf, x, y, mimage, binX, binY, _flagHandler);
481  MaskedImageT const smoothedImage = result.first;
482  double const smoothingSigma = result.second;
483 
484  MaskedImageT::xy_locator mim = smoothedImage.xy_at(smoothedImage.getWidth()/2,
485  smoothedImage.getHeight()/2);
486 
487  double sizeX2, sizeY2; // object widths^2 in x and y directions
488  double peakVal; // peak intensity in image
489 
490  doMeasureCentroidImpl(&xc, &dxc, &yc, &dyc, &sizeX2, &sizeY2, &peakVal, mim,
491  smoothingSigma, _flagHandler);
492 
493  if(binsize > 1) {
494  // dilate from the lower left corner of central pixel
495  xc = (xc + 0.5)*binX - 0.5;
496  dxc *= binX;
497  sizeX2 *= binX*binX;
498 
499  yc = (yc + 0.5)*binY - 0.5;
500  dyc *= binY;
501  sizeY2 *= binY*binY;
502  }
503 
504  xc += x; // xc, yc are measured relative to pixel (x, y)
505  yc += y;
506 
507  double const fac = _ctrl.wfac*(1 + smoothingSigma*smoothingSigma);
508  double const facX2 = fac*binX*binX;
509  double const facY2 = fac*binY*binY;
510 
511  if (sizeX2 < facX2 && ::pow(xc - x, 2) < facX2 &&
512  sizeY2 < facY2 && ::pow(yc - y, 2) < facY2) {
513  if (binsize > 1 || _ctrl.peakMin < 0.0 || peakVal > _ctrl.peakMin) {
514  break;
515  }
516  }
517 
518  if (sizeX2 >= facX2 || ::pow(xc - x, 2) >= facX2) {
519  binX *= 2;
520  }
521  if (sizeY2 >= facY2 || ::pow(yc - y, 2) >= facY2) {
522  binY *= 2;
523  }
524  }
525  result.x = lsst::afw::image::indexToPosition(xc + image.getX0());
526  result.y = lsst::afw::image::indexToPosition(yc + image.getY0());
527 
528  result.xSigma = sqrt(dxc*dxc);
529  result.ySigma = sqrt(dyc*dyc);
530  measRecord.set(_centroidKey, result);
531  _flagHandler.setValue(measRecord, FAILURE, false);
532 
533 }
int y
double indexToPosition(double ind)
Convert image index to image position.
Definition: ImageUtils.h:54
int positionToIndex(double pos)
Convert image position to nearest integer index.
Definition: ImageUtils.h:69
Point< double, 2 > Point2D
Definition: Point.h:286
int binmax
&quot;maximum allowed binning&quot; ;
Definition: SdssCentroid.h:49
Exception to be thrown when a measurement algorithm experiences a known failure mode.
Definition: exceptions.h:48
Extent< int, 2 > Extent2I
Definition: Extent.h:355
MaskedImage< float, lsst::afw::image::MaskPixel, lsst::afw::image::VariancePixel > MaskedImageT
Definition: Exposure.h:51
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
FlagDefinition getDefinition(int i) const
Definition: FlagHandler.h:66
SafeCentroidExtractor _centroidExtractor
Definition: SdssCentroid.h:98
if(width!=gim.getWidth()||height!=gim.getHeight()||x0!=gim.getX0()||y0!=gim.getY0())
Definition: saturated.cc:47
void setValue(afw::table::BaseRecord &record, int i, bool value) const
Definition: FlagHandler.h:72
double x
double peakMin
&quot;if the peak&#39;s less than this insist on binning at least once&quot; ;
Definition: SdssCentroid.h:50
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
double wfac
&quot;fiddle factor for adjusting the binning&quot; ;
Definition: SdssCentroid.h:51
#define CONST_PTR(...)
Definition: base.h:47
A polymorphic base class for representing an image&#39;s Point Spread Function.
Definition: Psf.h:68

Member Data Documentation

SafeCentroidExtractor lsst::meas::base::SdssCentroidAlgorithm::_centroidExtractor
private

Definition at line 98 of file SdssCentroid.h.

CentroidResultKey lsst::meas::base::SdssCentroidAlgorithm::_centroidKey
private

Definition at line 96 of file SdssCentroid.h.

Control lsst::meas::base::SdssCentroidAlgorithm::_ctrl
private

Definition at line 95 of file SdssCentroid.h.

FlagHandler lsst::meas::base::SdssCentroidAlgorithm::_flagHandler
private

Definition at line 97 of file SdssCentroid.h.


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