132 fitBasisComponents=
False, variance=
None, chi=
None):
133 """Display the PSF candidates. 135 If psf is provided include PSF model and residuals; if normalize is true normalize the PSFs 138 If chi is True, generate a plot of residuals/sqrt(variance), i.e. chi 140 If fitBasisComponents is true, also find the best linear combination of the PSF's components 144 display = afwDisplay.Display()
147 if variance
is not None:
152 mos = displayUtils.Mosaic()
154 candidateCenters = []
155 candidateCentersBad = []
158 for cell
in psfCellSet.getCellList():
159 for cand
in cell.begin(
False):
160 rchi2 = cand.getChi2()
164 if not showBadCandidates
and cand.isBad():
168 im_resid = displayUtils.Mosaic(gutter=0, background=-5, mode=
"x")
171 im = cand.getMaskedImage()
172 xc, yc = cand.getXCenter(), cand.getYCenter()
174 margin = 0
if True else 5
175 w, h = im.getDimensions()
179 bim = im.Factory(w + 2*margin, h + 2*margin)
183 bim.getVariance().
set(stdev**2)
190 im = im.Factory(im,
True)
191 im.setXY0(cand.getMaskedImage().getXY0())
196 im_resid.append(im.Factory(im,
True))
200 psfIm = mi.getImage()
201 config = measBase.SingleFrameMeasurementTask.ConfigClass()
202 config.slots.centroid =
"base_SdssCentroid" 204 schema = afwTable.SourceTable.makeMinimalSchema()
205 measureSources = measBase.SingleFrameMeasurementTask(schema, config=config)
209 miBig = mi.Factory(im.getWidth() + 2*extra, im.getHeight() + 2*extra)
210 miBig[extra:-extra, extra:-extra, afwImage.LOCAL] = mi
211 miBig.setXY0(mi.getX0() - extra, mi.getY0() - extra)
221 footprintSet.makeSources(catalog)
223 if len(catalog) == 0:
224 raise RuntimeError(
"Failed to detect any objects")
226 measureSources.run(catalog, exp)
227 if len(catalog) == 1:
231 for i, s
in enumerate(catalog):
232 d = numpy.hypot(xc - s.getX(), yc - s.getY())
233 if i == 0
or d < dmin:
235 xc, yc = source.getCentroid()
245 resid = resid.getImage()
246 var = im.getVariance()
247 var = var.Factory(var,
True)
248 numpy.sqrt(var.getArray(), var.getArray())
251 im_resid.append(resid)
254 if fitBasisComponents:
255 im = cand.getMaskedImage()
257 im = im.Factory(im,
True)
258 im.setXY0(cand.getMaskedImage().getXY0())
261 noSpatialKernel = psf.getKernel()
263 noSpatialKernel =
None 272 outImage = afwImage.ImageD(outputKernel.getDimensions())
273 outputKernel.computeImage(outImage,
False)
275 im -= outImage.convertF()
279 bim = im.Factory(w + 2*margin, h + 2*margin)
283 bim.assign(resid, bbox)
287 resid = resid.getImage()
290 im_resid.append(resid)
292 im = im_resid.makeMosaic()
294 im = cand.getMaskedImage()
299 objId =
splitId(cand.getSource().getId(),
True)[
"objId"]
301 lab =
"%d chi^2 %.1f" % (objId, rchi2)
302 ctype = afwDisplay.RED
if cand.isBad()
else afwDisplay.GREEN
304 lab =
"%d flux %8.3g" % (objId, cand.getSource().getPsfInstFlux())
305 ctype = afwDisplay.GREEN
307 mos.append(im, lab, ctype)
309 if False and numpy.isnan(rchi2):
310 display.mtv(cand.getMaskedImage().getImage(), title=
"showPsfCandidates: candidate")
311 print(
"amp", cand.getAmplitude())
313 im = cand.getMaskedImage()
314 center = (candidateIndex, xc - im.getX0(), yc - im.getY0())
317 candidateCentersBad.append(center)
319 candidateCenters.append(center)
322 title =
"chi(Psf fit)" 324 title =
"Stars & residuals" 325 mosaicImage = mos.makeMosaic(display=display, title=title)
327 with display.Buffering():
328 for centers, color
in ((candidateCenters, afwDisplay.GREEN), (candidateCentersBad, afwDisplay.RED)):
330 bbox = mos.getBBox(cen[0])
331 display.dot(
"+", cen[1] + bbox.getMinX(), cen[2] + bbox.getMinY(), ctype=color)
double subtractPsf(afw::detection::Psf const &psf, ImageT *data, double x, double y, double psfFlux=std::numeric_limits< double >::quiet_NaN())
A Threshold is used to pass a threshold value to detection algorithms.
daf::base::PropertySet * set
Statistics makeStatistics(lsst::afw::math::MaskedVector< EntryT > const &mv, std::vector< WeightPixel > const &vweights, int const flags, StatisticsControl const &sctrl=StatisticsControl())
The makeStatistics() overload to handle lsst::afw::math::MaskedVector<>
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.
A kernel that is a linear combination of fixed basis kernels.
void randomGaussianImage(ImageT *image, Random &rand)
Set image to random numbers with a gaussian N(0, 1) distribution.
def splitId(oid, asDict=True)
An integer coordinate rectangle.
std::pair< std::vector< double >, afw::math::KernelList > fitKernelParamsToImage(afw::math::LinearCombinationKernel const &kernel, Image const &image, geom::Point2D const &pos)
Fit a LinearCombinationKernel to an Image, allowing the coefficients of the components to vary...
A class that can be used to generate sequences of random numbers according to a number of different a...