LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
lsst::meas::extensions::photometryKron::KronFluxAlgorithm Class Reference

A measurement algorithm that estimates flux using Kron photometry. More...

#include <photometryKron.h>

Inheritance diagram for lsst::meas::extensions::photometryKron::KronFluxAlgorithm:
lsst::meas::base::SimpleAlgorithm lsst::meas::base::SingleFrameAlgorithm lsst::meas::base::ForcedAlgorithm lsst::meas::base::BaseAlgorithm lsst::meas::base::BaseAlgorithm

Public Types

typedef KronFluxControl Control
 A typedef to the Control object for this algorithm, defined above. More...
 

Public Member Functions

 KronFluxAlgorithm (Control const &ctrl, std::string const &name, afw::table::Schema &schema, daf::base::PropertySet &metadata)
 A class that knows how to calculate fluxes using the KRON photometry algorithm. More...
 
virtual void measure (afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
 Called to measure a single child source in an image. More...
 
virtual void measureForced (afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure, afw::table::SourceRecord const &refRecord, afw::geom::SkyWcs const &refWcs) const
 Called to measure a single child source in an image. More...
 
virtual void fail (afw::table::SourceRecord &measRecord, meas::base::MeasurementError *error=NULL) const
 Handle an exception thrown by the current algorithm by setting flags in the given record. More...
 
virtual void measureNForced (afw::table::SourceCatalog const &measCat, afw::image::Exposure< float > const &exposure, afw::table::SourceCatalog const &refRecord, afw::geom::SkyWcs const &refWcs) const
 Called to simultaneously measure all children in a deblend family, in a single image. More...
 
virtual void measureN (afw::table::SourceCatalog const &measCat, afw::image::Exposure< float > const &exposure) const
 Called to simultaneously measure all children in a deblend family, in a single image. More...
 
std::string getLogName () const
 

Static Public Member Functions

static meas::base::FlagDefinitionList const & getFlagDefinitions ()
 

Static Public Attributes

static meas::base::FlagDefinition const FAILURE = flagDefinitions.addFailureFlag( "general failure flag, set if anything went wrong")
 
static meas::base::FlagDefinition const EDGE = flagDefinitions.add("flag_edge", "bad measurement due to image edge")
 
static meas::base::FlagDefinition const BAD_SHAPE_NO_PSF = flagDefinitions.add("flag_bad_shape_no_psf", "bad shape and no PSF")
 
static meas::base::FlagDefinition const NO_MINIMUM_RADIUS = flagDefinitions.add("flag_no_minimum_radius", "minimum radius could not enforced: no minimum value or PSF")
 
static meas::base::FlagDefinition const NO_FALLBACK_RADIUS = flagDefinitions.add("flag_no_fallback_radius", "no minimum radius and no PSF provided")
 
static meas::base::FlagDefinition const BAD_RADIUS = flagDefinitions.add("flag_bad_radius", "bad Kron radius")
 
static meas::base::FlagDefinition const USED_MINIMUM_RADIUS = flagDefinitions.add("flag_used_minimum_radius", "used the minimum radius for the Kron aperture")
 
static meas::base::FlagDefinition const USED_PSF_RADIUS = flagDefinitions.add("flag_used_psf_radius", "used the PSF Kron radius for the Kron aperture")
 
static meas::base::FlagDefinition const SMALL_RADIUS = flagDefinitions.add("flag_small_radius", "measured Kron radius was smaller than that of the PSF")
 
static meas::base::FlagDefinition const BAD_SHAPE = flagDefinitions.add("flag_bad_shape", "shape for measuring Kron radius is bad; used PSF shape")
 

Protected Attributes

std::string _logName
 

Detailed Description

A measurement algorithm that estimates flux using Kron photometry.

Definition at line 87 of file photometryKron.h.

Member Typedef Documentation

◆ Control

A typedef to the Control object for this algorithm, defined above.

The control object contains the configuration parameters for this algorithm.

Definition at line 105 of file photometryKron.h.

Constructor & Destructor Documentation

◆ KronFluxAlgorithm()

lsst::meas::extensions::photometryKron::KronFluxAlgorithm::KronFluxAlgorithm ( Control const &  ctrl,
std::string const &  name,
afw::table::Schema schema,
daf::base::PropertySet metadata 
)

A class that knows how to calculate fluxes using the KRON photometry algorithm.

/

Definition at line 366 of file KronPhotometry.cc.

371  : _name(name),
372  _ctrl(ctrl),
373  _fluxResultKey(
374  meas::base::FluxResultKey::addFields(schema, name, "flux from Kron Flux algorithm")
375  ),
376  _radiusKey(schema.addField<float>(name + "_radius", "Kron radius (sqrt(a*b))")),
377  _radiusForRadiusKey(schema.addField<float>(name + "_radius_for_radius",
378  "radius used to estimate <radius> (sqrt(a*b))")),
379  _psfRadiusKey(schema.addField<float>(name + "_psf_radius", "Radius of PSF")),
380  _centroidExtractor(schema, name, true)
381 {
383  auto metadataName = name + "_nRadiusForflux";
384  boost::to_upper(metadataName);
385  metadata.add(metadataName, ctrl.nRadiusForFlux);
386 }
table::Schema schema
Definition: python.h:134
static FlagHandler addFields(afw::table::Schema &schema, std::string const &prefix, FlagDefinitionList const &flagDefs, FlagDefinitionList const &exclDefs=FlagDefinitionList::getEmptyList())
Add Flag fields to a schema, creating a FlagHandler object to manage them.
Definition: FlagHandler.cc:37
static FluxResultKey addFields(afw::table::Schema &schema, std::string const &name, std::string const &doc)
Add a pair of _instFlux, _instFluxErr fields to a Schema, and return a FluxResultKey that points to t...
static meas::base::FlagDefinitionList const & getFlagDefinitions()

Member Function Documentation

◆ fail()

void lsst::meas::extensions::photometryKron::KronFluxAlgorithm::fail ( afw::table::SourceRecord measRecord,
meas::base::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 388 of file KronPhotometry.cc.

391  {
392  _flagHandler.handleFailure(measRecord, error);
393 }
void handleFailure(afw::table::BaseRecord &record, MeasurementError const *error=nullptr) const
Handle an expected or unexpected Exception thrown by a measurement algorithm.
Definition: FlagHandler.cc:76

◆ getFlagDefinitions()

base::FlagDefinitionList const & lsst::meas::extensions::photometryKron::KronFluxAlgorithm::getFlagDefinitions ( )
static

Definition at line 66 of file KronPhotometry.cc.

66  {
67  return flagDefinitions;
68 }

◆ getLogName()

std::string lsst::meas::base::BaseAlgorithm::getLogName ( ) const
inlineinherited

Definition at line 66 of file Algorithm.h.

66 { return _logName; }

◆ measure()

void lsst::meas::extensions::photometryKron::KronFluxAlgorithm::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 455 of file KronPhotometry.cc.

458  {
459  geom::Point2D center = _centroidExtractor(source, _flagHandler);
460 
461  // Did we hit a condition that fundamentally prevented measuring the Kron flux?
462  // Such conditions include hitting the edge of the image and bad input shape, but not low signal-to-noise.
463  bool bad = false;
464 
465  afw::image::MaskedImage<float> const& mimage = exposure.getMaskedImage();
466 
467  double R_K_psf = -1;
468  if (exposure.getPsf()) {
469  R_K_psf = calculatePsfKronRadius(exposure.getPsf(), center, _ctrl.smoothingSigma);
470  }
471 
472  //
473  // Get the shape of the desired aperture
474  //
475  afw::geom::ellipses::Axes axes;
476  if (!source.getShapeFlag()) {
477  axes = source.getShape();
478  } else {
479  bad = true;
480  if (!exposure.getPsf()) {
481  throw LSST_EXCEPT(
482  meas::base::MeasurementError,
485  );
486  }
487  axes = exposure.getPsf()->computeShape();
488  _flagHandler.setValue(source, BAD_SHAPE.number, true);
489  }
490  if (_ctrl.useFootprintRadius) {
491  afw::geom::ellipses::Axes footprintAxes(source.getFootprint()->getShape());
492  // if the Footprint's a disk of radius R we want footRadius == R.
493  // As <r^2> = R^2/2 for a disk, we need to scale up by sqrt(2)
494  footprintAxes.scale(::sqrt(2));
495 
496  double radius0 = axes.getDeterminantRadius();
497  double const footRadius = footprintAxes.getDeterminantRadius();
498 
499  if (footRadius > radius0*_ctrl.nSigmaForRadius) {
500  radius0 = footRadius/_ctrl.nSigmaForRadius; // we'll scale it up by nSigmaForRadius
501  axes.scale(radius0/axes.getDeterminantRadius());
502  }
503  }
504 
506  if (_ctrl.fixed) {
507  aperture.reset(new KronAperture(source));
508  } else {
509  try {
510  aperture = KronAperture::determineRadius(mimage, axes, center, _ctrl);
511  } catch (pex::exceptions::OutOfRangeError& e) {
512  // We hit the edge of the image: no reasonable fallback or recovery possible
513  throw LSST_EXCEPT(
514  meas::base::MeasurementError,
515  EDGE.doc,
516  EDGE.number
517  );
518  } catch (BadKronException& e) {
519  // Not setting bad=true because we only failed due to low S/N
520  aperture = _fallbackRadius(source, R_K_psf, e);
521  } catch(pex::exceptions::Exception& e) {
522  bad = true; // There's something fundamental keeping us from measuring the Kron aperture
523  aperture = _fallbackRadius(source, R_K_psf, e);
524  }
525  }
526 
527  /*
528  * Estimate the minimum acceptable Kron radius as the Kron radius of the PSF or the
529  * provided minimum radius
530  */
531 
532  // Enforce constraints on minimum radius
533  double rad = aperture->getAxes().getDeterminantRadius();
534  if (_ctrl.enforceMinimumRadius) {
535  double newRadius = rad;
536  if (_ctrl.minimumRadius > 0.0) {
537  if (rad < _ctrl.minimumRadius) {
538  newRadius = _ctrl.minimumRadius;
539  _flagHandler.setValue(source, USED_MINIMUM_RADIUS.number, true);
540  }
541  } else if (!exposure.getPsf()) {
542  throw LSST_EXCEPT(
543  meas::base::MeasurementError,
546  );
547  } else if (rad < R_K_psf) {
548  newRadius = R_K_psf;
549  _flagHandler.setValue(source, USED_PSF_RADIUS.number, true);
550  }
551  if (newRadius != rad) {
552  aperture->getAxes().scale(newRadius/rad);
553  _flagHandler.setValue(source, SMALL_RADIUS.number, true); // guilty after all
554  }
555  }
556 
557  _applyAperture(source, exposure, *aperture);
558  source.set(_radiusForRadiusKey, aperture->getRadiusForRadius());
559  source.set(_psfRadiusKey, R_K_psf);
560  if (bad) _flagHandler.setValue(source, FAILURE.number, true);
561 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
void setValue(afw::table::BaseRecord &record, std::size_t i, bool value) const
Set the flag field corresponding to the given flag index.
Definition: FlagHandler.h:262
static std::shared_ptr< KronAperture > determineRadius(ImageT const &image, afw::geom::ellipses::Axes axes, geom::Point2D const &center, KronFluxControl const &ctrl)
Determine the Kron Aperture from an image.
static meas::base::FlagDefinition const USED_MINIMUM_RADIUS
static meas::base::FlagDefinition const FAILURE
static meas::base::FlagDefinition const SMALL_RADIUS
static meas::base::FlagDefinition const BAD_SHAPE
static meas::base::FlagDefinition const EDGE
static meas::base::FlagDefinition const NO_MINIMUM_RADIUS
static meas::base::FlagDefinition const BAD_SHAPE_NO_PSF
static meas::base::FlagDefinition const USED_PSF_RADIUS
double smoothingSigma
"Smooth image with N(0, smoothingSigma^2) Gaussian while estimating R_K" ;
bool fixed
"if true, use existing shape and centroid measurements instead of fitting" ;
bool useFootprintRadius
"Use the Footprint size as part of initial estimate of Kron radius" ;
double minimumRadius
"Minimum Kron radius (if == 0.0 use PSF's Kron radius) if enforceMinimumRadius. " "Also functions as ...
bool enforceMinimumRadius
"If true check that the Kron radius exceeds some minimum" ;
double nSigmaForRadius
"Multiplier of rms size for aperture used to initially estimate the Kron radius" ;
const char * source()
Source function that allows astChannel to source from a Stream.
Definition: Stream.h:224
double calculatePsfKronRadius(std::shared_ptr< afw::detection::Psf const > const &psf, geom::Point2D const &center, double smoothingSigma=0.0)
T reset(T... args)
T sqrt(T... args)

◆ measureForced()

void lsst::meas::extensions::photometryKron::KronFluxAlgorithm::measureForced ( afw::table::SourceRecord measRecord,
afw::image::Exposure< float > const &  exposure,
afw::table::SourceRecord const &  refRecord,
afw::geom::SkyWcs const &  refWcs 
) 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.

Reimplemented from lsst::meas::base::SimpleAlgorithm.

Definition at line 563 of file KronPhotometry.cc.

568  {
569  geom::Point2D center = _centroidExtractor(measRecord, _flagHandler);
570  auto xytransform = afw::geom::makeWcsPairTransform(refWcs, *exposure.getWcs());
571  _applyForced(measRecord, exposure, center, refRecord,
572  linearizeTransform(*xytransform, refRecord.getCentroid())
573  );
574 
575 }
std::shared_ptr< TransformPoint2ToPoint2 > makeWcsPairTransform(SkyWcs const &src, SkyWcs const &dst)
A Transform obtained by putting two SkyWcs objects "back to back".
Definition: SkyWcs.cc:146
lsst::geom::AffineTransform linearizeTransform(TransformPoint2ToPoint2 const &original, lsst::geom::Point2D const &inPoint)
Approximate a Transform by its local linearization.

◆ measureN()

void lsst::meas::base::SingleFrameAlgorithm::measureN ( afw::table::SourceCatalog const &  measCat,
afw::image::Exposure< float > const &  exposure 
) const
virtualinherited

Called to simultaneously measure all children in a deblend family, in a single image.

Outputs should be saved in the given SourceCatalog, which can also be used to obtain centroid (see SafeCentroidExtractor) and shape (see SafeShapeExtractor) information.

The default implementation simply throws an exception, indicating that simultaneous measurement is not supported.

Definition at line 31 of file Algorithm.cc.

32  {
33  throw LSST_EXCEPT(pex::exceptions::LogicError, "measureN not implemented for this algorithm");
34 }

◆ measureNForced()

virtual void lsst::meas::base::SimpleAlgorithm::measureNForced ( afw::table::SourceCatalog const &  measCat,
afw::image::Exposure< float > const &  exposure,
afw::table::SourceCatalog const &  refRecord,
afw::geom::SkyWcs const &  refWcs 
) const
inlinevirtualinherited

Called to simultaneously measure all children in a deblend family, in a single image.

Outputs should be saved in the given SourceCatalog, which can also be used to obtain centroid (see SafeCentroidExtractor) and shape (see SafeShapeExtractor) information.

The default implementation simply throws an exception, indicating that simultaneous measurement is not supported.

Reimplemented from lsst::meas::base::ForcedAlgorithm.

Definition at line 179 of file Algorithm.h.

182  {
183  measureN(measCat, exposure);
184  }
virtual void measureN(afw::table::SourceCatalog const &measCat, afw::image::Exposure< float > const &exposure) const
Called to simultaneously measure all children in a deblend family, in a single image.
Definition: Algorithm.cc:31

Member Data Documentation

◆ _logName

std::string lsst::meas::base::BaseAlgorithm::_logName
protectedinherited

Definition at line 69 of file Algorithm.h.

◆ BAD_RADIUS

base::FlagDefinition const lsst::meas::extensions::photometryKron::KronFluxAlgorithm::BAD_RADIUS = flagDefinitions.add("flag_bad_radius", "bad Kron radius")
static

Definition at line 97 of file photometryKron.h.

◆ BAD_SHAPE

base::FlagDefinition const lsst::meas::extensions::photometryKron::KronFluxAlgorithm::BAD_SHAPE = flagDefinitions.add("flag_bad_shape", "shape for measuring Kron radius is bad; used PSF shape")
static

Definition at line 101 of file photometryKron.h.

◆ BAD_SHAPE_NO_PSF

base::FlagDefinition const lsst::meas::extensions::photometryKron::KronFluxAlgorithm::BAD_SHAPE_NO_PSF = flagDefinitions.add("flag_bad_shape_no_psf", "bad shape and no PSF")
static

Definition at line 94 of file photometryKron.h.

◆ EDGE

base::FlagDefinition const lsst::meas::extensions::photometryKron::KronFluxAlgorithm::EDGE = flagDefinitions.add("flag_edge", "bad measurement due to image edge")
static

Definition at line 93 of file photometryKron.h.

◆ FAILURE

base::FlagDefinition const lsst::meas::extensions::photometryKron::KronFluxAlgorithm::FAILURE = flagDefinitions.addFailureFlag( "general failure flag, set if anything went wrong")
static

Definition at line 92 of file photometryKron.h.

◆ NO_FALLBACK_RADIUS

base::FlagDefinition const lsst::meas::extensions::photometryKron::KronFluxAlgorithm::NO_FALLBACK_RADIUS = flagDefinitions.add("flag_no_fallback_radius", "no minimum radius and no PSF provided")
static

Definition at line 96 of file photometryKron.h.

◆ NO_MINIMUM_RADIUS

base::FlagDefinition const lsst::meas::extensions::photometryKron::KronFluxAlgorithm::NO_MINIMUM_RADIUS = flagDefinitions.add("flag_no_minimum_radius", "minimum radius could not enforced: no minimum value or PSF")
static

Definition at line 95 of file photometryKron.h.

◆ SMALL_RADIUS

base::FlagDefinition const lsst::meas::extensions::photometryKron::KronFluxAlgorithm::SMALL_RADIUS = flagDefinitions.add("flag_small_radius", "measured Kron radius was smaller than that of the PSF")
static

Definition at line 100 of file photometryKron.h.

◆ USED_MINIMUM_RADIUS

base::FlagDefinition const lsst::meas::extensions::photometryKron::KronFluxAlgorithm::USED_MINIMUM_RADIUS = flagDefinitions.add("flag_used_minimum_radius", "used the minimum radius for the Kron aperture")
static

Definition at line 98 of file photometryKron.h.

◆ USED_PSF_RADIUS

base::FlagDefinition const lsst::meas::extensions::photometryKron::KronFluxAlgorithm::USED_PSF_RADIUS = flagDefinitions.add("flag_used_psf_radius", "used the PSF Kron radius for the Kron aperture")
static

Definition at line 99 of file photometryKron.h.


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