Skip to content

Commit

Permalink
Merge pull request #12 from lsst/tickets/DM-34778
Browse files Browse the repository at this point in the history
DM-34778: Expose interpolant in Piff config
  • Loading branch information
arunkannawadi committed May 25, 2022
2 parents c3b167f + 6645d2f commit c7cc541
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
29 changes: 28 additions & 1 deletion python/lsst/meas/extensions/piff/piffPsfDeterminer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import numpy as np
import piff
import galsim
import re

import lsst.pex.config as pexConfig
import lsst.meas.algorithms as measAlg
Expand All @@ -32,6 +33,22 @@


class PiffPsfDeterminerConfig(BasePsfDeterminerTask.ConfigClass):
def _validateGalsimInterpolant(name: str) -> bool: # noqa: N805
"""A helper function to validate the GalSim interpolant at config time.
"""
# First, check if ``name`` is a valid Lanczos interpolant.
for pattern in (re.compile(r"Lanczos\(\d+\)"), re.compile(r"galsim.Lanczos\(\d+\)"),):
match = re.match(pattern, name) # Search from the start of the string.
if match is not None:
# Check that the pattern is also the end of the string.
return match.end() == len(name)

# If not, check if ``name`` is any other valid GalSim interpolant.
names = {"galsim.{interp}" for interp in
("Cubic", "Delta", "Linear", "Nearest", "Quintic", "SincInterpolant")
}
return name in names

spatialOrder = pexConfig.Field(
doc="specify spatial order for PSF kernel creation",
dtype=int,
Expand Down Expand Up @@ -69,6 +86,15 @@ class PiffPsfDeterminerConfig(BasePsfDeterminerTask.ConfigClass):
dtype=float,
default=0.5
)
interpolant = pexConfig.Field(
doc="GalSim interpolant name for Piff to use. "
"Options include 'Lanczos(N)', where N is an integer, along with "
"galsim.Cubic, galsim.Delta, galsim.Linear, galsim.Nearest, "
"galsim.Quintic, and galsim.SincInterpolant.",
dtype=str,
check=_validateGalsimInterpolant,
default="Lanczos(11)",
)

def setDefaults(self):
self.kernelSize = 21
Expand Down Expand Up @@ -278,7 +304,8 @@ def determinePsf(
'model': {
'type': 'PixelGrid',
'scale': self.config.samplingSize,
'size': kernelSize
'size': kernelSize,
'interp': self.config.interpolant
},
'interp': {
'type': 'BasisPolynomial',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def checkPiffDeterminer(self, kernelSize=None):
)

# Test how well we can subtract the PSF model
self.subtractStars(self.exposure, self.catalog, chi_lim=5.6)
self.subtractStars(self.exposure, self.catalog, chi_lim=6.1)

# Test bboxes
for point in [
Expand Down

0 comments on commit c7cc541

Please sign in to comment.