Skip to content

Commit

Permalink
Remove large objects from Piff results by default
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeyers314 committed Nov 15, 2022
1 parent 6bf3c73 commit c5c553e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
18 changes: 16 additions & 2 deletions python/lsst/meas/extensions/piff/piffPsfDeterminer.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ class PiffPsfDeterminerConfig(BasePsfDeterminerTask.ConfigClass):
check=_validateGalsimInterpolant,
default="Lanczos(11)",
)
debugStarData = pexConfig.Field[bool](
doc="Include star images used for fitting in PSF model object.",
default=False
)

def setDefaults(self):
super().setDefaults()
Expand Down Expand Up @@ -342,7 +346,6 @@ def determinePsf(

piffResult.fit(stars, wcs, pointing, logger=self.log)
drawSize = 2*np.floor(0.5*stampSize/self.config.samplingSize) + 1
psf = PiffPsf(drawSize, drawSize, piffResult)

used_image_pos = [s.image_pos for s in piffResult.stars]
if flagKey:
Expand All @@ -359,7 +362,18 @@ def determinePsf(
metadata["avgX"] = np.mean([p.x for p in piffResult.stars])
metadata["avgY"] = np.mean([p.y for p in piffResult.stars])

return psf, None
if not self.config.debugStarData:
for star in piffResult.stars:
# Remove large data objects from the stars
del star.fit.params
del star.fit.params_var
del star.fit.A
del star.fit.b
del star.data.image
del star.data.weight
del star.data.orig_weight

return PiffPsf(drawSize, drawSize, piffResult), None

# TODO: DM-36311: This method can be removed.
@staticmethod
Expand Down
15 changes: 12 additions & 3 deletions tests/test_psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def setUp(self):
cand = measAlg.makePsfCandidate(source, self.exposure)
self.cellSet.insertCandidate(cand)

def setupDeterminer(self, stampSize=None):
def setupDeterminer(self, stampSize=None, debugStarData=False):
"""Setup the starSelector and psfDeterminer
Parameters
Expand Down Expand Up @@ -192,6 +192,7 @@ def setupDeterminer(self, stampSize=None):
psfDeterminerConfig.spatialOrder = 1
if stampSize is not None:
psfDeterminerConfig.stampSize = stampSize
psfDeterminerConfig.debugStarData = debugStarData

self.psfDeterminer = PiffPsfDeterminerTask(psfDeterminerConfig)

Expand All @@ -218,15 +219,15 @@ def subtractStars(self, exposure, catalog, chi_lim=-1):
self.assertGreater(chi_min, -chi_lim)
self.assertLess(chi_max, chi_lim)

def checkPiffDeterminer(self, stampSize=None):
def checkPiffDeterminer(self, stampSize=None, debugStarData=False):
"""Configure PiffPsfDeterminerTask and run basic tests on it.
Parameters
----------
stampSize : `int`, optional
Set ``config.stampSize`` to this, if not None.
"""
self.setupDeterminer(stampSize=stampSize)
self.setupDeterminer(stampSize=stampSize, debugStarData=debugStarData)
metadata = dafBase.PropertyList()

stars = self.starSelector.run(self.catalog, exposure=self.exposure)
Expand All @@ -251,6 +252,10 @@ def checkPiffDeterminer(self, stampSize=None):
np.mean([s.y for s in psf._piffResult.stars])
)
)
if self.psfDeterminer.config.debugStarData:
self.assertIn('image', psf._piffResult.stars[0].data.__dict__)
else:
self.assertNotIn('image', psf._piffResult.stars[0].data.__dict__)

# Test how well we can subtract the PSF model
self.subtractStars(self.exposure, self.catalog, chi_lim=6.1)
Expand Down Expand Up @@ -308,6 +313,10 @@ def testPiffDeterminer_kernelSize27(self):
"""Test Piff with a psf kernelSize of 27."""
self.checkPiffDeterminer(27)

def testPiffDeterminer_debugStarData(self):
"""Test Piff with debugStarData=True."""
self.checkPiffDeterminer(debugStarData=True)

@lsst.utils.tests.methodParameters(samplingSize=[1.0, 0.9, 1.1])
def test_validatePsfCandidates(self, samplingSize):
"""Test that `_validatePsfCandidates` raises for too-small candidates.
Expand Down

0 comments on commit c5c553e

Please sign in to comment.