Skip to content

Commit

Permalink
Fix gen3 handling of new bfKernel data.
Browse files Browse the repository at this point in the history
  • Loading branch information
czwa committed Jan 28, 2020
1 parent 5e0e0c1 commit fb28bf9
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions python/lsst/ip/isr/isrTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ class IsrTaskConnections(pipeBase.PipelineTaskConnections,
storageClass="NumpyArray",
dimensions=["instrument", "calibration_label"],
)
newBFKernel = cT.PrerequisiteInput(
name='brighterFatterKernel',
doc="Newer complete kernel + gain solutions.",
storageClass="BrighterFatterKernel",
dimensions=["instrument", "calibration_label", "detector"],
)
defects = cT.PrerequisiteInput(
name='defects',
doc="Input defect tables.",
Expand Down Expand Up @@ -181,6 +187,7 @@ def __init__(self, *, config=None):
self.prerequisiteInputs.discard("crosstalkSources")
if config.doBrighterFatter is not True:
self.prerequisiteInputs.discard("bfKernel")
self.prerequisiteInputs.discard("newBFKernel")
if config.doDefect is not True:
self.prerequisiteInputs.discard("defects")
if config.doDark is not True:
Expand Down Expand Up @@ -831,33 +838,35 @@ def runQuantum(self, butlerQC, inputRefs, outputRefs):
if not isinstance(inputs["defects"], Defects):
inputs["defects"] = Defects.fromTable(inputs["defects"])

# TODO: DM-22776 add retrieval for brighter-fatter kernel for Gen3
# if we can get HSC to use a new kernel, or just translate the old
# one to the new format we could drop the whole new/old style support

# Broken: DM-17169
# ci_hsc does not use crosstalkSources, as it's intra-CCD CT only. This needs to be
# fixed for non-HSC cameras in the future.
# inputs['crosstalkSources'] = (self.crosstalk.prepCrosstalk(inputsIds['ccdExposure'])
# if self.config.doCrosstalk else None)
# Load the correct style of brighter fatter kernel, and repack
# the information as a numpy array.
if self.config.doBrighterFatter:
brighterFatterKernel = inputs.get('bfKernel', None)
brighterFatterKernel = inputs.pop('newBFKernel', None)
if brighterFatterKernel is None:
brighterFatterKernel = inputs.get('bfKernel', None)

if brighterFatterKernel is not None and not isinstance(brighterFatterKernel, numpy.ndarray):
detId = detector.getId()
inputs['bfGains'] = brighterFatterKernel.gain
# If the kernel is not an ndarray, it's the cp_pipe version
# so extract the kernel for this detector, or raise an error
if self.config.brighterFatterLevel == 'DETECTOR':
ccd = inputs['ccdExposure']
if brighterFatterKernel.detectorKernel:
inputs['bfKernel'] = brighterFatterKernel.detectorKernel[ccd.getId()]
inputs['bfKernel'] = brighterFatterKernel.detectorKernel[detId]
elif brighterFatterKernel.detectorKernelFromAmpKernels:
inputs['bfKernel'] = brighterFatterKernel.detectorKernelFromAmpKernels[ccd.getId()]
inputs['bfKernel'] = brighterFatterKernel.detectorKernelFromAmpKernels[detId]
else:
raise RuntimeError("Failed to extract kernel from new-style BF kernel.")
else:
# TODO DM-15631 for implementing this
raise NotImplementedError("Per-amplifier brighter-fatter correction not implemented")

# Broken: DM-17169
# ci_hsc does not use crosstalkSources, as it's intra-CCD CT only. This needs to be
# fixed for non-HSC cameras in the future.
# inputs['crosstalkSources'] = (self.crosstalk.prepCrosstalk(inputsIds['ccdExposure'])
# if self.config.doCrosstalk else None)

if self.config.doFringe is True and self.fringe.checkFilter(inputs['ccdExposure']):
expId = inputs['ccdExposure'].getInfo().getVisitInfo().getExposureId()
inputs['fringes'] = self.fringe.loadFringes(inputs['fringes'],
Expand Down Expand Up @@ -960,7 +969,7 @@ def readIsrData(self, dataRef, rawExposure):
# If using a new-style kernel, always use the self-consistent
# gains, i.e. the ones inside the kernel object itself
brighterFatterKernel = dataRef.get("brighterFatterKernel")
brighterFatterGains = brighterFatterKernel.gain
brighterFatterGains = getattr(brighterFatterKernel, 'gain', None)
self.log.info("New style bright-fatter kernel (brighterFatterKernel) loaded")
except NoResults:
try: # Fall back to the old-style numpy-ndarray style kernel if necessary.
Expand Down Expand Up @@ -1341,7 +1350,8 @@ def run(self, ccdExposure, camera=None, bias=None, linearizer=None, crosstalkSou
)
bfExp = interpExp.clone()

self.log.info("Applying brighter fatter correction.")
self.log.info("Applying brighter fatter correction using kernel type %s / gains %s.",
type(bfKernel), type(bfGains))
bfResults = isrFunctions.brighterFatterCorrection(bfExp, bfKernel,
self.config.brighterFatterMaxIter,
self.config.brighterFatterThreshold,
Expand Down

0 comments on commit fb28bf9

Please sign in to comment.