1062 def runPreconvolve(self, template, science, matchedScience, selectSources, preConvKernel):
1063 """Convolve the science image with its own PSF, then convolve the
1064 template with a matching kernel and subtract to form the Score
1065 exposure.
1066
1067 Parameters
1068 ----------
1069 template : `lsst.afw.image.ExposureF`
1070 Template exposure, warped to match the science exposure.
1071 science : `lsst.afw.image.ExposureF`
1072 Science exposure to subtract from the template.
1073 matchedScience : `lsst.afw.image.ExposureF`
1074 The science exposure, convolved with the reflection of its own PSF.
1075 selectSources : `lsst.afw.table.SourceCatalog`
1076 Identified sources on the science exposure. This catalog is used to
1077 select sources in order to perform the AL PSF matching on stamp
1078 images around them.
1079 preConvKernel : `lsst.afw.math.Kernel`
1080 The reflection of the kernel that was used to preconvolve the
1081 `science` exposure. Must be normalized to sum to 1.
1082
1083 Returns
1084 -------
1085 results : `lsst.pipe.base.Struct`
1086
1087 ``scoreExposure`` : `lsst.afw.image.ExposureF`
1088 Result of subtracting the convolved template and science
1089 images. Attached PSF is that of the original science image.
1090 ``matchedTemplate`` : `lsst.afw.image.ExposureF`
1091 Warped and PSF-matched template exposure. Attached PSF is that
1092 of the original science image.
1093 ``matchedScience`` : `lsst.afw.image.ExposureF`
1094 The science exposure after convolving with its own PSF.
1095 Attached PSF is that of the original science image.
1096 ``backgroundModel`` : `lsst.afw.math.Function2D`
1097 Background model that was fit while solving for the
1098 PSF-matching kernel
1099 ``psfMatchingKernel`` : `lsst.afw.math.Kernel`
1100 Final kernel used to PSF-match the template to the science
1101 image.
1102 """
1103 bbox = science.getBBox()
1104 innerBBox = preConvKernel.shrinkBBox(bbox)
1105
1106 kernelSources = self.makeKernel.selectKernelSources(template[innerBBox], matchedScience[innerBBox],
1107 candidateList=selectSources,
1108 preconvolved=True)
1109 kernelResult = self.makeKernel.run(template[innerBBox], matchedScience[innerBBox], kernelSources,
1110 preconvolved=True)
1111
1112 matchedTemplate = self._convolveExposure(template, kernelResult.psfMatchingKernel,
1113 self.convolutionControl,
1114 bbox=bbox,
1115 psf=science.psf,
1116 interpolateBadMaskPlanes=True,
1117 photoCalib=science.photoCalib)
1118 score = _subtractImages(matchedScience, matchedTemplate,
1119 backgroundModel=(kernelResult.backgroundModel
1120 if self.config.doSubtractBackground else None))
1121 correctedScore = self.finalize(template[bbox], science, score,
1122 kernelResult.psfMatchingKernel,
1123 templateMatched=True, preConvMode=True,
1124 preConvKernel=preConvKernel)
1125
1126 return lsst.pipe.base.Struct(scoreExposure=correctedScore,
1127 matchedTemplate=matchedTemplate,
1128 matchedScience=matchedScience,
1129 backgroundModel=kernelResult.backgroundModel,
1130 psfMatchingKernel=kernelResult.psfMatchingKernel)
1131
1132