1001 def runPreconvolve(self, template, science, matchedScience, selectSources, preConvKernel):
1002 """Convolve the science image with its own PSF, then convolve the
1003 template with a matching kernel and subtract to form the Score
1004 exposure.
1005
1006 Parameters
1007 ----------
1008 template : `lsst.afw.image.ExposureF`
1009 Template exposure, warped to match the science exposure.
1010 science : `lsst.afw.image.ExposureF`
1011 Science exposure to subtract from the template.
1012 matchedScience : `lsst.afw.image.ExposureF`
1013 The science exposure, convolved with the reflection of its own PSF.
1014 selectSources : `lsst.afw.table.SourceCatalog`
1015 Identified sources on the science exposure. This catalog is used to
1016 select sources in order to perform the AL PSF matching on stamp
1017 images around them.
1018 preConvKernel : `lsst.afw.math.Kernel`
1019 The reflection of the kernel that was used to preconvolve the
1020 `science` exposure. Must be normalized to sum to 1.
1021
1022 Returns
1023 -------
1024 results : `lsst.pipe.base.Struct`
1025
1026 ``scoreExposure`` : `lsst.afw.image.ExposureF`
1027 Result of subtracting the convolved template and science
1028 images. Attached PSF is that of the original science image.
1029 ``matchedTemplate`` : `lsst.afw.image.ExposureF`
1030 Warped and PSF-matched template exposure. Attached PSF is that
1031 of the original science image.
1032 ``matchedScience`` : `lsst.afw.image.ExposureF`
1033 The science exposure after convolving with its own PSF.
1034 Attached PSF is that of the original science image.
1035 ``backgroundModel`` : `lsst.afw.math.Function2D`
1036 Background model that was fit while solving for the
1037 PSF-matching kernel
1038 ``psfMatchingKernel`` : `lsst.afw.math.Kernel`
1039 Final kernel used to PSF-match the template to the science
1040 image.
1041 """
1042 bbox = science.getBBox()
1043 innerBBox = preConvKernel.shrinkBBox(bbox)
1044
1045 kernelSources = self.makeKernel.selectKernelSources(template[innerBBox], matchedScience[innerBBox],
1046 candidateList=selectSources,
1047 preconvolved=True)
1048 kernelResult = self.makeKernel.run(template[innerBBox], matchedScience[innerBBox], kernelSources,
1049 preconvolved=True)
1050
1051 matchedTemplate = self._convolveExposure(template, kernelResult.psfMatchingKernel,
1052 self.convolutionControl,
1053 bbox=bbox,
1054 psf=science.psf,
1055 interpolateBadMaskPlanes=True,
1056 photoCalib=science.photoCalib)
1057 score = _subtractImages(matchedScience, matchedTemplate,
1058 backgroundModel=(kernelResult.backgroundModel
1059 if self.config.doSubtractBackground else None))
1060 correctedScore = self.finalize(template[bbox], science, score,
1061 kernelResult.psfMatchingKernel,
1062 templateMatched=True, preConvMode=True,
1063 preConvKernel=preConvKernel)
1064
1065 return lsst.pipe.base.Struct(scoreExposure=correctedScore,
1066 matchedTemplate=matchedTemplate,
1067 matchedScience=matchedScience,
1068 backgroundModel=kernelResult.backgroundModel,
1069 psfMatchingKernel=kernelResult.psfMatchingKernel)
1070
1071