From 73d763396fe3ae34164c977100f5316f60d251fd Mon Sep 17 00:00:00 2001 From: Ian Sullivan Date: Wed, 27 Nov 2024 10:01:08 -0800 Subject: [PATCH] Pass PSF sigma in to fallback source detector. This is necessary in rare cases when convolving the template if building the kernel fails, and the fallback source detector attempts to calculate the template PSF at a chip gap. --- python/lsst/ip/diffim/makeKernel.py | 4 ++-- python/lsst/ip/diffim/subtractImages.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/python/lsst/ip/diffim/makeKernel.py b/python/lsst/ip/diffim/makeKernel.py index b5457b68..46dc47c6 100644 --- a/python/lsst/ip/diffim/makeKernel.py +++ b/python/lsst/ip/diffim/makeKernel.py @@ -276,7 +276,7 @@ def getSelectSources(self, exposure, sigma=None, doSmooth=True, idFactory=None): return selectSources def makeCandidateList(self, convolved, reference, kernelSize, - candidateList, preconvolved=False): + candidateList, preconvolved=False, sigma=None): """Make a list of acceptable KernelCandidates. Generate a list of candidate sources for Psf-matching, remove sources @@ -309,7 +309,7 @@ def makeCandidateList(self, convolved, reference, kernelSize, If ``candidateList`` is empty after sub-selection. """ if candidateList is None: - candidateList = self.getSelectSources(reference, doSmooth=not preconvolved) + candidateList = self.getSelectSources(reference, doSmooth=not preconvolved, sigma=sigma) if len(candidateList) < 1: raise RuntimeError("No kernel candidates after detection and measurement.") diff --git a/python/lsst/ip/diffim/subtractImages.py b/python/lsst/ip/diffim/subtractImages.py index 8ef55938..26a87eef 100644 --- a/python/lsst/ip/diffim/subtractImages.py +++ b/python/lsst/ip/diffim/subtractImages.py @@ -505,8 +505,13 @@ def runConvolveTemplate(self, template, science, selectSources): if self.config.allowKernelSourceDetection: self.log.warning("Error encountered trying to construct the matching kernel" f" Running source detection and retrying. {e}") + kernelSize = self.makeKernel.makeKernelBasisList( + self.templatePsfSize, self.sciencePsfSize)[0].getWidth() + sigmaToFwhm = 2*np.log(2*np.sqrt(2)) + candidateList = self.makeKernel.makeCandidateList(template, science, kernelSize, + sigma=self.sciencePsfSize/sigmaToFwhm) kernelSources = self.makeKernel.selectKernelSources(template, science, - candidateList=None, + candidateList=candidateList, preconvolved=False) kernelResult = self.makeKernel.run(template, science, kernelSources, preconvolved=False)