ScaleVarianceTask#

class lsst.meas.algorithms.ScaleVarianceTask(*args, **kwargs)#

Bases: Task

Scale the variance in a MaskedImage

The variance plane in a convolved or warped image (or a coadd derived from warped images) does not accurately reflect the noise properties of the image because variance has been lost to covariance. This Task attempts to correct for this by scaling the variance plane to match the observed variance in the image. This is not perfect (because we’re not tracking the covariance) but it’s simple and is often good enough.

The task implements a pixel-based and an image-based correction estimator.

Methods Summary

computeScaleFactors(maskedImage)

Calculate and return both variance scaling factors without modifying the image.

imageBased(maskedImage)

Determine the variance rescaling factor from image statistics

pixelBased(maskedImage)

Determine the variance rescaling factor from pixel statistics

run(maskedImage)

Rescale the variance in a maskedImage in place.

subtractedBackground(maskedImage)

Context manager for subtracting the background

Methods Documentation

computeScaleFactors(maskedImage)#

Calculate and return both variance scaling factors without modifying the image.

Parameters#

maskedImagelsst.afw.image.MaskedImage

Image for which to determine the variance rescaling factor.

Returns#

Rlsst.pipe.base.Struct
  • pixelFactor : float The pixel based variance rescaling factor or 1 if all pixels are masked or invalid.

  • imageFactor : float The image based variance rescaling factor or 1 if all pixels are masked or invalid.

imageBased(maskedImage)#

Determine the variance rescaling factor from image statistics

We calculate average(SNR) = stdev(image)/median(variance), and the value should be unity. We use the interquartile range as a robust estimator of the stdev. The variance rescaling factor is the factor that brings this value to unity.

This may not work well if the pixels from which we measure the standard deviation of the image are not effectively the same pixels from which we measure the median of the variance. In that case, use an alternate method.

Parameters#

maskedImagelsst.afw.image.MaskedImage

Image for which to determine the variance rescaling factor.

Returns#

factorfloat

Variance rescaling factor or 1 if all pixels are masked or non-finite.

pixelBased(maskedImage)#

Determine the variance rescaling factor from pixel statistics

We calculate SNR = image/sqrt(variance), and the distribution for most of the background-subtracted image should have a standard deviation of unity. We use the interquartile range as a robust estimator of the SNR standard deviation. The variance rescaling factor is the factor that brings that distribution to have unit standard deviation.

This may not work well if the image has a lot of structure in it, as the assumptions are violated. In that case, use an alternate method.

Parameters#

maskedImagelsst.afw.image.MaskedImage

Image for which to determine the variance rescaling factor.

Returns#

factorfloat

Variance rescaling factor or 1 if all pixels are masked or non-finite.

run(maskedImage)#

Rescale the variance in a maskedImage in place.

Parameters#

maskedImagelsst.afw.image.MaskedImage

Image for which to determine the variance rescaling factor. The image is modified in place.

Returns#

factorfloat

Variance rescaling factor.

Raises#

ExceedsMaxVarianceScaleError

If the estimated variance rescaling factor by both methods exceed the configured limit.

Notes#

The task calculates and applies the pixel-based correction unless it is over the config.limit threshold. In this case, the image-based method is applied.

subtractedBackground(maskedImage)#

Context manager for subtracting the background

We need to subtract the background so that the entire image (apart from objects, which should be clipped) will have the image/sqrt(variance) distributed about zero.

This context manager subtracts the background, and ensures it is restored on exit.

Parameters#

maskedImagelsst.afw.image.MaskedImage

Image+mask+variance to have background subtracted and restored.

Returns#

contextcontext manager

Context manager that ensure the background is restored.