673 def run(self, exposure, crosstalk=None,
674 crosstalkSources=None, isTrimmed=False, camera=None):
675 """Apply intra-detector crosstalk correction
679 exposure : `lsst.afw.image.Exposure`
680 Exposure for which to remove crosstalk.
681 crosstalkCalib : `lsst.ip.isr.CrosstalkCalib`, optional
682 External crosstalk calibration to apply. Constructed from
683 detector if not found.
684 crosstalkSources : `defaultdict`, optional
685 Image data for other detectors that are sources of
686 crosstalk in exposure. The keys are expected to be names
687 of the other detectors, with the values containing
688 `lsst.afw.image.Exposure` at the same level of processing
690 The default for intra-detector crosstalk here is None.
691 isTrimmed : `bool`, optional
692 The image is already trimmed.
693 This should no longer be needed once DM-15409 is resolved.
694 camera : `lsst.afw.cameraGeom.Camera`, optional
695 Camera associated with this exposure. Only used for
701 Raised if called for a detector that does not have a
702 crosstalk correction. Also raised if the crosstalkSource
703 is not an expected type.
707 crosstalk = crosstalk.fromDetector(exposure.getDetector(),
708 coeffVector=self.config.crosstalkValues)
709 if not crosstalk.log:
710 crosstalk.log = self.log
711 if not crosstalk.hasCrosstalk:
712 raise RuntimeError(
"Attempted to correct crosstalk without crosstalk coefficients.")
715 self.log.info(
"Applying crosstalk correction.")
716 crosstalk.subtractCrosstalk(exposure, crosstalkCoeffs=crosstalk.coeffs,
717 minPixelToMask=self.config.minPixelToMask,
718 crosstalkStr=self.config.crosstalkMaskPlane, isTrimmed=isTrimmed,
719 backgroundMethod=self.config.crosstalkBackgroundMethod)
721 if crosstalk.interChip:
727 sourceNames = [exp.getDetector().getName()
for exp
in crosstalkSources]
728 elif isinstance(crosstalkSources[0], lsst.daf.butler.DeferredDatasetHandle):
730 detectorList = [source.dataId[
'detector']
for source
in crosstalkSources]
731 sourceNames = [camera[detector].getName()
for detector
in detectorList]
733 raise RuntimeError(
"Unknown object passed as crosstalk sources.",
734 type(crosstalkSources[0]))
736 for detName
in crosstalk.interChip:
737 if detName
not in sourceNames:
738 self.log.warning(
"Crosstalk lists %s, not found in sources: %s",
739 detName, sourceNames)
742 interChipCoeffs = crosstalk.interChip[detName]
744 sourceExposure = crosstalkSources[sourceNames.index(detName)]
745 if isinstance(sourceExposure, lsst.daf.butler.DeferredDatasetHandle):
747 sourceExposure = sourceExposure.get()
749 raise RuntimeError(
"Unknown object passed as crosstalk sources.",
750 type(sourceExposure))
752 self.log.info(
"Correcting detector %s with ctSource %s",
753 exposure.getDetector().getName(),
754 sourceExposure.getDetector().getName())
755 crosstalk.subtractCrosstalk(exposure, sourceExposure=sourceExposure,
756 crosstalkCoeffs=interChipCoeffs,
757 minPixelToMask=self.config.minPixelToMask,
758 crosstalkStr=self.config.crosstalkMaskPlane,
760 backgroundMethod=self.config.crosstalkBackgroundMethod)
762 self.log.warning(
"Crosstalk contains interChip coefficients, but no sources found!")