138 fitBasisComponents=
False, variance=
None, chi=
None):
139 """Display the PSF candidates.
141 If psf is provided include PSF model and residuals; if normalize is true normalize the PSFs
144 If chi is True, generate a plot of residuals/sqrt(variance), i.e. chi
146 If fitBasisComponents is true, also find the best linear combination of the PSF's components
150 display = afwDisplay.Display()
153 if variance
is not None:
158 mos = displayUtils.Mosaic()
160 candidateCenters = []
161 candidateCentersBad = []
164 for cell
in psfCellSet.getCellList():
165 for cand
in cell.begin(
False):
166 rchi2 = cand.getChi2()
170 if not showBadCandidates
and cand.isBad():
174 im_resid = displayUtils.Mosaic(gutter=0, background=-5, mode=
"x")
177 im = cand.getMaskedImage()
178 xc, yc = cand.getXCenter(), cand.getYCenter()
180 margin = 0
if True else 5
181 w, h = im.getDimensions()
185 bim = im.Factory(w + 2*margin, h + 2*margin)
189 bim.getVariance().
set(stdev**2)
196 im = im.Factory(im,
True)
197 im.setXY0(cand.getMaskedImage().getXY0())
202 im_resid.append(im.Factory(im,
True))
206 psfIm = mi.getImage()
207 config = measBase.SingleFrameMeasurementTask.ConfigClass()
208 config.slots.centroid =
"base_SdssCentroid"
210 schema = afwTable.SourceTable.makeMinimalSchema()
211 measureSources = measBase.SingleFrameMeasurementTask(schema, config=config)
215 miBig = mi.Factory(im.getWidth() + 2*extra, im.getHeight() + 2*extra)
216 miBig[extra:-extra, extra:-extra, afwImage.LOCAL] = mi
217 miBig.setXY0(mi.getX0() - extra, mi.getY0() - extra)
227 footprintSet.makeSources(catalog)
229 if len(catalog) == 0:
230 raise RuntimeError(
"Failed to detect any objects")
232 measureSources.run(catalog, exp)
233 if len(catalog) == 1:
237 for i, s
in enumerate(catalog):
238 d = numpy.hypot(xc - s.getX(), yc - s.getY())
239 if i == 0
or d < dmin:
241 xc, yc = source.getCentroid()
251 resid = resid.getImage()
252 var = im.getVariance()
253 var = var.Factory(var,
True)
254 numpy.sqrt(var.getArray(), var.getArray())
257 im_resid.append(resid)
260 if fitBasisComponents:
261 im = cand.getMaskedImage()
263 im = im.Factory(im,
True)
264 im.setXY0(cand.getMaskedImage().getXY0())
267 noSpatialKernel = psf.getKernel()
269 noSpatialKernel =
None
278 outImage = afwImage.ImageD(outputKernel.getDimensions())
279 outputKernel.computeImage(outImage,
False)
281 im -= outImage.convertF()
285 bim = im.Factory(w + 2*margin, h + 2*margin)
289 bim.assign(resid, bbox)
293 resid = resid.getImage()
296 im_resid.append(resid)
298 im = im_resid.makeMosaic()
300 im = cand.getMaskedImage()
305 objId =
splitId(cand.getSource().getId(),
True)[
"objId"]
307 lab =
"%d chi^2 %.1f" % (objId, rchi2)
308 ctype = afwDisplay.RED
if cand.isBad()
else afwDisplay.GREEN
310 lab =
"%d flux %8.3g" % (objId, cand.getSource().getPsfInstFlux())
311 ctype = afwDisplay.GREEN
313 mos.append(im, lab, ctype)
315 if False and numpy.isnan(rchi2):
316 display.mtv(cand.getMaskedImage().getImage(), title=
"showPsfCandidates: candidate")
317 print(
"amp", cand.getAmplitude())
319 im = cand.getMaskedImage()
320 center = (candidateIndex, xc - im.getX0(), yc - im.getY0())
323 candidateCentersBad.append(center)
325 candidateCenters.append(center)
328 title =
"chi(Psf fit)"
330 title =
"Stars & residuals"
331 mosaicImage = mos.makeMosaic(display=display, title=title)
333 with display.Buffering():
334 for centers, color
in ((candidateCenters, afwDisplay.GREEN), (candidateCentersBad, afwDisplay.RED)):
336 bbox = mos.getBBox(cen[0])
337 display.dot(
"+", cen[1] + bbox.getMinX(), cen[2] + bbox.getMinY(), ctype=color)
A Threshold is used to pass a threshold value to detection algorithms.
A kernel that is a linear combination of fixed basis kernels.
A class that can be used to generate sequences of random numbers according to a number of different a...
An integer coordinate rectangle.
daf::base::PropertySet * set
std::shared_ptr< Exposure< ImagePixelT, MaskPixelT, VariancePixelT > > makeExposure(MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > &mimage, std::shared_ptr< geom::SkyWcs const > wcs=std::shared_ptr< geom::SkyWcs const >())
A function to return an Exposure of the correct type (cf.
void randomGaussianImage(ImageT *image, Random &rand)
Set image to random numbers with a gaussian N(0, 1) distribution.
Statistics makeStatistics(lsst::afw::image::Image< Pixel > const &img, lsst::afw::image::Mask< image::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Handle a watered-down front-end to the constructor (no variance)
def splitId(oid, asDict=True)
double subtractPsf(afw::detection::Psf const &psf, ImageT *data, double x, double y, double psfFlux=std::numeric_limits< double >::quiet_NaN())