Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-34584: Use samplingSize in setting stamp size #10

Merged
merged 1 commit into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions python/lsst/meas/extensions/piff/piffPsfDeterminer.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def determinePsf(
self.config.kernelSizeMin,
self.config.kernelSizeMax
))
self._validatePsfCandidates(psfCandidateList, kernelSize)
self._validatePsfCandidates(psfCandidateList, kernelSize, self.config.samplingSize)

stars = []
for candidate in psfCandidateList:
Expand Down Expand Up @@ -297,7 +297,8 @@ def determinePsf(
pointing = None

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

used_image_pos = [s.image_pos for s in piffResult.stars]
if flagKey:
Expand All @@ -316,7 +317,7 @@ def determinePsf(

return psf, None

def _validatePsfCandidates(self, psfCandidateList, kernelSize):
def _validatePsfCandidates(self, psfCandidateList, kernelSize, samplingSize):
"""Raise if psfCandidates are smaller than the configured kernelSize.

Parameters
Expand All @@ -325,6 +326,8 @@ def _validatePsfCandidates(self, psfCandidateList, kernelSize):
Sequence of psf candidates to check.
kernelSize : `int`
Size of image model to use in PIFF.
samplingSize : `float`
Resolution of the internal PSF model relative to the pixel size.

Raises
------
Expand All @@ -334,10 +337,11 @@ def _validatePsfCandidates(self, psfCandidateList, kernelSize):
"""
# We can assume all candidates have the same dimensions.
candidate = psfCandidateList[0]
if (candidate.getHeight() < kernelSize
or candidate.getWidth() < kernelSize):
raise RuntimeError("PSF candidates must be at least config.kernelSize="
f"{kernelSize} pixels per side; "
drawSize = int(2*np.floor(0.5*kernelSize/samplingSize) + 1)
if (candidate.getHeight() < drawSize
or candidate.getWidth() < drawSize):
raise RuntimeError("PSF candidates must be at least config.kernelSize/config.samplingSize="
f"{drawSize} pixels per side; "
f"found {candidate.getWidth()}x{candidate.getHeight()}.")


Expand Down
19 changes: 14 additions & 5 deletions tests/test_psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,15 @@ def testPiffDeterminer_kernelSize27(self):
"""Test Piff with a psf kernelSize of 27."""
self.checkPiffDeterminer(27)

def test_validatePsfCandidates(self):
@lsst.utils.tests.methodParameters(samplingSize=[1.0, 0.9, 1.1])
def test_validatePsfCandidates(self, samplingSize):
"""Test that `_validatePsfCandidates` raises for too-small candidates.
"""
drawSizeDict = {1.0: 27,
0.9: 31,
1.1: 25,
}

makePsfCandidatesConfig = measAlg.MakePsfCandidatesTask.ConfigClass()
makePsfCandidatesConfig.kernelSize = 24
self.makePsfCandidates = measAlg.MakePsfCandidatesTask(config=makePsfCandidatesConfig)
Expand All @@ -316,14 +322,17 @@ def test_validatePsfCandidates(self):
).psfCandidates

psfDeterminerConfig = PiffPsfDeterminerConfig()
psfDeterminerConfig.kernelSize = 25
psfDeterminerConfig.kernelSize = 27
psfDeterminerConfig.samplingSize = samplingSize
self.psfDeterminer = PiffPsfDeterminerTask(psfDeterminerConfig)

with self.assertRaisesRegex(RuntimeError,
"config.kernelSize=25 pixels per side; found 24x24"):
self.psfDeterminer._validatePsfCandidates(psfCandidateList, 25)
f"config.kernelSize/config.samplingSize={drawSizeDict[samplingSize]} "
"pixels per side; found 24x24"):
self.psfDeterminer._validatePsfCandidates(psfCandidateList, 27, samplingSize)

# This should not raise.
self.psfDeterminer._validatePsfCandidates(psfCandidateList, 23)
self.psfDeterminer._validatePsfCandidates(psfCandidateList, 21, samplingSize)


class TestMemory(lsst.utils.tests.MemoryTestCase):
Expand Down