899 exposure, crosstalk=None,
900 crosstalkSources=None, isTrimmed=False, camera=None, parallelOverscanRegion=False,
903 """Apply intra-detector crosstalk correction
907 exposure : `lsst.afw.image.Exposure`
908 Exposure for which to remove crosstalk.
909 crosstalkCalib : `lsst.ip.isr.CrosstalkCalib`, optional
910 External crosstalk calibration to apply. Constructed from
911 detector if not found.
912 crosstalkSources : `defaultdict`, optional
913 Image data for other detectors that are sources of
914 crosstalk in exposure. The keys are expected to be names
915 of the other detectors, with the values containing
916 `lsst.afw.image.Exposure` at the same level of processing
918 The default for intra-detector crosstalk here is None.
919 isTrimmed : `bool`, optional
920 The image is already trimmed.
921 This should no longer be needed once DM-15409 is resolved.
922 camera : `lsst.afw.cameraGeom.Camera`, optional
923 Camera associated with this exposure. Only used for
925 parallelOverscanRegion : `bool`, optional
926 Do subtraction in parallel overscan region (only)?
927 detectorConfig : `lsst.ip.isr.OverscanDetectorConfig`, optional
928 Per-amplifier configs used when parallelOverscanRegion=True.
933 Raised if called for a detector that does not have a
934 crosstalk correction. Also raised if the crosstalkSource
935 is not an expected type.
939 crosstalk = crosstalk.fromDetector(exposure.getDetector(),
940 coeffVector=self.config.crosstalkValues)
941 if not crosstalk.log:
942 crosstalk.log = self.log
944 doSqrCrosstalk = self.config.doQuadraticCrosstalkCorrection
945 if doSqrCrosstalk
and crosstalk.coeffsSqr
is None:
946 raise RuntimeError(
"Attempted to perform NL crosstalk correction without NL "
947 "crosstalk coefficients.")
949 crosstalkCoeffsSqr = crosstalk.coeffsSqr
951 crosstalkCoeffsSqr =
None
953 if not crosstalk.hasCrosstalk:
954 raise RuntimeError(
"Attempted to correct crosstalk without crosstalk coefficients.")
955 elif parallelOverscanRegion:
956 self.log.info(
"Applying crosstalk correction to parallel overscan region.")
957 crosstalk.subtractCrosstalkParallelOverscanRegion(
959 crosstalkCoeffs=crosstalk.coeffs,
960 crosstalkCoeffsSqr=crosstalkCoeffsSqr,
961 detectorConfig=detectorConfig,
962 doSqrCrosstalk=doSqrCrosstalk,
965 self.log.info(
"Applying crosstalk correction.")
966 crosstalk.subtractCrosstalk(exposure, crosstalkCoeffs=crosstalk.coeffs,
967 crosstalkCoeffsSqr=crosstalkCoeffsSqr,
968 minPixelToMask=self.config.minPixelToMask,
969 crosstalkStr=self.config.crosstalkMaskPlane, isTrimmed=isTrimmed,
970 backgroundMethod=self.config.crosstalkBackgroundMethod,
971 doSqrCrosstalk=doSqrCrosstalk)
973 if crosstalk.interChip:
979 sourceNames = [exp.getDetector().getName()
for exp
in crosstalkSources]
980 elif isinstance(crosstalkSources[0], lsst.daf.butler.DeferredDatasetHandle):
982 detectorList = [source.dataId[
'detector']
for source
in crosstalkSources]
983 sourceNames = [camera[detector].getName()
for detector
in detectorList]
985 raise RuntimeError(
"Unknown object passed as crosstalk sources.",
986 type(crosstalkSources[0]))
988 for detName
in crosstalk.interChip:
989 if detName
not in sourceNames:
990 self.log.warning(
"Crosstalk lists %s, not found in sources: %s",
991 detName, sourceNames)
994 interChipCoeffs = crosstalk.interChip[detName]
996 sourceExposure = crosstalkSources[sourceNames.index(detName)]
997 if isinstance(sourceExposure, lsst.daf.butler.DeferredDatasetHandle):
999 sourceExposure = sourceExposure.get()
1001 raise RuntimeError(
"Unknown object passed as crosstalk sources.",
1002 type(sourceExposure))
1004 self.log.info(
"Correcting detector %s with ctSource %s",
1005 exposure.getDetector().getName(),
1006 sourceExposure.getDetector().getName())
1007 crosstalk.subtractCrosstalk(exposure, sourceExposure=sourceExposure,
1008 crosstalkCoeffs=interChipCoeffs,
1009 minPixelToMask=self.config.minPixelToMask,
1010 crosstalkStr=self.config.crosstalkMaskPlane,
1011 isTrimmed=isTrimmed,
1012 backgroundMethod=self.config.crosstalkBackgroundMethod)
1014 self.log.warning(
"Crosstalk contains interChip coefficients, but no sources found!")