Skip to content

Commit

Permalink
Remove scipy convolution option
Browse files Browse the repository at this point in the history
  • Loading branch information
djreiss committed Jun 28, 2016
1 parent 629057d commit e31492d
Showing 1 changed file with 22 additions and 35 deletions.
57 changes: 22 additions & 35 deletions python/lsst/ip/diffim/imageDecorrelation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,23 @@ class DecorrelateALKernelConfig(pexConfig.Config):
\anchor DecorrelateALKernelConfig_
\brief Configuration parameters for the DecorrelateALKernelTask
"""
useScipy = pexConfig.Field(
dtype=bool,
doc="If True use scipy for image convolution (debugging option); if False use afwMath",
default=False
)
Currently there are no parameters for DecorrelateALKernelTask.
"""
pass

## \addtogroup LSST_task_documentation
## \{
## \page exampleCmdLineTask
## \ref ExampleCmdLineTask "ExampleCmdLineTask"
## An example intended to show how to write a command-line task.
## \page DecorrelateALKernelTask
## \ref DecorrelateALKernelTask "DecorrelateALKernelTask"
## Decorrelate the effect of convolution by Alard-Lupton matching kernel in image difference
## \}

class DecorrelateALKernelTask(pipeBase.Task):
"""!
\anchor DecorrelateALKernelTask_
\brief Decorrelate the effect of convolution by A&L matching kernel in image difference
\brief Decorrelate the effect of convolution by Alard-Lupton matching kernel in image difference
\section pipe_tasks_multiBand_Contents Contents
Expand All @@ -72,12 +69,12 @@ class DecorrelateALKernelTask(pipeBase.Task):
Pipe-task that removes the neighboring-pixel covariance in an
image difference that are added when the template image is
convolved with the Alard & Lupton (A&L) PSF matching kernel.
convolved with the Alard-Lupton PSF matching kernel.
The image differencing pipeline \ref
ip_diffim_psfMatch_PsfMatchConfigAL uses the Alard and Lupton
(1998) (A&L) method for matching the PSFs of the template and
science exposures prior to subtraction. The A&L method identifies
(1998) method for matching the PSFs of the template and science
exposures prior to subtraction. The Alard-Lupton method identifies
a matching kernel, which is then (typically) convolved with the
template image to perform PSF matching. This convolution has the
effect of adding covariance between neighboring pixels in the
Expand Down Expand Up @@ -185,8 +182,7 @@ def run(self, templateExposure, exposure, subtractedExposure, psfMatchingKernel)
corrKernel = DecorrelateALKernelTask._computeDecorrelationKernel(kimg.getArray(), sig1=sig1, sig2=sig2)
fcorrKernel = DecorrelateALKernelTask._fixEvenKernel(corrKernel)
self.log.info("Convolving.")
correctedExposure, corrKern = DecorrelateALKernelTask._doConvolve(subtractedExposure, fcorrKernel,
use_scipy=self.config.useScipy)
correctedExposure, corrKern = DecorrelateALKernelTask._doConvolve(subtractedExposure, fcorrKernel)
self.log.info("Updating correctedExposure and its PSF.")

# Compute the subtracted exposure's updated psf
Expand Down Expand Up @@ -282,35 +278,26 @@ def _fixEvenKernel(kernel):
return out

@staticmethod
def _doConvolve(exposure, kernel, use_scipy=False):
def _doConvolve(exposure, kernel):
"""! Convolve an Exposure with a decorrelation convolution kernel.
@param exposure Input afw.image.Exposure to be convolved.
@param kernel Input 2-d numpy.array to convolve the image with
@param use_scipy Use scipy to do convolution instead of afwMath
@return a new Exposure with the convolved pixels and the (possibly
re-centered) kernel.
@note We use afwMath.convolve() but keep scipy.convolve for debugging.
@note We re-center the kernel if necessary and return the possibly re-centered kernel
"""
outExp = kern = None
fkernel = DecorrelateALKernelTask._fixEvenKernel(kernel)
if use_scipy:
pci = scipy_convolve(exposure.getMaskedImage().getImage().getArray(),
fkernel, mode='constant', cval=np.nan)
outExp = exposure.clone()
outExp.getMaskedImage().getImage().getArray()[:, :] = pci
kern = fkernel

else:
kernelImg = afwImage.ImageD(fkernel.shape[0], fkernel.shape[1])
kernelImg.getArray()[:, :] = fkernel
kern = afwMath.FixedKernel(kernelImg)
maxloc = np.unravel_index(np.argmax(fkernel), fkernel.shape)
kern.setCtrX(maxloc[0])
kern.setCtrY(maxloc[1])
outExp = exposure.clone() # Do this to keep WCS, PSF, masks, etc.
convCntrl = afwMath.ConvolutionControl(False, True, 0)
afwMath.convolve(outExp.getMaskedImage(), exposure.getMaskedImage(), kern, convCntrl)

kernelImg = afwImage.ImageD(fkernel.shape[0], fkernel.shape[1])
kernelImg.getArray()[:, :] = fkernel
kern = afwMath.FixedKernel(kernelImg)
maxloc = np.unravel_index(np.argmax(fkernel), fkernel.shape)
kern.setCtrX(maxloc[0])
kern.setCtrY(maxloc[1])
outExp = exposure.clone() # Do this to keep WCS, PSF, masks, etc.
convCntrl = afwMath.ConvolutionControl(False, True, 0)
afwMath.convolve(outExp.getMaskedImage(), exposure.getMaskedImage(), kern, convCntrl)

return outExp, kern

0 comments on commit e31492d

Please sign in to comment.