Skip to content

Commit

Permalink
Merge branch 'tickets/DM-23623'
Browse files Browse the repository at this point in the history
  • Loading branch information
plazas committed Apr 8, 2020
2 parents a8ea8f5 + ead1cea commit dc8ce7c
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions python/lsst/ip/isr/crosstalk.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,37 @@ def run(self, exposure, crosstalkSources=None, isTrimmed=False):
------
RuntimeError
Raised if called for a detector that does not have a
crosstalk correction
crosstalk correction.
TypeError
Raised if crosstalkSources is not None
and not a numpy array or a dictionary.
"""
detector = exposure.getDetector()
if not self.config.hasCrosstalk(detector=detector):
raise RuntimeError("Attempted to correct crosstalk without crosstalk coefficients")
coeffs = self.config.getCrosstalk(detector=detector)
if crosstalkSources is not None:
if isinstance(crosstalkSources, np.ndarray):
coeffs = crosstalkSources
elif isinstance(crosstalkSources, dict):
# Nested dictionary produced by `measureCrosstalk.py`
# There are two keys first in the nested dictionary
for fKey, fValue in crosstalkSources.items():
for sKey, sValue in fValue.items():
firstKey = fKey
secondKey = sKey
tempDict = crosstalkSources[firstKey][secondKey]
coeffs = []
for thirdKey in tempDict:
tempList = []
for fourthKey in tempDict[thirdKey]:
value = tempDict[thirdKey][fourthKey]
tempList.append(value)
coeffs.append(tempList)
coeffs = np.array(coeffs)
else:
raise TypeError("crosstalkSources not of the correct type: `np.array` or `dict`")
else:
detector = exposure.getDetector()
if not self.config.hasCrosstalk(detector=detector):
raise RuntimeError("Attempted to correct crosstalk without crosstalk coefficients")
coeffs = self.config.getCrosstalk(detector=detector)

self.log.info("Applying crosstalk correction.")
subtractCrosstalk(exposure, crosstalkCoeffs=coeffs,
Expand Down

0 comments on commit dc8ce7c

Please sign in to comment.