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 | Static Public Member Functions | Private Attributes | List of all members
lsst::meas::base::SdssShapeAlgorithm Class Reference

Measure the image moments of source using adaptive Gaussian weights. More...

#include <SdssShape.h>

Inheritance diagram for lsst::meas::base::SdssShapeAlgorithm:
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, UNWEIGHTED_BAD, UNWEIGHTED, SHIFT,
  MAXITER, N_FLAGS
}
 
typedef SdssShapeControl Control
 
typedef SdssShapeResult Result
 
typedef SdssShapeResultKey ResultKey
 

Public Member Functions

 SdssShapeAlgorithm (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
 
template<typename ImageT >
SdssShapeResult computeAdaptiveMoments (ImageT const &image, afw::geom::Point2D const &center, Control const &control)
 
- 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 ()
 

Static Public Member Functions

template<typename ImageT >
static Result computeAdaptiveMoments (ImageT const &image, afw::geom::Point2D const &position, Control const &ctrl=Control())
 
template<typename ImageT >
static FluxResult computeFixedMomentsFlux (ImageT const &image, afw::geom::ellipses::Quadrupole const &shape, afw::geom::Point2D const &position)
 

Private Attributes

Control _ctrl
 
ResultKey _resultKey
 
SafeCentroidExtractor _centroidExtractor
 

Detailed Description

Measure the image moments of source using adaptive Gaussian weights.

This algorithm measures the weighted second moments of an image using a Gaussian weight function, which is iteratively updated to match the current weights. If this iteration does not converge, it can fall back to using unweighted moments, which can be significantly noisier.

See Bernstein & Jarvis, 2002, for more information on this type of algorithm. Note that the code here makes no attempt to correct for the PSF; for PSF corrected ellipticities using weighted moments please use the shapeHSM package.

Definition at line 133 of file SdssShape.h.

Member Typedef Documentation

Definition at line 136 of file SdssShape.h.

Definition at line 137 of file SdssShape.h.

Definition at line 138 of file SdssShape.h.

Member Enumeration Documentation

anonymous enum

Constructor & Destructor Documentation

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

Definition at line 742 of file SdssShape.cc.

747  : _ctrl(ctrl),
750 {}
static SdssShapeResultKey addFields(afw::table::Schema &schema, std::string const &name)
Add the appropriate fields to a Schema, and return a SdssShapeResultKey that manages them...
Definition: SdssShape.cc:654
SafeCentroidExtractor _centroidExtractor
Definition: SdssShape.h:196
table::Key< std::string > name
Definition: ApCorrMap.cc:71
afw::table::Schema schema
Definition: GaussianPsf.cc:41

Member Function Documentation

template<typename ImageT >
static Result lsst::meas::base::SdssShapeAlgorithm::computeAdaptiveMoments ( ImageT const &  image,
afw::geom::Point2D const &  position,
Control const &  ctrl = Control() 
)
static

Compute the adaptive Gaussian-weighted moments of an image.

Parameters
[in]imageAn Image or MaskedImage instance with int, float, or double pixels. This need not be a small postage stamp (the pixel region actually used in the fit will be a subset of this image determined automatically).
[in]positionCenter position of the object to be measured, in the image's PARENT coordinates.
[in]ctrlControl object specifying the details of how the object is to be measured.
template<typename ImageT >
SdssShapeResult lsst::meas::base::SdssShapeAlgorithm::computeAdaptiveMoments ( ImageT const &  image,
afw::geom::Point2D const &  center,
Control const &  control 
)

Definition at line 753 of file SdssShape.cc.

757  {
758  double xcen = center.getX(); // object's column position
759  double ycen = center.getY(); // object's row position
760 
761  xcen -= image.getX0(); // work in image Pixel coordinates
762  ycen -= image.getY0();
763 
764  float shiftmax = control.maxShift; // Max allowed centroid shift
765  if (shiftmax < 2) {
766  shiftmax = 2;
767  } else if (shiftmax > 10) {
768  shiftmax = 10;
769  }
770 
771  SdssShapeResult result;
772  try {
773  result.flags[FAILURE] = !getAdaptiveMoments(
774  image, control.background, xcen, ycen, shiftmax, &result,
775  control.maxIter, control.tol1, control.tol2
776  );
777  } catch (pex::exceptions::Exception & err) {
778  result.flags[FAILURE] = true;
779  }
780  if (result.flags[UNWEIGHTED] || result.flags[SHIFT]) {
781  // These are also considered fatal errors in terms of the quality of the results,
782  // even though they do produce some results.
783  result.flags[FAILURE] = true;
784  }
785  if (result.getQuadrupole().getDeterminant() < 0) {
786  if (!result.flags[FAILURE]) {
787  throw LSST_EXCEPT(
788  pex::exceptions::LogicError,
789  "Should not get singular moments unless a flag is set");
790  }
791  }
792 
793  // getAdaptiveMoments() just computes the zeroth moment in result.flux (and its error in
794  // result.fluxSigma, result.flux_xx_Cov, etc.) That's related to the flux by some geometric
795  // factors, which we apply here.
796  double fluxScale = computeFluxScale(result);
797 
798  result.flux *= fluxScale;
799  result.fluxSigma *= fluxScale;
800  result.x += image.getX0();
801  result.y += image.getY0();
802 
803  if (ImageAdaptor<ImageT>::hasVariance) {
804  result.flux_xx_Cov *= fluxScale;
805  result.flux_yy_Cov *= fluxScale;
806  result.flux_xy_Cov *= fluxScale;
807  }
808 
809  return result;
810 }
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
template<typename ImageT >
template FluxResult lsst::meas::base::SdssShapeAlgorithm::computeFixedMomentsFlux ( ImageT const &  image,
afw::geom::ellipses::Quadrupole const &  shape,
afw::geom::Point2D const &  position 
)
static

Compute the flux within a fixed Gaussian aperture.

Parameters
[in]imageAn Image or MaskedImage instance with int, float, or double pixels. This need not be a small postage stamp (the pixel region actually used in the fit will be a subset of this image determined automatically).
[in]shapeEllipse object specifying the 1-sigma contour of the Gaussian.
[in]positionCenter position of the object to be measured, in the image's PARENT coordinates.

Definition at line 813 of file SdssShape.cc.

817  {
818  // while arguments to computeFixedMomentsFlux are in PARENT coordinates, the implementation is LOCAL.
819  afw::geom::Point2D localCenter = center - afw::geom::Extent2D(image.getXY0());
820 
821  afwGeom::BoxI const bbox = computeAdaptiveMomentsBBox(image.getBBox(afw::image::LOCAL),
822  localCenter,
823  shape.getIxx(), shape.getIxy(), shape.getIyy());
824 
825  boost::tuple<std::pair<bool, double>, double, double, double> weights =
826  getWeights(shape.getIxx(), shape.getIxy(), shape.getIyy());
827 
828  FluxResult result;
829 
830  if (!weights.get<0>().first) {
831  throw pex::exceptions::InvalidParameterError("Input shape is singular");
832  }
833 
834  double const w11 = weights.get<1>();
835  double const w12 = weights.get<2>();
836  double const w22 = weights.get<3>();
837  bool const interp = shouldInterp(shape.getIxx(), shape.getIyy(), weights.get<0>().second);
838 
839  double i0 = 0; // amplitude of Gaussian
840  if (calcmom<true>(ImageAdaptor<ImageT>().getImage(image), localCenter.getX(), localCenter.getY(),
841  bbox, 0.0, interp, w11, w12, w22, &i0, NULL, NULL, NULL, NULL, NULL, NULL, NULL)< 0) {
842  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Error from calcmom");
843  }
844 
845  double const wArea = afw::geom::PI*std::sqrt(shape.getDeterminant());
846 
847  result.flux = i0*2*wArea;
848 
849  if (ImageAdaptor<ImageT>::hasVariance) {
850  int ix = static_cast<int>(center.getX() - image.getX0());
851  int iy = static_cast<int>(center.getY() - image.getY0());
852  if (!image.getBBox(afw::image::LOCAL).contains(afw::geom::Point2I(ix, iy))) {
853  throw LSST_EXCEPT(pex::exceptions::RuntimeError,
854  (boost::format("Center (%d,%d) not in image (%dx%d)") %
855  ix % iy % image.getWidth() % image.getHeight()).str());
856  }
857  double var = ImageAdaptor<ImageT>().getVariance(image, ix, iy);
858  double i0Err = std::sqrt(var/wArea);
859  result.fluxSigma = i0Err*2*wArea;
860  }
861 
862  return result;
863 }
Point< double, 2 > Point2D
Definition: Point.h:286
Point< int, 2 > Point2I
Definition: Point.h:283
An integer coordinate rectangle.
Definition: Box.h:53
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
double const PI
The ratio of a circle&#39;s circumference to diameter.
Definition: Angle.h:18
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
Extent< double, 2 > Extent2D
Definition: Extent.h:358
void lsst::meas::base::SdssShapeAlgorithm::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 877 of file SdssShape.cc.

880  {
882 }
FlagHandler const & getFlagHandler() const
Definition: SdssShape.h:110
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::SdssShapeAlgorithm::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 865 of file SdssShape.cc.

868  {
869  SdssShapeResult result = computeAdaptiveMoments(
870  exposure.getMaskedImage(),
872  _ctrl
873  );
874  measRecord.set(_resultKey, result);
875 }
SafeCentroidExtractor _centroidExtractor
Definition: SdssShape.h:196
FlagHandler const & getFlagHandler() const
Definition: SdssShape.h:110
static Result computeAdaptiveMoments(ImageT const &image, afw::geom::Point2D const &position, Control const &ctrl=Control())

Member Data Documentation

SafeCentroidExtractor lsst::meas::base::SdssShapeAlgorithm::_centroidExtractor
private

Definition at line 196 of file SdssShape.h.

Control lsst::meas::base::SdssShapeAlgorithm::_ctrl
private

Definition at line 194 of file SdssShape.h.

ResultKey lsst::meas::base::SdssShapeAlgorithm::_resultKey
private

Definition at line 195 of file SdssShape.h.


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