276 self, exposure, psfCandidateList, metadata=None, flagKey=None
278 """Determine a Piff PSF model for an exposure given a list of PSF
283 exposure : `lsst.afw.image.Exposure`
284 Exposure containing the PSF candidates.
285 psfCandidateList : `list` of `lsst.meas.algorithms.PsfCandidate`
286 A sequence of PSF candidates typically obtained by detecting sources
287 and then running them through a star selector.
288 metadata : `lsst.daf.base import PropertyList` or `None`, optional
289 A home for interesting tidbits of information.
290 flagKey : `str` or `None`, optional
291 Schema key used to mark sources actually used in PSF determination.
295 psf : `lsst.meas.extensions.piff.PiffPsf`
296 The measured PSF model.
298 Unused by this PsfDeterminer.
302 if self.config.stampSize:
303 stampSize = self.config.stampSize
304 if stampSize > psfCandidateList[0].getWidth():
305 self.log.warning(
"stampSize is larger than the PSF candidate size. Using candidate size.")
306 stampSize = psfCandidateList[0].getWidth()
308 self.log.debug(
"stampSize not set. Using candidate size.")
309 stampSize = psfCandidateList[0].getWidth()
311 scale = exposure.getWcs().getPixelScale().asArcseconds()
312 match self.config.useCoordinates:
314 detector = exposure.getDetector()
315 pix_to_field = detector.getTransform(PIXELS, FIELD_ANGLE)
320 skyOrigin = exposure.getWcs().getSkyOrigin()
321 ra = skyOrigin.getLongitude().asDegrees()
322 dec = skyOrigin.getLatitude().asDegrees()
323 pointing = galsim.CelestialCoord(
328 gswcs = galsim.PixelScale(scale)
332 for candidate
in psfCandidateList:
333 cmi = candidate.getMaskedImage(stampSize, stampSize)
335 fracGood = np.sum(good)/good.size
336 if fracGood < self.config.minimumUnmaskedFraction:
341 bds = galsim.BoundsI(
342 galsim.PositionI(*bbox.getMin()),
343 galsim.PositionI(*bbox.getMax())
345 gsImage = galsim.Image(bds, wcs=gswcs, dtype=float)
346 gsImage.array[:] = cmi.image.array
347 gsWeight = galsim.Image(bds, wcs=gswcs, dtype=float)
348 gsWeight.array[:] = weight
350 source = candidate.getSource()
351 image_pos = galsim.PositionD(source.getX(), source.getY())
353 data = piff.StarData(
359 stars.append(piff.Star(data,
None))
365 'scale': scale * self.config.samplingSize,
367 'interp': self.config.interpolant
370 'type':
'BasisPolynomial',
371 'order': self.config.spatialOrder
375 'nsigma': self.config.outlierNSigma,
376 'max_remove': self.config.outlierMaxRemove
380 piffResult = piff.PSF.process(piffConfig)
383 piffResult.fit(stars, wcs, pointing, logger=self.log)
384 drawSize = 2*np.floor(0.5*stampSize/self.config.samplingSize) + 1
386 used_image_pos = [s.image_pos
for s
in piffResult.stars]
388 for candidate
in psfCandidateList:
389 source = candidate.getSource()
390 posd = galsim.PositionD(source.getX(), source.getY())
391 if posd
in used_image_pos:
392 source.set(flagKey,
True)
394 if metadata
is not None:
395 metadata[
"spatialFitChi2"] = piffResult.chisq
396 metadata[
"numAvailStars"] = len(stars)
397 metadata[
"numGoodStars"] = len(piffResult.stars)
398 metadata[
"avgX"] = np.mean([p.x
for p
in piffResult.stars])
399 metadata[
"avgY"] = np.mean([p.y
for p
in piffResult.stars])
401 if not self.config.debugStarData:
402 for star
in piffResult.stars:
405 del star.fit.params_var
410 del star.data.orig_weight
412 return PiffPsf(drawSize, drawSize, piffResult),
None