325 self, exposure, psfCandidateList, metadata=None, flagKey=None
327 """Determine a Piff PSF model for an exposure given a list of PSF
332 exposure : `lsst.afw.image.Exposure`
333 Exposure containing the PSF candidates.
334 psfCandidateList : `list` of `lsst.meas.algorithms.PsfCandidate`
335 A sequence of PSF candidates typically obtained by detecting sources
336 and then running them through a star selector.
337 metadata : `lsst.daf.base import PropertyList` or `None`, optional
338 A home for interesting tidbits of information.
339 flagKey : `str` or `None`, optional
340 Schema key used to mark sources actually used in PSF determination.
344 psf : `lsst.meas.extensions.piff.PiffPsf`
345 The measured PSF model.
347 Unused by this PsfDeterminer.
351 if self.config.stampSize:
352 stampSize = self.config.stampSize
353 if stampSize > psfCandidateList[0].getWidth():
354 self.log.warning(
"stampSize is larger than the PSF candidate size. Using candidate size.")
355 stampSize = psfCandidateList[0].getWidth()
357 self.log.debug(
"stampSize not set. Using candidate size.")
358 stampSize = psfCandidateList[0].getWidth()
360 scale = exposure.getWcs().getPixelScale(exposure.getBBox().getCenter()).asArcseconds()
362 match self.config.useCoordinates:
364 detector = exposure.getDetector()
365 pix_to_field = detector.getTransform(PIXELS, FIELD_ANGLE)
371 skyOrigin = exposure.getWcs().getSkyOrigin()
372 ra = skyOrigin.getLongitude().asDegrees()
373 dec = skyOrigin.getLatitude().asDegrees()
374 pointing = galsim.CelestialCoord(
380 gswcs = galsim.PixelScale(scale)
384 for candidate
in psfCandidateList:
385 cmi = candidate.getMaskedImage(stampSize, stampSize)
387 fracGood = np.sum(good)/good.size
388 if fracGood < self.config.minimumUnmaskedFraction:
393 bds = galsim.BoundsI(
394 galsim.PositionI(*bbox.getMin()),
395 galsim.PositionI(*bbox.getMax())
397 gsImage = galsim.Image(bds, wcs=gswcs, dtype=float)
398 gsImage.array[:] = cmi.image.array
399 gsWeight = galsim.Image(bds, wcs=gswcs, dtype=float)
400 gsWeight.array[:] = weight
402 source = candidate.getSource()
403 image_pos = galsim.PositionD(source.getX(), source.getY())
405 data = piff.StarData(
411 stars.append(piff.Star(data,
None))
417 'scale': scale * self.config.samplingSize,
418 'size': self.config.modelSize,
419 'interp': self.config.interpolant
422 'type':
'BasisPolynomial',
423 'order': self.config.spatialOrder
427 'nsigma': self.config.outlierNSigma,
428 'max_remove': self.config.outlierMaxRemove
432 piffResult = piff.PSF.process(piffConfig)
435 piffResult.fit(stars, wcs, pointing, logger=self.
piffLogger)
436 drawSize = 2*np.floor(0.5*stampSize/self.config.samplingSize) + 1
438 used_image_pos = [s.image_pos
for s
in piffResult.stars]
440 for candidate
in psfCandidateList:
441 source = candidate.getSource()
442 posd = galsim.PositionD(source.getX(), source.getY())
443 if posd
in used_image_pos:
444 source.set(flagKey,
True)
446 if metadata
is not None:
447 metadata[
"spatialFitChi2"] = piffResult.chisq
448 metadata[
"numAvailStars"] = len(stars)
449 metadata[
"numGoodStars"] = len(piffResult.stars)
450 metadata[
"avgX"] = np.mean([p.x
for p
in piffResult.stars])
451 metadata[
"avgY"] = np.mean([p.y
for p
in piffResult.stars])
453 if not self.config.debugStarData:
454 for star
in piffResult.stars:
457 del star.fit.params_var
462 del star.data.orig_weight
464 return PiffPsf(drawSize, drawSize, piffResult),
None