LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
Public Types | Public Member Functions | List of all members
lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT > Class Template Reference

Asseses the quality of a candidate given a spatial kernel and background model. More...

#include <AssessSpatialKernelVisitor.h>

Inheritance diagram for lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >:
lsst::afw::math::CandidateVisitor

Public Types

typedef std::shared_ptr< AssessSpatialKernelVisitor< PixelT > > Ptr
 

Public Member Functions

 AssessSpatialKernelVisitor (std::shared_ptr< lsst::afw::math::LinearCombinationKernel > spatialKernel, lsst::afw::math::Kernel::SpatialFunctionPtr spatialBackground, lsst::daf::base::PropertySet const &ps)
 
virtual ~AssessSpatialKernelVisitor ()
 
void reset ()
 
int getNGood ()
 
int getNRejected ()
 
int getNProcessed ()
 
void processCandidate (lsst::afw::math::SpatialCellCandidate *candidate)
 

Detailed Description

template<typename PixelT>
class lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >

Asseses the quality of a candidate given a spatial kernel and background model.

detail::AssessSpatialKernelVisitor<PixelT> spatialKernelAssessor(spatialKernel,
spatialBackground,
ps);
spatialKernelAssessor.reset();
kernelCells.visitCandidates(&spatialKernelAssessor, nStarPerCell);
nRejected = spatialKernelAssessor.getNRejected();
Note
Evaluates the spatial kernel and spatial background at the location of each candidate, and computes the resulting difference image. Sets candidate as afwMath::SpatialCellCandidate::GOOD/BAD if requested by the PropertySet configuration.

Definition at line 26 of file AssessSpatialKernelVisitor.h.

Member Typedef Documentation

◆ Ptr

Definition at line 29 of file AssessSpatialKernelVisitor.h.

Constructor & Destructor Documentation

◆ AssessSpatialKernelVisitor()

Parameters
spatialKernelSpatially varying kernel
spatialBackgroundSpatially varying background
psPropertySet config

Definition at line 54 of file AssessSpatialKernelVisitor.cc.

58  :
60  _spatialKernel(spatialKernel),
61  _spatialBackground(spatialBackground),
62  _ps(ps.deepCopy()),
63  _imstats(ImageStatistics<PixelT>(ps)),
64  _nGood(0),
65  _nRejected(0),
66  _nProcessed(0),
67  _useCoreStats(ps.getAsBool("useCoreStats")),
68  _coreRadius(ps.getAsInt("candidateCoreRadius"))
69  {};

◆ ~AssessSpatialKernelVisitor()

template<typename PixelT >
virtual lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >::~AssessSpatialKernelVisitor ( )
inlinevirtual

Definition at line 36 of file AssessSpatialKernelVisitor.h.

36 {};

Member Function Documentation

◆ getNGood()

template<typename PixelT >
int lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >::getNGood ( )
inline

Definition at line 40 of file AssessSpatialKernelVisitor.h.

40 {return _nGood;}

◆ getNProcessed()

template<typename PixelT >
int lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >::getNProcessed ( )
inline

Definition at line 42 of file AssessSpatialKernelVisitor.h.

42 {return _nProcessed;}

◆ getNRejected()

template<typename PixelT >
int lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >::getNRejected ( )
inline

Definition at line 41 of file AssessSpatialKernelVisitor.h.

41 {return _nRejected;}

◆ processCandidate()

template<typename PixelT >
void lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >::processCandidate ( lsst::afw::math::SpatialCellCandidate candidate)
virtual

Reimplemented from lsst::afw::math::CandidateVisitor.

Definition at line 72 of file AssessSpatialKernelVisitor.cc.

74  {
75 
76  KernelCandidate<PixelT> *kCandidate = dynamic_cast<KernelCandidate<PixelT> *>(candidate);
77  if (kCandidate == NULL) {
79  "Failed to cast SpatialCellCandidate to KernelCandidate");
80  }
81  if (!(kCandidate->isInitialized())) {
82  kCandidate->setStatus(afwMath::SpatialCellCandidate::BAD);
83  LOGL_DEBUG("TRACE2.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
84  "Cannot process candidate %d, continuing", kCandidate->getId());
85  return;
86  }
87 
88  LOGL_DEBUG("TRACE1.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
89  "Processing candidate %d", kCandidate->getId());
90 
91  /*
92  Note - this is a hack until the Kernel API is upgraded by the
93  Davis crew. I need a "local" version of the spatially varying
94  Kernel
95  */
96  afwImage::Image<double> kImage(_spatialKernel->getDimensions());
97  double kSum = _spatialKernel->computeImage(kImage, false,
98  kCandidate->getXCenter(), kCandidate->getYCenter());
100  kernelPtr(new afwMath::FixedKernel(kImage));
101  /* </hack> */
102 
103  double background = (*_spatialBackground)(kCandidate->getXCenter(), kCandidate->getYCenter());
104 
105  MaskedImageT diffim = kCandidate->getDifferenceImage(kernelPtr, background);
106 
107  if (DEBUG_IMAGES) {
108  kImage.writeFits(str(boost::format("askv_k%d.fits") % kCandidate->getId()));
109  diffim.writeFits(str(boost::format("askv_d%d.fits") % kCandidate->getId()));
110  }
111 
112  /* Official resids */
113  try {
114  if (_useCoreStats)
115  _imstats.apply(diffim, _coreRadius);
116  else
117  _imstats.apply(diffim);
118  } catch (pexExcept::Exception& e) {
119  LOGL_DEBUG("TRACE2.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
120  "Unable to calculate imstats for Candidate %d", kCandidate->getId());
121  kCandidate->setStatus(afwMath::SpatialCellCandidate::BAD);
122  return;
123  }
124 
125  _nProcessed += 1;
126 
127  LOGL_DEBUG("TRACE4.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
128  "Chi2 = %.3f", _imstats.getVariance());
129  LOGL_DEBUG("TRACE4.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
130  "X = %.2f Y = %.2f",
131  kCandidate->getXCenter(),
132  kCandidate->getYCenter());
133  LOGL_DEBUG("TRACE4.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
134  "Kernel Sum = %.3f", kSum);
135  LOGL_DEBUG("TRACE4.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
136  "Background = %.3f", background);
137  LOGL_DEBUG("TRACE2.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
138  "Candidate %d resids = %.3f +/- %.3f sigma (%d pix)",
139  kCandidate->getId(),
140  _imstats.getMean(),
141  _imstats.getRms(),
142  _imstats.getNpix());
143 
144  bool meanIsNan = std::isnan(_imstats.getMean());
145  bool rmsIsNan = std::isnan(_imstats.getRms());
146  if (meanIsNan || rmsIsNan) {
147  kCandidate->setStatus(afwMath::SpatialCellCandidate::BAD);
148  LOGL_DEBUG("TRACE3.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
149  "Rejecting candidate %d, encountered NaN",
150  kCandidate->getId());
151  _nRejected += 1;
152  return;
153  }
154 
155  if (_ps->getAsBool("spatialKernelClipping")) {
156  if (fabs(_imstats.getMean()) > _ps->getAsDouble("candidateResidualMeanMax")) {
157  kCandidate->setStatus(afwMath::SpatialCellCandidate::BAD);
158  LOGL_DEBUG("TRACE3.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
159  "Rejecting candidate %d; bad mean residual : |%.3f| > %.3f",
160  kCandidate->getId(),
161  _imstats.getMean(),
162  _ps->getAsDouble("candidateResidualMeanMax"));
163  _nRejected += 1;
164  }
165  else if (_imstats.getRms() > _ps->getAsDouble("candidateResidualStdMax")) {
166  kCandidate->setStatus(afwMath::SpatialCellCandidate::BAD);
167  LOGL_DEBUG("TRACE3.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
168  "Rejecting candidate %d; bad residual rms : %.3f > %.3f",
169  kCandidate->getId(),
170  _imstats.getRms(),
171  _ps->getAsDouble("candidateResidualStdMax"));
172  _nRejected += 1;
173  }
174  else {
175  kCandidate->setStatus(afwMath::SpatialCellCandidate::GOOD);
176  LOGL_DEBUG("TRACE3.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
177  "Spatial kernel OK");
178  _nGood += 1;
179  }
180  }
181  else {
182  kCandidate->setStatus(afwMath::SpatialCellCandidate::GOOD);
183  LOGL_DEBUG("TRACE5.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
184  "Sigma clipping not enabled");
185  _nGood += 1;
186  }
187 
188  /* Core resids for debugging */
189  if (!(_useCoreStats)) {
190  try {
191  _imstats.apply(diffim, _coreRadius);
192  } catch (pexExcept::Exception& e) {
193  LOGL_DEBUG("TRACE2.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
194  "Unable to calculate core imstats for Candidate %d",
195  kCandidate->getId());
196  kCandidate->setStatus(afwMath::SpatialCellCandidate::BAD);
197  return;
198  }
199  LOGL_DEBUG("TRACE3.ip.diffim.AssessSpatialKernelVisitor.processCandidate",
200  "Candidate %d core resids = %.3f +/- %.3f sigma (%d pix)",
201  kCandidate->getId(),
202  _imstats.getMean(),
203  _imstats.getRms(),
204  _imstats.getNpix());
205  }
206  }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:504
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:58
A kernel created from an Image.
Definition: Kernel.h:472
lsst::geom::Extent2I const getDimensions() const
Return the Kernel's dimensions (width, height)
Definition: Kernel.h:213
double computeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize, double x=0.0, double y=0.0) const
Compute an image (pixellized representation of the kernel) in place.
Definition: Kernel.cc:85
Provides consistent interface for LSST exceptions.
Definition: Exception.h:107
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
T fabs(T... args)
T isnan(T... args)
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
#define DEBUG_IMAGES

◆ reset()

template<typename PixelT >
void lsst::ip::diffim::detail::AssessSpatialKernelVisitor< PixelT >::reset ( )
inlinevirtual

Reimplemented from lsst::afw::math::CandidateVisitor.

Definition at line 38 of file AssessSpatialKernelVisitor.h.

38 {_nGood = 0; _nRejected = 0; _nProcessed = 0;}

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