Skip to content

Commit

Permalink
Fix incorrect BF kernel transposes.
Browse files Browse the repository at this point in the history
  • Loading branch information
czwa committed May 10, 2023
1 parent 07e61e7 commit 39e9492
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
13 changes: 10 additions & 3 deletions python/lsst/ip/isr/brighterFatterKernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,17 +552,24 @@ def repackCorrelations(self, amp, correlationShape):
# Implementation methods
def makeDetectorKernelFromAmpwiseKernels(self, detectorName, ampsToExclude=[]):
"""Average the amplifier level kernels to create a detector level
kernel.
kernel. There is no change in index ordering/orientation from
this averaging.
Parameters
----------
detectorName : `str`
Detector for which the averaged kernel will be used.
ampsToExclude : `list` [`str`], optional
Amps that should not be included in the average.
"""
inKernels = np.array([self.ampKernels[amp] for amp in
self.ampKernels if amp not in ampsToExclude])
averagingList = np.transpose(inKernels)
avgKernel = np.zeros_like(inKernels[0])
sctrl = afwMath.StatisticsControl()
sctrl.setNumSigmaClip(5.0)
for i in range(np.shape(avgKernel)[0]):
for j in range(np.shape(avgKernel)[1]):
avgKernel[i, j] = afwMath.makeStatistics(averagingList[i, j],
avgKernel[i, j] = afwMath.makeStatistics(inKernels[:, i, j],
afwMath.MEANCLIP, sctrl).getValue()

self.detKernels[detectorName] = avgKernel
Expand Down
21 changes: 18 additions & 3 deletions python/lsst/ip/isr/isrTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,26 +1037,41 @@ def runQuantum(self, butlerQC, inputRefs, outputRefs):
if self.config.doBrighterFatter:
brighterFatterKernel = inputs.pop('newBFKernel', None)
if brighterFatterKernel is None:
# This type of kernel must be in (y, x) index
# ordering, as it used directly as the .array
# component of the afwImage kernel.
brighterFatterKernel = inputs.get('bfKernel', None)

if brighterFatterKernel is not None and not isinstance(brighterFatterKernel, numpy.ndarray):
# This is a ISR calib kernel
# This is a ISR calib kernel. These kernels are
# generated in (x, y) index ordering, and need to be
# transposed to be used directly as the .array
# component of the afwImage kernel. This is done
# explicitly below when setting the ``bfKernel``
# input.
detName = detector.getName()
level = brighterFatterKernel.level

# This is expected to be a dictionary of amp-wise gains.
inputs['bfGains'] = brighterFatterKernel.gain
if self.config.brighterFatterLevel == 'DETECTOR':
kernel = None
if level == 'DETECTOR':
if detName in brighterFatterKernel.detKernels:
inputs['bfKernel'] = brighterFatterKernel.detKernels[detName]
kernel = brighterFatterKernel.detKernels[detName]
else:
raise RuntimeError("Failed to extract kernel from new-style BF kernel.")
elif level == 'AMP':
self.log.warning("Making DETECTOR level kernel from AMP based brighter "
"fatter kernels.")
brighterFatterKernel.makeDetectorKernelFromAmpwiseKernels(detName)
inputs['bfKernel'] = brighterFatterKernel.detKernels[detName]
kernel = brighterFatterKernel.detKernels[detName]
if kernel is None:
raise RuntimeError("Could not identify brighter-fatter kernel!")
# Do the one single transpose here so the kernel
# can be directly loaded into the afwImage .array
# component.
inputs['bfKernel'] = numpy.transpose(kernel)
elif self.config.brighterFatterLevel == 'AMP':
raise NotImplementedError("Per-amplifier brighter-fatter correction not implemented")

Expand Down

0 comments on commit 39e9492

Please sign in to comment.