From 78500d4c2cd1292dd49bada77a7130749b566b9d Mon Sep 17 00:00:00 2001 From: Ian Sullivan Date: Tue, 16 Dec 2025 10:25:30 -0800 Subject: [PATCH 1/2] Remove matchedTemplate from spatially sampled metrics --- .../diffim/computeSpatiallySampledMetrics.py | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/python/lsst/ip/diffim/computeSpatiallySampledMetrics.py b/python/lsst/ip/diffim/computeSpatiallySampledMetrics.py index 804f82746..a0b28162a 100644 --- a/python/lsst/ip/diffim/computeSpatiallySampledMetrics.py +++ b/python/lsst/ip/diffim/computeSpatiallySampledMetrics.py @@ -48,12 +48,6 @@ class SpatiallySampledMetricsConnections(pipeBase.PipelineTaskConnections, storageClass="ExposureF", name="{fakesType}calexp" ) - matchedTemplate = pipeBase.connectionTypes.Input( - doc="Warped and PSF-matched template used to create the difference image.", - dimensions=("instrument", "visit", "detector"), - storageClass="ExposureF", - name="{fakesType}{coaddName}Diff_matchedExp", - ) template = pipeBase.connectionTypes.Input( doc="Warped and not PSF-matched template used to create the difference image.", dimensions=("instrument", "visit", "detector"), @@ -195,16 +189,13 @@ def __init__(self, **kwargs): units="radian") @timeMethod - def run(self, science, matchedTemplate, template, difference, diaSources, psfMatchingKernel): + def run(self, science, template, difference, diaSources, psfMatchingKernel): """Calculate difference image metrics on specific locations across the images Parameters ---------- science : `lsst.afw.image.ExposureF` Science exposure that the template was subtracted from. - matchedTemplate : `lsst.afw.image.ExposureF` - Warped and PSF-matched template that was used produce the - difference image. template : `lsst.afw.image.ExposureF` Warped and non PSF-matched template that was used produce the difference image. @@ -237,13 +228,13 @@ def run(self, science, matchedTemplate, template, difference, diaSources, psfMat self.log.info("Unable to calculate metrics for mask plane %s: not in image"%maskPlane) for src in spatiallySampledMetrics: - self._evaluateLocalMetric(src, science, matchedTemplate, template, difference, diaSources, + self._evaluateLocalMetric(src, science, template, difference, diaSources, metricsMaskPlanes=metricsMaskPlanes, psfMatchingKernel=psfMatchingKernel) return pipeBase.Struct(spatiallySampledMetrics=spatiallySampledMetrics.asAstropy()) - def _evaluateLocalMetric(self, src, science, matchedTemplate, template, difference, diaSources, + def _evaluateLocalMetric(self, src, science, template, difference, diaSources, metricsMaskPlanes, psfMatchingKernel): """Calculate image quality metrics at spatially sampled locations. @@ -255,8 +246,6 @@ def _evaluateLocalMetric(self, src, science, matchedTemplate, template, differen The catalog of detected sources. science : `lsst.afw.image.Exposure` The science image. - matchedTemplate : `lsst.afw.image.Exposure` - The reference image, warped and psf-matched to the science image. difference : `lsst.afw.image.Exposure` Result of subtracting template from the science image. metricsMaskPlanes : `list` of `str` @@ -293,7 +282,7 @@ def _evaluateLocalMetric(self, src, science, matchedTemplate, template, differen meanDipoleSeparation = np.mean(dipoleSources["ip_diffim_DipoleFit_separation"]) src.set('dipole_separation', meanDipoleSeparation) - templateVal = np.median(matchedTemplate[bbox].image.array) + templateVal = np.median(template[bbox].image.array) scienceVal = np.median(science[bbox].image.array) diffimVal = np.median(difference[bbox].image.array) src.set('source_density', sourceDensity) From d817f60be4d302d92e0adda4a70af662e255e352 Mon Sep 17 00:00:00 2001 From: Ian Sullivan Date: Tue, 16 Dec 2025 16:02:32 -0800 Subject: [PATCH 2/2] Switch spatial metrics to use final filtered diaSource catalog --- .../lsst/ip/diffim/computeSpatiallySampledMetrics.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/python/lsst/ip/diffim/computeSpatiallySampledMetrics.py b/python/lsst/ip/diffim/computeSpatiallySampledMetrics.py index a0b28162a..cddec0afb 100644 --- a/python/lsst/ip/diffim/computeSpatiallySampledMetrics.py +++ b/python/lsst/ip/diffim/computeSpatiallySampledMetrics.py @@ -63,8 +63,8 @@ class SpatiallySampledMetricsConnections(pipeBase.PipelineTaskConnections, diaSources = pipeBase.connectionTypes.Input( doc="Filtered diaSources on the difference image.", dimensions=("instrument", "visit", "detector"), - storageClass="SourceCatalog", - name="{fakesType}{coaddName}Diff_candidateDiaSrc", + storageClass="ArrowAstropy", + name="{fakesType}dia_source_detector", ) psfMatchingKernel = pipeBase.connectionTypes.Input( doc="Kernel used to PSF match the science and template images.", @@ -271,15 +271,15 @@ def _evaluateLocalMetric(self, src, science, template, difference, diaSources, src.set('x', peak['i_x']) src.set('y', peak['i_y']) src.setCoord(science.wcs.pixelToSky(peak['i_x'], peak['i_y'])) - selectSources = diaSources[bbox.contains(diaSources.getX(), diaSources.getY())] + selectSources = diaSources[bbox.contains(diaSources['x'], diaSources['y'])] sourceDensity = len(selectSources)/area - dipoleSources = selectSources[selectSources["ip_diffim_DipoleFit_classification"]] + dipoleSources = selectSources[selectSources["isDipole"]] dipoleDensity = len(dipoleSources)/area if dipoleSources: - meanDipoleOrientation = angleMean(dipoleSources["ip_diffim_DipoleFit_orientation"]) + meanDipoleOrientation = angleMean(dipoleSources["dipoleAngle"]) src.set('dipole_direction', meanDipoleOrientation) - meanDipoleSeparation = np.mean(dipoleSources["ip_diffim_DipoleFit_separation"]) + meanDipoleSeparation = np.mean(dipoleSources["dipoleLength"]) src.set('dipole_separation', meanDipoleSeparation) templateVal = np.median(template[bbox].image.array)