136 fitBasisComponents=
False, variance=
None, chi=
None):
137 """Display the PSF candidates.
139 If psf is provided include PSF model and residuals; if normalize is true normalize the PSFs
142 If chi is True, generate a plot of residuals/sqrt(variance), i.e. chi
144 If fitBasisComponents is true, also find the best linear combination of the PSF's components
148 display = afwDisplay.Display()
151 if variance
is not None:
156 mos = displayUtils.Mosaic()
158 candidateCenters = []
159 candidateCentersBad = []
162 for cell
in psfCellSet.getCellList():
163 for cand
in cell.begin(
False):
164 rchi2 = cand.getChi2()
168 if not showBadCandidates
and cand.isBad():
172 im_resid = displayUtils.Mosaic(gutter=0, background=-5, mode=
"x")
175 im = cand.getMaskedImage()
176 xc, yc = cand.getXCenter(), cand.getYCenter()
178 margin = 0
if True else 5
179 w, h = im.getDimensions()
183 bim = im.Factory(w + 2*margin, h + 2*margin)
187 bim.getVariance().
set(stdev**2)
194 im = im.Factory(im,
True)
195 im.setXY0(cand.getMaskedImage().getXY0())
200 im_resid.append(im.Factory(im,
True))
204 psfIm = mi.getImage()
205 config = measBase.SingleFrameMeasurementTask.ConfigClass()
206 config.slots.centroid =
"base_SdssCentroid"
208 schema = afwTable.SourceTable.makeMinimalSchema()
209 measureSources = measBase.SingleFrameMeasurementTask(schema, config=config)
213 miBig = mi.Factory(im.getWidth() + 2*extra, im.getHeight() + 2*extra)
214 miBig[extra:-extra, extra:-extra, afwImage.LOCAL] = mi
215 miBig.setXY0(mi.getX0() - extra, mi.getY0() - extra)
225 footprintSet.makeSources(catalog)
227 if len(catalog) == 0:
228 raise RuntimeError(
"Failed to detect any objects")
230 measureSources.run(catalog, exp)
231 if len(catalog) == 1:
235 for i, s
in enumerate(catalog):
236 d = numpy.hypot(xc - s.getX(), yc - s.getY())
237 if i == 0
or d < dmin:
239 xc, yc = source.getCentroid()
249 resid = resid.getImage()
250 var = im.getVariance()
251 var = var.Factory(var,
True)
252 numpy.sqrt(var.getArray(), var.getArray())
255 im_resid.append(resid)
258 if fitBasisComponents:
259 im = cand.getMaskedImage()
261 im = im.Factory(im,
True)
262 im.setXY0(cand.getMaskedImage().getXY0())
265 noSpatialKernel = psf.getKernel()
267 noSpatialKernel =
None
276 outImage = afwImage.ImageD(outputKernel.getDimensions())
277 outputKernel.computeImage(outImage,
False)
279 im -= outImage.convertF()
283 bim = im.Factory(w + 2*margin, h + 2*margin)
287 bim.assign(resid, bbox)
291 resid = resid.getImage()
294 im_resid.append(resid)
296 im = im_resid.makeMosaic()
298 im = cand.getMaskedImage()
303 objId =
splitId(cand.getSource().getId(),
True)[
"objId"]
305 lab =
"%d chi^2 %.1f" % (objId, rchi2)
306 ctype = afwDisplay.RED
if cand.isBad()
else afwDisplay.GREEN
308 lab =
"%d flux %8.3g" % (objId, cand.getSource().getPsfInstFlux())
309 ctype = afwDisplay.GREEN
311 mos.append(im, lab, ctype)
313 if False and numpy.isnan(rchi2):
314 display.mtv(cand.getMaskedImage().getImage(), title=
"showPsfCandidates: candidate")
315 print(
"amp", cand.getAmplitude())
317 im = cand.getMaskedImage()
318 center = (candidateIndex, xc - im.getX0(), yc - im.getY0())
321 candidateCentersBad.append(center)
323 candidateCenters.append(center)
326 title =
"chi(Psf fit)"
328 title =
"Stars & residuals"
329 mosaicImage = mos.makeMosaic(display=display, title=title)
331 with display.Buffering():
332 for centers, color
in ((candidateCenters, afwDisplay.GREEN), (candidateCentersBad, afwDisplay.RED)):
334 bbox = mos.getBBox(cen[0])
335 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())