LSSTApplications
19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
|
|
def | createPsf (fwhm) |
|
def | transposeMaskedImage (maskedImage) |
|
def | interpolateDefectList (maskedImage, defectList, fwhm, fallbackValue=None) |
|
def | makeThresholdMask (maskedImage, threshold, growFootprints=1, maskName='SAT') |
|
def | growMasks (mask, radius=0, maskNameList=['BAD'], maskValue="BAD") |
|
def | interpolateFromMask (maskedImage, fwhm, growSaturatedFootprints=1, maskNameList=['SAT'], fallbackValue=None) |
|
def | saturationCorrection (maskedImage, saturation, fwhm, growFootprints=1, interpolate=True, maskName='SAT', fallbackValue=None) |
|
def | trimToMatchCalibBBox (rawMaskedImage, calibMaskedImage) |
|
def | biasCorrection (maskedImage, biasMaskedImage, trimToFit=False) |
|
def | darkCorrection (maskedImage, darkMaskedImage, expScale, darkScale, invert=False, trimToFit=False) |
|
def | updateVariance (maskedImage, gain, readNoise) |
|
def | flatCorrection (maskedImage, flatMaskedImage, scalingType, userScale=1.0, invert=False, trimToFit=False) |
|
def | illuminationCorrection (maskedImage, illumMaskedImage, illumScale, trimToFit=True) |
|
def | overscanCorrection (ampMaskedImage, overscanImage, fitType='MEDIAN', order=1, collapseRej=3.0, statControl=None, overscanIsInt=True) |
|
def | brighterFatterCorrection (exposure, kernel, maxIter, threshold, applyGain, gains=None) |
|
def | gainContext (exp, image, apply, gains=None) |
|
def | attachTransmissionCurve (exposure, opticsTransmission=None, filterTransmission=None, sensorTransmission=None, atmosphereTransmission=None) |
|
def | applyGains (exposure, normalizeGains=False) |
|
def | widenSaturationTrails (mask) |
|
def | setBadRegions (exposure, badStatistic="MEDIAN") |
|
◆ applyGains()
def lsst.ip.isr.isrFunctions.applyGains |
( |
|
exposure, |
|
|
|
normalizeGains = False |
|
) |
| |
Scale an exposure by the amplifier gains.
Parameters
----------
exposure : `lsst.afw.image.Exposure`
Exposure to process. The image is modified.
normalizeGains : `Bool`, optional
If True, then amplifiers are scaled to force the median of
each amplifier to equal the median of those medians.
Definition at line 746 of file isrFunctions.py.
746 def applyGains(exposure, normalizeGains=False):
747 """Scale an exposure by the amplifier gains.
751 exposure : `lsst.afw.image.Exposure`
752 Exposure to process. The image is modified.
753 normalizeGains : `Bool`, optional
754 If True, then amplifiers are scaled to force the median of
755 each amplifier to equal the median of those medians.
757 ccd = exposure.getDetector()
758 ccdImage = exposure.getMaskedImage()
762 sim = ccdImage.Factory(ccdImage, amp.getBBox())
766 medians.append(numpy.median(sim.getImage().getArray()))
769 median = numpy.median(numpy.array(medians))
770 for index, amp
in enumerate(ccd):
771 sim = ccdImage.Factory(ccdImage, amp.getBBox())
772 if medians[index] != 0.0:
773 sim *= median/medians[index]
◆ attachTransmissionCurve()
def lsst.ip.isr.isrFunctions.attachTransmissionCurve |
( |
|
exposure, |
|
|
|
opticsTransmission = None , |
|
|
|
filterTransmission = None , |
|
|
|
sensorTransmission = None , |
|
|
|
atmosphereTransmission = None |
|
) |
| |
Attach a TransmissionCurve to an Exposure, given separate curves for
different components.
Parameters
----------
exposure : `lsst.afw.image.Exposure`
Exposure object to modify by attaching the product of all given
``TransmissionCurves`` in post-assembly trimmed detector coordinates.
Must have a valid ``Detector`` attached that matches the detector
associated with sensorTransmission.
opticsTransmission : `lsst.afw.image.TransmissionCurve`
A ``TransmissionCurve`` that represents the throughput of the optics,
to be evaluated in focal-plane coordinates.
filterTransmission : `lsst.afw.image.TransmissionCurve`
A ``TransmissionCurve`` that represents the throughput of the filter
itself, to be evaluated in focal-plane coordinates.
sensorTransmission : `lsst.afw.image.TransmissionCurve`
A ``TransmissionCurve`` that represents the throughput of the sensor
itself, to be evaluated in post-assembly trimmed detector coordinates.
atmosphereTransmission : `lsst.afw.image.TransmissionCurve`
A ``TransmissionCurve`` that represents the throughput of the
atmosphere, assumed to be spatially constant.
Returns
-------
combined : `lsst.afw.image.TransmissionCurve`
The TransmissionCurve attached to the exposure.
Notes
-----
All ``TransmissionCurve`` arguments are optional; if none are provided, the
attached ``TransmissionCurve`` will have unit transmission everywhere.
Definition at line 694 of file isrFunctions.py.
695 sensorTransmission=None, atmosphereTransmission=None):
696 """Attach a TransmissionCurve to an Exposure, given separate curves for
697 different components.
701 exposure : `lsst.afw.image.Exposure`
702 Exposure object to modify by attaching the product of all given
703 ``TransmissionCurves`` in post-assembly trimmed detector coordinates.
704 Must have a valid ``Detector`` attached that matches the detector
705 associated with sensorTransmission.
706 opticsTransmission : `lsst.afw.image.TransmissionCurve`
707 A ``TransmissionCurve`` that represents the throughput of the optics,
708 to be evaluated in focal-plane coordinates.
709 filterTransmission : `lsst.afw.image.TransmissionCurve`
710 A ``TransmissionCurve`` that represents the throughput of the filter
711 itself, to be evaluated in focal-plane coordinates.
712 sensorTransmission : `lsst.afw.image.TransmissionCurve`
713 A ``TransmissionCurve`` that represents the throughput of the sensor
714 itself, to be evaluated in post-assembly trimmed detector coordinates.
715 atmosphereTransmission : `lsst.afw.image.TransmissionCurve`
716 A ``TransmissionCurve`` that represents the throughput of the
717 atmosphere, assumed to be spatially constant.
721 combined : `lsst.afw.image.TransmissionCurve`
722 The TransmissionCurve attached to the exposure.
726 All ``TransmissionCurve`` arguments are optional; if none are provided, the
727 attached ``TransmissionCurve`` will have unit transmission everywhere.
729 combined = afwImage.TransmissionCurve.makeIdentity()
730 if atmosphereTransmission
is not None:
731 combined *= atmosphereTransmission
732 if opticsTransmission
is not None:
733 combined *= opticsTransmission
734 if filterTransmission
is not None:
735 combined *= filterTransmission
736 detector = exposure.getDetector()
737 fpToPix = detector.getTransform(fromSys=camGeom.FOCAL_PLANE,
738 toSys=camGeom.PIXELS)
739 combined = combined.transformedBy(fpToPix)
740 if sensorTransmission
is not None:
741 combined *= sensorTransmission
742 exposure.getInfo().setTransmissionCurve(combined)
◆ biasCorrection()
def lsst.ip.isr.isrFunctions.biasCorrection |
( |
|
maskedImage, |
|
|
|
biasMaskedImage, |
|
|
|
trimToFit = False |
|
) |
| |
Apply bias correction in place.
Parameters
----------
maskedImage : `lsst.afw.image.MaskedImage`
Image to process. The image is modified by this method.
biasMaskedImage : `lsst.afw.image.MaskedImage`
Bias image of the same size as ``maskedImage``
trimToFit : `Bool`, optional
If True, raw data is symmetrically trimmed to match
calibration size.
Raises
------
RuntimeError
Raised if ``maskedImage`` and ``biasMaskedImage`` do not have
the same size.
Definition at line 270 of file isrFunctions.py.
270 def biasCorrection(maskedImage, biasMaskedImage, trimToFit=False):
271 """Apply bias correction in place.
275 maskedImage : `lsst.afw.image.MaskedImage`
276 Image to process. The image is modified by this method.
277 biasMaskedImage : `lsst.afw.image.MaskedImage`
278 Bias image of the same size as ``maskedImage``
279 trimToFit : `Bool`, optional
280 If True, raw data is symmetrically trimmed to match
286 Raised if ``maskedImage`` and ``biasMaskedImage`` do not have
293 if maskedImage.getBBox(afwImage.LOCAL) != biasMaskedImage.getBBox(afwImage.LOCAL):
294 raise RuntimeError(
"maskedImage bbox %s != biasMaskedImage bbox %s" %
295 (maskedImage.getBBox(afwImage.LOCAL), biasMaskedImage.getBBox(afwImage.LOCAL)))
296 maskedImage -= biasMaskedImage
◆ brighterFatterCorrection()
def lsst.ip.isr.isrFunctions.brighterFatterCorrection |
( |
|
exposure, |
|
|
|
kernel, |
|
|
|
maxIter, |
|
|
|
threshold, |
|
|
|
applyGain, |
|
|
|
gains = None |
|
) |
| |
Apply brighter fatter correction in place for the image.
Parameters
----------
exposure : `lsst.afw.image.Exposure`
Exposure to have brighter-fatter correction applied. Modified
by this method.
kernel : `numpy.ndarray`
Brighter-fatter kernel to apply.
maxIter : scalar
Number of correction iterations to run.
threshold : scalar
Convergence threshold in terms of the sum of absolute
deviations between an iteration and the previous one.
applyGain : `Bool`
If True, then the exposure values are scaled by the gain prior
to correction.
gains : `dict` [`str`, `float`]
A dictionary, keyed by amplifier name, of the gains to use.
If gains is None, the nominal gains in the amplifier object are used.
Returns
-------
diff : `float`
Final difference between iterations achieved in correction.
iteration : `int`
Number of iterations used to calculate correction.
Notes
-----
This correction takes a kernel that has been derived from flat
field images to redistribute the charge. The gradient of the
kernel is the deflection field due to the accumulated charge.
Given the original image I(x) and the kernel K(x) we can compute
the corrected image Ic(x) using the following equation:
Ic(x) = I(x) + 0.5*d/dx(I(x)*d/dx(int( dy*K(x-y)*I(y))))
To evaluate the derivative term we expand it as follows:
0.5 * ( d/dx(I(x))*d/dx(int(dy*K(x-y)*I(y))) + I(x)*d^2/dx^2(int(dy* K(x-y)*I(y))) )
Because we use the measured counts instead of the incident counts
we apply the correction iteratively to reconstruct the original
counts and the correction. We stop iterating when the summed
difference between the current corrected image and the one from
the previous iteration is below the threshold. We do not require
convergence because the number of iterations is too large a
computational cost. How we define the threshold still needs to be
evaluated, the current default was shown to work reasonably well
on a small set of images. For more information on the method see
DocuShare Document-19407.
The edges as defined by the kernel are not corrected because they
have spurious values due to the convolution.
Definition at line 519 of file isrFunctions.py.
520 """Apply brighter fatter correction in place for the image.
524 exposure : `lsst.afw.image.Exposure`
525 Exposure to have brighter-fatter correction applied. Modified
527 kernel : `numpy.ndarray`
528 Brighter-fatter kernel to apply.
530 Number of correction iterations to run.
532 Convergence threshold in terms of the sum of absolute
533 deviations between an iteration and the previous one.
535 If True, then the exposure values are scaled by the gain prior
537 gains : `dict` [`str`, `float`]
538 A dictionary, keyed by amplifier name, of the gains to use.
539 If gains is None, the nominal gains in the amplifier object are used.
544 Final difference between iterations achieved in correction.
546 Number of iterations used to calculate correction.
550 This correction takes a kernel that has been derived from flat
551 field images to redistribute the charge. The gradient of the
552 kernel is the deflection field due to the accumulated charge.
554 Given the original image I(x) and the kernel K(x) we can compute
555 the corrected image Ic(x) using the following equation:
557 Ic(x) = I(x) + 0.5*d/dx(I(x)*d/dx(int( dy*K(x-y)*I(y))))
559 To evaluate the derivative term we expand it as follows:
561 0.5 * ( d/dx(I(x))*d/dx(int(dy*K(x-y)*I(y))) + I(x)*d^2/dx^2(int(dy* K(x-y)*I(y))) )
563 Because we use the measured counts instead of the incident counts
564 we apply the correction iteratively to reconstruct the original
565 counts and the correction. We stop iterating when the summed
566 difference between the current corrected image and the one from
567 the previous iteration is below the threshold. We do not require
568 convergence because the number of iterations is too large a
569 computational cost. How we define the threshold still needs to be
570 evaluated, the current default was shown to work reasonably well
571 on a small set of images. For more information on the method see
572 DocuShare Document-19407.
574 The edges as defined by the kernel are not corrected because they
575 have spurious values due to the convolution.
577 image = exposure.getMaskedImage().getImage()
580 with gainContext(exposure, image, applyGain, gains):
582 kLx = numpy.shape(kernel)[0]
583 kLy = numpy.shape(kernel)[1]
584 kernelImage = afwImage.ImageD(kLx, kLy)
585 kernelImage.getArray()[:, :] = kernel
586 tempImage = image.clone()
588 nanIndex = numpy.isnan(tempImage.getArray())
589 tempImage.getArray()[nanIndex] = 0.
591 outImage = afwImage.ImageF(image.getDimensions())
592 corr = numpy.zeros_like(image.getArray())
593 prev_image = numpy.zeros_like(image.getArray())
605 for iteration
in range(maxIter):
608 tmpArray = tempImage.getArray()
609 outArray = outImage.getArray()
611 with numpy.errstate(invalid=
"ignore", over=
"ignore"):
613 gradTmp = numpy.gradient(tmpArray[startY:endY, startX:endX])
614 gradOut = numpy.gradient(outArray[startY:endY, startX:endX])
615 first = (gradTmp[0]*gradOut[0] + gradTmp[1]*gradOut[1])[1:-1, 1:-1]
618 diffOut20 = numpy.diff(outArray, 2, 0)[startY:endY, startX + 1:endX - 1]
619 diffOut21 = numpy.diff(outArray, 2, 1)[startY + 1:endY - 1, startX:endX]
620 second = tmpArray[startY + 1:endY - 1, startX + 1:endX - 1]*(diffOut20 + diffOut21)
622 corr[startY + 1:endY - 1, startX + 1:endX - 1] = 0.5*(first + second)
624 tmpArray[:, :] = image.getArray()[:, :]
625 tmpArray[nanIndex] = 0.
626 tmpArray[startY:endY, startX:endX] += corr[startY:endY, startX:endX]
629 diff = numpy.sum(numpy.abs(prev_image - tmpArray))
633 prev_image[:, :] = tmpArray[:, :]
635 image.getArray()[startY + 1:endY - 1, startX + 1:endX - 1] += \
636 corr[startY + 1:endY - 1, startX + 1:endX - 1]
638 return diff, iteration
◆ createPsf()
def lsst.ip.isr.isrFunctions.createPsf |
( |
|
fwhm | ) |
|
Make a double Gaussian PSF.
Parameters
----------
fwhm : scalar
FWHM of double Gaussian smoothing kernel.
Returns
-------
psf : `lsst.meas.algorithms.DoubleGaussianPsf`
The created smoothing kernel.
Definition at line 40 of file isrFunctions.py.
41 """Make a double Gaussian PSF.
46 FWHM of double Gaussian smoothing kernel.
50 psf : `lsst.meas.algorithms.DoubleGaussianPsf`
51 The created smoothing kernel.
53 ksize = 4*int(fwhm) + 1
54 return measAlg.DoubleGaussianPsf(ksize, ksize, fwhm/(2*math.sqrt(2*math.log(2))))
◆ darkCorrection()
def lsst.ip.isr.isrFunctions.darkCorrection |
( |
|
maskedImage, |
|
|
|
darkMaskedImage, |
|
|
|
expScale, |
|
|
|
darkScale, |
|
|
|
invert = False , |
|
|
|
trimToFit = False |
|
) |
| |
Apply dark correction in place.
Parameters
----------
maskedImage : `lsst.afw.image.MaskedImage`
Image to process. The image is modified by this method.
darkMaskedImage : `lsst.afw.image.MaskedImage`
Dark image of the same size as ``maskedImage``.
expScale : scalar
Dark exposure time for ``maskedImage``.
darkScale : scalar
Dark exposure time for ``darkMaskedImage``.
invert : `Bool`, optional
If True, re-add the dark to an already corrected image.
trimToFit : `Bool`, optional
If True, raw data is symmetrically trimmed to match
calibration size.
Raises
------
RuntimeError
Raised if ``maskedImage`` and ``darkMaskedImage`` do not have
the same size.
Notes
-----
The dark correction is applied by calculating:
maskedImage -= dark * expScaling / darkScaling
Definition at line 299 of file isrFunctions.py.
299 def darkCorrection(maskedImage, darkMaskedImage, expScale, darkScale, invert=False, trimToFit=False):
300 """Apply dark correction in place.
304 maskedImage : `lsst.afw.image.MaskedImage`
305 Image to process. The image is modified by this method.
306 darkMaskedImage : `lsst.afw.image.MaskedImage`
307 Dark image of the same size as ``maskedImage``.
309 Dark exposure time for ``maskedImage``.
311 Dark exposure time for ``darkMaskedImage``.
312 invert : `Bool`, optional
313 If True, re-add the dark to an already corrected image.
314 trimToFit : `Bool`, optional
315 If True, raw data is symmetrically trimmed to match
321 Raised if ``maskedImage`` and ``darkMaskedImage`` do not have
326 The dark correction is applied by calculating:
327 maskedImage -= dark * expScaling / darkScaling
332 if maskedImage.getBBox(afwImage.LOCAL) != darkMaskedImage.getBBox(afwImage.LOCAL):
333 raise RuntimeError(
"maskedImage bbox %s != darkMaskedImage bbox %s" %
334 (maskedImage.getBBox(afwImage.LOCAL), darkMaskedImage.getBBox(afwImage.LOCAL)))
336 scale = expScale / darkScale
338 maskedImage.scaledMinus(scale, darkMaskedImage)
340 maskedImage.scaledPlus(scale, darkMaskedImage)
◆ flatCorrection()
def lsst.ip.isr.isrFunctions.flatCorrection |
( |
|
maskedImage, |
|
|
|
flatMaskedImage, |
|
|
|
scalingType, |
|
|
|
userScale = 1.0 , |
|
|
|
invert = False , |
|
|
|
trimToFit = False |
|
) |
| |
Apply flat correction in place.
Parameters
----------
maskedImage : `lsst.afw.image.MaskedImage`
Image to process. The image is modified.
flatMaskedImage : `lsst.afw.image.MaskedImage`
Flat image of the same size as ``maskedImage``
scalingType : str
Flat scale computation method. Allowed values are 'MEAN',
'MEDIAN', or 'USER'.
userScale : scalar, optional
Scale to use if ``scalingType``='USER'.
invert : `Bool`, optional
If True, unflatten an already flattened image.
trimToFit : `Bool`, optional
If True, raw data is symmetrically trimmed to match
calibration size.
Raises
------
RuntimeError
Raised if ``maskedImage`` and ``flatMaskedImage`` do not have
the same size or if ``scalingType`` is not an allowed value.
Definition at line 361 of file isrFunctions.py.
361 def flatCorrection(maskedImage, flatMaskedImage, scalingType, userScale=1.0, invert=False, trimToFit=False):
362 """Apply flat correction in place.
366 maskedImage : `lsst.afw.image.MaskedImage`
367 Image to process. The image is modified.
368 flatMaskedImage : `lsst.afw.image.MaskedImage`
369 Flat image of the same size as ``maskedImage``
371 Flat scale computation method. Allowed values are 'MEAN',
373 userScale : scalar, optional
374 Scale to use if ``scalingType``='USER'.
375 invert : `Bool`, optional
376 If True, unflatten an already flattened image.
377 trimToFit : `Bool`, optional
378 If True, raw data is symmetrically trimmed to match
384 Raised if ``maskedImage`` and ``flatMaskedImage`` do not have
385 the same size or if ``scalingType`` is not an allowed value.
390 if maskedImage.getBBox(afwImage.LOCAL) != flatMaskedImage.getBBox(afwImage.LOCAL):
391 raise RuntimeError(
"maskedImage bbox %s != flatMaskedImage bbox %s" %
392 (maskedImage.getBBox(afwImage.LOCAL), flatMaskedImage.getBBox(afwImage.LOCAL)))
397 if scalingType
in (
'MEAN',
'MEDIAN'):
400 elif scalingType ==
'USER':
401 flatScale = userScale
403 raise RuntimeError(
'%s : %s not implemented' % (
"flatCorrection", scalingType))
406 maskedImage.scaledDivides(1.0/flatScale, flatMaskedImage)
408 maskedImage.scaledMultiplies(1.0/flatScale, flatMaskedImage)
◆ gainContext()
def lsst.ip.isr.isrFunctions.gainContext |
( |
|
exp, |
|
|
|
image, |
|
|
|
apply, |
|
|
|
gains = None |
|
) |
| |
Context manager that applies and removes gain.
Parameters
----------
exp : `lsst.afw.image.Exposure`
Exposure to apply/remove gain.
image : `lsst.afw.image.Image`
Image to apply/remove gain.
apply : `Bool`
If True, apply and remove the amplifier gain.
gains : `dict` [`str`, `float`]
A dictionary, keyed by amplifier name, of the gains to use.
If gains is None, the nominal gains in the amplifier object are used.
Yields
------
exp : `lsst.afw.image.Exposure`
Exposure with the gain applied.
Definition at line 642 of file isrFunctions.py.
643 """Context manager that applies and removes gain.
647 exp : `lsst.afw.image.Exposure`
648 Exposure to apply/remove gain.
649 image : `lsst.afw.image.Image`
650 Image to apply/remove gain.
652 If True, apply and remove the amplifier gain.
653 gains : `dict` [`str`, `float`]
654 A dictionary, keyed by amplifier name, of the gains to use.
655 If gains is None, the nominal gains in the amplifier object are used.
659 exp : `lsst.afw.image.Exposure`
660 Exposure with the gain applied.
664 if gains
and apply
is True:
665 ampNames = [amp.getName()
for amp
in exp.getDetector()]
666 for ampName
in ampNames:
667 if ampName
not in gains.keys():
668 raise RuntimeError(f
"Gains provided to gain context, but no entry found for amp {ampName}")
671 ccd = exp.getDetector()
673 sim = image.Factory(image, amp.getBBox())
675 gain = gains[amp.getName()]
684 ccd = exp.getDetector()
686 sim = image.Factory(image, amp.getBBox())
688 gain = gains[amp.getName()]
◆ growMasks()
def lsst.ip.isr.isrFunctions.growMasks |
( |
|
mask, |
|
|
|
radius = 0 , |
|
|
|
maskNameList = ['BAD'] , |
|
|
|
maskValue = "BAD" |
|
) |
| |
Grow a mask by an amount and add to the requested plane.
Parameters
----------
mask : `lsst.afw.image.Mask`
Mask image to process.
radius : scalar
Amount to grow the mask.
maskNameList : `str` or `list` [`str`]
Mask names that should be grown.
maskValue : `str`
Mask plane to assign the newly masked pixels to.
Definition at line 136 of file isrFunctions.py.
136 def growMasks(mask, radius=0, maskNameList=['BAD'], maskValue="BAD"):
137 """Grow a mask by an amount and add to the requested plane.
141 mask : `lsst.afw.image.Mask`
142 Mask image to process.
144 Amount to grow the mask.
145 maskNameList : `str` or `list` [`str`]
146 Mask names that should be grown.
148 Mask plane to assign the newly masked pixels to.
151 thresh = afwDetection.Threshold(mask.getPlaneBitMask(maskNameList), afwDetection.Threshold.BITMASK)
152 fpSet = afwDetection.FootprintSet(mask, thresh)
153 fpSet = afwDetection.FootprintSet(fpSet, rGrow=radius, isotropic=
False)
154 fpSet.setMask(mask, maskValue)
◆ illuminationCorrection()
def lsst.ip.isr.isrFunctions.illuminationCorrection |
( |
|
maskedImage, |
|
|
|
illumMaskedImage, |
|
|
|
illumScale, |
|
|
|
trimToFit = True |
|
) |
| |
Apply illumination correction in place.
Parameters
----------
maskedImage : `lsst.afw.image.MaskedImage`
Image to process. The image is modified.
illumMaskedImage : `lsst.afw.image.MaskedImage`
Illumination correction image of the same size as ``maskedImage``.
illumScale : scalar
Scale factor for the illumination correction.
trimToFit : `Bool`, optional
If True, raw data is symmetrically trimmed to match
calibration size.
Raises
------
RuntimeError
Raised if ``maskedImage`` and ``illumMaskedImage`` do not have
the same size.
Definition at line 411 of file isrFunctions.py.
412 """Apply illumination correction in place.
416 maskedImage : `lsst.afw.image.MaskedImage`
417 Image to process. The image is modified.
418 illumMaskedImage : `lsst.afw.image.MaskedImage`
419 Illumination correction image of the same size as ``maskedImage``.
421 Scale factor for the illumination correction.
422 trimToFit : `Bool`, optional
423 If True, raw data is symmetrically trimmed to match
429 Raised if ``maskedImage`` and ``illumMaskedImage`` do not have
435 if maskedImage.getBBox(afwImage.LOCAL) != illumMaskedImage.getBBox(afwImage.LOCAL):
436 raise RuntimeError(
"maskedImage bbox %s != illumMaskedImage bbox %s" %
437 (maskedImage.getBBox(afwImage.LOCAL), illumMaskedImage.getBBox(afwImage.LOCAL)))
439 maskedImage.scaledDivides(1.0/illumScale, illumMaskedImage)
◆ interpolateDefectList()
def lsst.ip.isr.isrFunctions.interpolateDefectList |
( |
|
maskedImage, |
|
|
|
defectList, |
|
|
|
fwhm, |
|
|
|
fallbackValue = None |
|
) |
| |
Interpolate over defects specified in a defect list.
Parameters
----------
maskedImage : `lsst.afw.image.MaskedImage`
Image to process.
defectList : `lsst.meas.algorithms.Defects`
List of defects to interpolate over.
fwhm : scalar
FWHM of double Gaussian smoothing kernel.
fallbackValue : scalar, optional
Fallback value if an interpolated value cannot be determined.
If None, then the clipped mean of the image is used.
Definition at line 77 of file isrFunctions.py.
78 """Interpolate over defects specified in a defect list.
82 maskedImage : `lsst.afw.image.MaskedImage`
84 defectList : `lsst.meas.algorithms.Defects`
85 List of defects to interpolate over.
87 FWHM of double Gaussian smoothing kernel.
88 fallbackValue : scalar, optional
89 Fallback value if an interpolated value cannot be determined.
90 If None, then the clipped mean of the image is used.
93 if fallbackValue
is None:
95 if 'INTRP' not in maskedImage.getMask().getMaskPlaneDict():
96 maskedImage.getMask().addMaskPlane(
'INTRP')
97 measAlg.interpolateOverDefects(maskedImage, psf, defectList, fallbackValue,
True)
◆ interpolateFromMask()
def lsst.ip.isr.isrFunctions.interpolateFromMask |
( |
|
maskedImage, |
|
|
|
fwhm, |
|
|
|
growSaturatedFootprints = 1 , |
|
|
|
maskNameList = ['SAT'] , |
|
|
|
fallbackValue = None |
|
) |
| |
Interpolate over defects identified by a particular set of mask planes.
Parameters
----------
maskedImage : `lsst.afw.image.MaskedImage`
Image to process.
fwhm : scalar
FWHM of double Gaussian smoothing kernel.
growSaturatedFootprints : scalar, optional
Number of pixels to grow footprints for saturated pixels.
maskNameList : `List` of `str`, optional
Mask plane name.
fallbackValue : scalar, optional
Value of last resort for interpolation.
Definition at line 157 of file isrFunctions.py.
158 maskNameList=['SAT'], fallbackValue=None):
159 """Interpolate over defects identified by a particular set of mask planes.
163 maskedImage : `lsst.afw.image.MaskedImage`
166 FWHM of double Gaussian smoothing kernel.
167 growSaturatedFootprints : scalar, optional
168 Number of pixels to grow footprints for saturated pixels.
169 maskNameList : `List` of `str`, optional
171 fallbackValue : scalar, optional
172 Value of last resort for interpolation.
174 mask = maskedImage.getMask()
176 if growSaturatedFootprints > 0
and "SAT" in maskNameList:
179 growMasks(mask, radius=growSaturatedFootprints, maskNameList=[
'SAT'], maskValue=
"SAT")
181 thresh = afwDetection.Threshold(mask.getPlaneBitMask(maskNameList), afwDetection.Threshold.BITMASK)
182 fpSet = afwDetection.FootprintSet(mask, thresh)
183 defectList = Defects.fromFootprintList(fpSet.getFootprints())
◆ makeThresholdMask()
def lsst.ip.isr.isrFunctions.makeThresholdMask |
( |
|
maskedImage, |
|
|
|
threshold, |
|
|
|
growFootprints = 1 , |
|
|
|
maskName = 'SAT' |
|
) |
| |
Mask pixels based on threshold detection.
Parameters
----------
maskedImage : `lsst.afw.image.MaskedImage`
Image to process. Only the mask plane is updated.
threshold : scalar
Detection threshold.
growFootprints : scalar, optional
Number of pixels to grow footprints of detected regions.
maskName : str, optional
Mask plane name, or list of names to convert
Returns
-------
defectList : `lsst.meas.algorithms.Defects`
Defect list constructed from pixels above the threshold.
Definition at line 101 of file isrFunctions.py.
102 """Mask pixels based on threshold detection.
106 maskedImage : `lsst.afw.image.MaskedImage`
107 Image to process. Only the mask plane is updated.
110 growFootprints : scalar, optional
111 Number of pixels to grow footprints of detected regions.
112 maskName : str, optional
113 Mask plane name, or list of names to convert
117 defectList : `lsst.meas.algorithms.Defects`
118 Defect list constructed from pixels above the threshold.
121 thresh = afwDetection.Threshold(threshold)
122 fs = afwDetection.FootprintSet(maskedImage, thresh)
124 if growFootprints > 0:
125 fs = afwDetection.FootprintSet(fs, rGrow=growFootprints, isotropic=
False)
126 fpList = fs.getFootprints()
129 mask = maskedImage.getMask()
130 bitmask = mask.getPlaneBitMask(maskName)
131 afwDetection.setMaskFromFootprintList(mask, fpList, bitmask)
133 return Defects.fromFootprintList(fpList)
◆ overscanCorrection()
def lsst.ip.isr.isrFunctions.overscanCorrection |
( |
|
ampMaskedImage, |
|
|
|
overscanImage, |
|
|
|
fitType = 'MEDIAN' , |
|
|
|
order = 1 , |
|
|
|
collapseRej = 3.0 , |
|
|
|
statControl = None , |
|
|
|
overscanIsInt = True |
|
) |
| |
Apply overscan correction in place.
Parameters
----------
ampMaskedImage : `lsst.afw.image.MaskedImage`
Image of amplifier to correct; modified.
overscanImage : `lsst.afw.image.Image` or `lsst.afw.image.MaskedImage`
Image of overscan; modified.
fitType : `str`
Type of fit for overscan correction. May be one of:
- ``MEAN``: use mean of overscan.
- ``MEANCLIP``: use clipped mean of overscan.
- ``MEDIAN``: use median of overscan.
- ``MEDIAN_PER_ROW``: use median per row of overscan.
- ``POLY``: fit with ordinary polynomial.
- ``CHEB``: fit with Chebyshev polynomial.
- ``LEG``: fit with Legendre polynomial.
- ``NATURAL_SPLINE``: fit with natural spline.
- ``CUBIC_SPLINE``: fit with cubic spline.
- ``AKIMA_SPLINE``: fit with Akima spline.
order : `int`
Polynomial order or number of spline knots; ignored unless
``fitType`` indicates a polynomial or spline.
statControl : `lsst.afw.math.StatisticsControl`
Statistics control object. In particular, we pay attention to numSigmaClip
overscanIsInt : `bool`
Treat the overscan region as consisting of integers, even if it's been
converted to float. E.g. handle ties properly.
Returns
-------
result : `lsst.pipe.base.Struct`
Result struct with components:
- ``imageFit``: Value(s) removed from image (scalar or
`lsst.afw.image.Image`)
- ``overscanFit``: Value(s) removed from overscan (scalar or
`lsst.afw.image.Image`)
- ``overscanImage``: Overscan corrected overscan region
(`lsst.afw.image.Image`)
Raises
------
RuntimeError
Raised if ``fitType`` is not an allowed value.
Notes
-----
The ``ampMaskedImage`` and ``overscanImage`` are modified, with the fit
subtracted. Note that the ``overscanImage`` should not be a subimage of
the ``ampMaskedImage``, to avoid being subtracted twice.
Debug plots are available for the SPLINE fitTypes by setting the
`debug.display` for `name` == "lsst.ip.isr.isrFunctions". These
plots show the scatter plot of the overscan data (collapsed along
the perpendicular dimension) as a function of position on the CCD
(normalized between +/-1).
Definition at line 442 of file isrFunctions.py.
442 def overscanCorrection(ampMaskedImage, overscanImage, fitType='MEDIAN', order=1, collapseRej=3.0,
443 statControl=None, overscanIsInt=True):
444 """Apply overscan correction in place.
448 ampMaskedImage : `lsst.afw.image.MaskedImage`
449 Image of amplifier to correct; modified.
450 overscanImage : `lsst.afw.image.Image` or `lsst.afw.image.MaskedImage`
451 Image of overscan; modified.
453 Type of fit for overscan correction. May be one of:
455 - ``MEAN``: use mean of overscan.
456 - ``MEANCLIP``: use clipped mean of overscan.
457 - ``MEDIAN``: use median of overscan.
458 - ``MEDIAN_PER_ROW``: use median per row of overscan.
459 - ``POLY``: fit with ordinary polynomial.
460 - ``CHEB``: fit with Chebyshev polynomial.
461 - ``LEG``: fit with Legendre polynomial.
462 - ``NATURAL_SPLINE``: fit with natural spline.
463 - ``CUBIC_SPLINE``: fit with cubic spline.
464 - ``AKIMA_SPLINE``: fit with Akima spline.
467 Polynomial order or number of spline knots; ignored unless
468 ``fitType`` indicates a polynomial or spline.
469 statControl : `lsst.afw.math.StatisticsControl`
470 Statistics control object. In particular, we pay attention to numSigmaClip
471 overscanIsInt : `bool`
472 Treat the overscan region as consisting of integers, even if it's been
473 converted to float. E.g. handle ties properly.
477 result : `lsst.pipe.base.Struct`
478 Result struct with components:
480 - ``imageFit``: Value(s) removed from image (scalar or
481 `lsst.afw.image.Image`)
482 - ``overscanFit``: Value(s) removed from overscan (scalar or
483 `lsst.afw.image.Image`)
484 - ``overscanImage``: Overscan corrected overscan region
485 (`lsst.afw.image.Image`)
489 Raised if ``fitType`` is not an allowed value.
493 The ``ampMaskedImage`` and ``overscanImage`` are modified, with the fit
494 subtracted. Note that the ``overscanImage`` should not be a subimage of
495 the ``ampMaskedImage``, to avoid being subtracted twice.
497 Debug plots are available for the SPLINE fitTypes by setting the
498 `debug.display` for `name` == "lsst.ip.isr.isrFunctions". These
499 plots show the scatter plot of the overscan data (collapsed along
500 the perpendicular dimension) as a function of position on the CCD
501 (normalized between +/-1).
503 ampImage = ampMaskedImage.getImage()
505 config = OverscanCorrectionTaskConfig()
507 config.fitType = fitType
511 config.numSigmaClip = collapseRej
513 config.overscanIsInt =
True
515 overscanTask = OverscanCorrectionTask(config=config)
516 return overscanTask.run(ampImage, overscanImage)
◆ saturationCorrection()
def lsst.ip.isr.isrFunctions.saturationCorrection |
( |
|
maskedImage, |
|
|
|
saturation, |
|
|
|
fwhm, |
|
|
|
growFootprints = 1 , |
|
|
|
interpolate = True , |
|
|
|
maskName = 'SAT' , |
|
|
|
fallbackValue = None |
|
) |
| |
Mark saturated pixels and optionally interpolate over them
Parameters
----------
maskedImage : `lsst.afw.image.MaskedImage`
Image to process.
saturation : scalar
Saturation level used as the detection threshold.
fwhm : scalar
FWHM of double Gaussian smoothing kernel.
growFootprints : scalar, optional
Number of pixels to grow footprints of detected regions.
interpolate : Bool, optional
If True, saturated pixels are interpolated over.
maskName : str, optional
Mask plane name.
fallbackValue : scalar, optional
Value of last resort for interpolation.
Definition at line 190 of file isrFunctions.py.
190 def saturationCorrection(maskedImage, saturation, fwhm, growFootprints=1, interpolate=True, maskName='SAT',
192 """Mark saturated pixels and optionally interpolate over them
196 maskedImage : `lsst.afw.image.MaskedImage`
199 Saturation level used as the detection threshold.
201 FWHM of double Gaussian smoothing kernel.
202 growFootprints : scalar, optional
203 Number of pixels to grow footprints of detected regions.
204 interpolate : Bool, optional
205 If True, saturated pixels are interpolated over.
206 maskName : str, optional
208 fallbackValue : scalar, optional
209 Value of last resort for interpolation.
212 maskedImage=maskedImage,
213 threshold=saturation,
214 growFootprints=growFootprints,
◆ setBadRegions()
def lsst.ip.isr.isrFunctions.setBadRegions |
( |
|
exposure, |
|
|
|
badStatistic = "MEDIAN" |
|
) |
| |
Set all BAD areas of the chip to the average of the rest of the exposure
Parameters
----------
exposure : `lsst.afw.image.Exposure`
Exposure to mask. The exposure mask is modified.
badStatistic : `str`, optional
Statistic to use to generate the replacement value from the
image data. Allowed values are 'MEDIAN' or 'MEANCLIP'.
Returns
-------
badPixelCount : scalar
Number of bad pixels masked.
badPixelValue : scalar
Value substituted for bad pixels.
Raises
------
RuntimeError
Raised if `badStatistic` is not an allowed value.
Definition at line 823 of file isrFunctions.py.
824 """Set all BAD areas of the chip to the average of the rest of the exposure
828 exposure : `lsst.afw.image.Exposure`
829 Exposure to mask. The exposure mask is modified.
830 badStatistic : `str`, optional
831 Statistic to use to generate the replacement value from the
832 image data. Allowed values are 'MEDIAN' or 'MEANCLIP'.
836 badPixelCount : scalar
837 Number of bad pixels masked.
838 badPixelValue : scalar
839 Value substituted for bad pixels.
844 Raised if `badStatistic` is not an allowed value.
846 if badStatistic ==
"MEDIAN":
847 statistic = afwMath.MEDIAN
848 elif badStatistic ==
"MEANCLIP":
849 statistic = afwMath.MEANCLIP
851 raise RuntimeError(
"Impossible method %s of bad region correction" % badStatistic)
853 mi = exposure.getMaskedImage()
855 BAD = mask.getPlaneBitMask(
"BAD")
856 INTRP = mask.getPlaneBitMask(
"INTRP")
859 sctrl.setAndMask(BAD)
862 maskArray = mask.getArray()
863 imageArray = mi.getImage().getArray()
864 badPixels = numpy.logical_and((maskArray & BAD) > 0, (maskArray & INTRP) == 0)
865 imageArray[:] = numpy.where(badPixels, value, imageArray)
867 return badPixels.sum(), value
◆ transposeMaskedImage()
def lsst.ip.isr.isrFunctions.transposeMaskedImage |
( |
|
maskedImage | ) |
|
Make a transposed copy of a masked image.
Parameters
----------
maskedImage : `lsst.afw.image.MaskedImage`
Image to process.
Returns
-------
transposed : `lsst.afw.image.MaskedImage`
The transposed copy of the input image.
Definition at line 57 of file isrFunctions.py.
58 """Make a transposed copy of a masked image.
62 maskedImage : `lsst.afw.image.MaskedImage`
67 transposed : `lsst.afw.image.MaskedImage`
68 The transposed copy of the input image.
70 transposed = maskedImage.Factory(
lsst.geom.Extent2I(maskedImage.getHeight(), maskedImage.getWidth()))
71 transposed.getImage().getArray()[:] = maskedImage.getImage().getArray().T
72 transposed.getMask().getArray()[:] = maskedImage.getMask().getArray().T
73 transposed.getVariance().getArray()[:] = maskedImage.getVariance().getArray().T
◆ trimToMatchCalibBBox()
def lsst.ip.isr.isrFunctions.trimToMatchCalibBBox |
( |
|
rawMaskedImage, |
|
|
|
calibMaskedImage |
|
) |
| |
Compute number of edge trim pixels to match the calibration data.
Use the dimension difference between the raw exposure and the
calibration exposure to compute the edge trim pixels. This trim
is applied symmetrically, with the same number of pixels masked on
each side.
Parameters
----------
rawMaskedImage : `lsst.afw.image.MaskedImage`
Image to trim.
calibMaskedImage : `lsst.afw.image.MaskedImage`
Calibration image to draw new bounding box from.
Returns
-------
replacementMaskedImage : `lsst.afw.image.MaskedImage`
``rawMaskedImage`` trimmed to the appropriate size
Raises
------
RuntimeError
Rasied if ``rawMaskedImage`` cannot be symmetrically trimmed to
match ``calibMaskedImage``.
Definition at line 223 of file isrFunctions.py.
224 """Compute number of edge trim pixels to match the calibration data.
226 Use the dimension difference between the raw exposure and the
227 calibration exposure to compute the edge trim pixels. This trim
228 is applied symmetrically, with the same number of pixels masked on
233 rawMaskedImage : `lsst.afw.image.MaskedImage`
235 calibMaskedImage : `lsst.afw.image.MaskedImage`
236 Calibration image to draw new bounding box from.
240 replacementMaskedImage : `lsst.afw.image.MaskedImage`
241 ``rawMaskedImage`` trimmed to the appropriate size
245 Rasied if ``rawMaskedImage`` cannot be symmetrically trimmed to
246 match ``calibMaskedImage``.
248 nx, ny = rawMaskedImage.getBBox().getDimensions() - calibMaskedImage.getBBox().getDimensions()
250 raise RuntimeError(
"Raw and calib maskedImages are trimmed differently in X and Y.")
252 raise RuntimeError(
"Calibration maskedImage is trimmed unevenly in X.")
254 raise RuntimeError(
"Calibration maskedImage is larger than raw data.")
258 replacementMaskedImage = rawMaskedImage[nEdge:-nEdge, nEdge:-nEdge, afwImage.LOCAL]
259 SourceDetectionTask.setEdgeBits(
261 replacementMaskedImage.getBBox(),
262 rawMaskedImage.getMask().getPlaneBitMask(
"EDGE")
265 replacementMaskedImage = rawMaskedImage
267 return replacementMaskedImage
◆ updateVariance()
def lsst.ip.isr.isrFunctions.updateVariance |
( |
|
maskedImage, |
|
|
|
gain, |
|
|
|
readNoise |
|
) |
| |
Set the variance plane based on the image plane.
Parameters
----------
maskedImage : `lsst.afw.image.MaskedImage`
Image to process. The variance plane is modified.
gain : scalar
The amplifier gain in electrons/ADU.
readNoise : scalar
The amplifier read nmoise in ADU/pixel.
Definition at line 343 of file isrFunctions.py.
344 """Set the variance plane based on the image plane.
348 maskedImage : `lsst.afw.image.MaskedImage`
349 Image to process. The variance plane is modified.
351 The amplifier gain in electrons/ADU.
353 The amplifier read nmoise in ADU/pixel.
355 var = maskedImage.getVariance()
356 var[:] = maskedImage.getImage()
◆ widenSaturationTrails()
def lsst.ip.isr.isrFunctions.widenSaturationTrails |
( |
|
mask | ) |
|
Grow the saturation trails by an amount dependent on the width of the trail.
Parameters
----------
mask : `lsst.afw.image.Mask`
Mask which will have the saturated areas grown.
Definition at line 776 of file isrFunctions.py.
777 """Grow the saturation trails by an amount dependent on the width of the trail.
781 mask : `lsst.afw.image.Mask`
782 Mask which will have the saturated areas grown.
786 for i
in range(1, 6):
788 for i
in range(6, 8):
790 for i
in range(8, 10):
794 if extraGrowMax <= 0:
797 saturatedBit = mask.getPlaneBitMask(
"SAT")
799 xmin, ymin = mask.getBBox().getMin()
800 width = mask.getWidth()
802 thresh = afwDetection.Threshold(saturatedBit, afwDetection.Threshold.BITMASK)
803 fpList = afwDetection.FootprintSet(mask, thresh).getFootprints()
806 for s
in fp.getSpans():
807 x0, x1 = s.getX0(), s.getX1()
809 extraGrow = extraGrowDict.get(x1 - x0 + 1, extraGrowMax)
812 x0 -= xmin + extraGrow
813 x1 -= xmin - extraGrow
820 mask.array[y, x0:x1+1] |= saturatedBit
def interpolateDefectList(maskedImage, defectList, fwhm, fallbackValue=None)
def applyGains(exposure, normalizeGains=False)
def illuminationCorrection(maskedImage, illumMaskedImage, illumScale, trimToFit=True)
def interpolateFromMask(maskedImage, fwhm, growSaturatedFootprints=1, maskNameList=['SAT'], fallbackValue=None)
def saturationCorrection(maskedImage, saturation, fwhm, growFootprints=1, interpolate=True, maskName='SAT', fallbackValue=None)
def gainContext(exp, image, apply, gains=None)
def transposeMaskedImage(maskedImage)
A kernel created from an Image.
Statistics makeStatistics(lsst::afw::math::MaskedVector< EntryT > const &mv, std::vector< WeightPixel > const &vweights, int const flags, StatisticsControl const &sctrl=StatisticsControl())
The makeStatistics() overload to handle lsst::afw::math::MaskedVector<>
Property stringToStatisticsProperty(std::string const property)
Conversion function to switch a string to a Property (see Statistics.h)
def flatCorrection(maskedImage, flatMaskedImage, scalingType, userScale=1.0, invert=False, trimToFit=False)
def darkCorrection(maskedImage, darkMaskedImage, expScale, darkScale, invert=False, trimToFit=False)
def overscanCorrection(ampMaskedImage, overscanImage, fitType='MEDIAN', order=1, collapseRej=3.0, statControl=None, overscanIsInt=True)
def brighterFatterCorrection(exposure, kernel, maxIter, threshold, applyGain, gains=None)
def setBadRegions(exposure, badStatistic="MEDIAN")
def growMasks(mask, radius=0, maskNameList=['BAD'], maskValue="BAD")
def trimToMatchCalibBBox(rawMaskedImage, calibMaskedImage)
def updateVariance(maskedImage, gain, readNoise)
Pass parameters to a Statistics object.
Parameters to control convolution.
def attachTransmissionCurve(exposure, opticsTransmission=None, filterTransmission=None, sensorTransmission=None, atmosphereTransmission=None)
void convolve(OutImageT &convolvedImage, InImageT const &inImage, KernelT const &kernel, bool doNormalize, bool doCopyEdge)
def biasCorrection(maskedImage, biasMaskedImage, trimToFit=False)
def makeThresholdMask(maskedImage, threshold, growFootprints=1, maskName='SAT')
def widenSaturationTrails(mask)