Esempio n. 1
0
    def testSaturation(self):
        saturation = 1000

        bbox = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Point2I(19, 19))
        maskedImage = afwImage.MaskedImageF(bbox)
        maskedImage.set(100, 0x0, 1)
        exposure = afwImage.ExposureF(maskedImage, None)

        bbox = afwGeom.Box2I(afwGeom.Point2I(9, 5), afwGeom.Point2I(9, 15))
        submi = afwImage.MaskedImageF(maskedImage, bbox, afwImage.PARENT,
                                      False)
        submi.set(saturation, 0x0, 1)

        ipIsr.makeThresholdMask(
            maskedImage=maskedImage,
            threshold=saturation,
            growFootprints=0,
            maskName='SAT',
        )
        ipIsr.interpolateFromMask(
            maskedImage=maskedImage,
            fwhm=5.0,
            growFootprints=1,
            maskName='SAT',
        )

        mask = maskedImage.getMask()
        bitmaskBad = mask.getPlaneBitMask('BAD')
        bitmaskSat = mask.getPlaneBitMask('SAT')
        bitmaskInterp = mask.getPlaneBitMask('INTRP')
        height = maskedImage.getHeight()
        width = maskedImage.getWidth()

        for j in range(height):
            for i in range(width):
                # Grown saturation mask; one around the mask at 9
                if i >= 8 and i <= 10:
                    if (i, j) in [(8, 4), (8, 16), (10, 4), (10, 16)]:
                        #Should not be saturated or interpolated at all
                        self.assertEqual(mask.get(i, j) & bitmaskInterp, 0)
                        self.assertEqual(mask.get(i, j) & bitmaskSat, 0)
                    elif (j > 4 and j < 16) and (i == 8 or i == 10):
                        # Not saturated but interpolated over
                        self.assertEqual(
                            mask.get(i, j) & bitmaskInterp, bitmaskInterp)
                    elif (j == 4 or j == 16):
                        # Interpolated over; bottom/top
                        self.assertEqual(
                            mask.get(i, j) & bitmaskInterp, bitmaskInterp)
                    elif (j > 4 and j < 16 and i == 9):
                        # Both saturated and interpolated over; guts of it
                        self.assertEqual(
                            mask.get(i, j) & bitmaskInterp, bitmaskInterp)
                        self.assertEqual(
                            mask.get(i, j) & bitmaskSat, bitmaskSat)
                    else:
                        # Neither; above or below the mask
                        self.assertEqual(mask.get(i, j), 0)
                else:
                    self.assertEqual(mask.get(i, j), 0)
Esempio n. 2
0
    def testSaturation(self):
        """Test saturation threshold masking and interpolation.

        The test image used here is a simulated 20x20 square with a
        10-pixel long defect in the y-direction.
        """
        saturation = 1000

        bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Point2I(19, 19))
        maskedImage = afwImage.MaskedImageF(bbox)
        maskedImage.set(100, 0x0, 1)

        bbox = lsst.geom.Box2I(lsst.geom.Point2I(9, 5),
                               lsst.geom.Point2I(9, 15))
        submi = afwImage.MaskedImageF(maskedImage, bbox, afwImage.PARENT, False)
        submi.set(saturation, 0x0, 1)

        ipIsr.makeThresholdMask(
            maskedImage=maskedImage,
            threshold=saturation,
            growFootprints=0,
            maskName='SAT',
        )
        ipIsr.interpolateFromMask(
            maskedImage=maskedImage,
            fwhm=5.0,
            growSaturatedFootprints=1,
            maskNameList=['SAT'],
        )

        mask = maskedImage.getMask()
        bitmaskSat = mask.getPlaneBitMask('SAT')
        bitmaskInterp = mask.getPlaneBitMask('INTRP')
        height = maskedImage.getHeight()
        width = maskedImage.getWidth()

        for j in range(height):
            for i in range(width):
                # Grown saturation mask; one around the mask at 9
                if i >= 8 and i <= 10:
                    if (i, j) in [(8, 4), (8, 16), (10, 4), (10, 16)]:
                        # Should not be saturated or interpolated at all
                        self.assertEqual(mask[i, j, afwImage.LOCAL] & bitmaskInterp, 0)
                        self.assertEqual(mask[i, j, afwImage.LOCAL] & bitmaskSat, 0)
                    elif (j > 4 and j < 16) and (i == 8 or i == 10):
                        # Not saturated but interpolated over
                        self.assertEqual(mask[i, j, afwImage.LOCAL] & bitmaskInterp, bitmaskInterp)
                    elif (j == 4 or j == 16):
                        # Interpolated over; bottom/top
                        self.assertEqual(mask[i, j, afwImage.LOCAL] & bitmaskInterp, bitmaskInterp)
                    elif (j > 4 and j < 16 and i == 9):
                        # Both saturated and interpolated over; guts of it
                        self.assertEqual(mask[i, j, afwImage.LOCAL] & bitmaskInterp, bitmaskInterp)
                        self.assertEqual(mask[i, j, afwImage.LOCAL] & bitmaskSat, bitmaskSat)
                    else:
                        # Neither; above or below the mask
                        self.assertEqual(mask[i, j, afwImage.LOCAL], 0)
                else:
                    self.assertEqual(mask[i, j, afwImage.LOCAL], 0)
    def testSaturation(self):
        saturation = 1000

        bbox = afwGeom.Box2I(afwGeom.Point2I(0,0), afwGeom.Point2I(19,19))
        maskedImage       = afwImage.MaskedImageF(bbox)
        maskedImage.set(100, 0x0, 1)
        exposure = afwImage.ExposureF(maskedImage, None)
        
        bbox     = afwGeom.Box2I(afwGeom.Point2I(9,5),
                                 afwGeom.Point2I(9,15))
        submi    = afwImage.MaskedImageF(maskedImage, bbox, afwImage.PARENT, False)
        submi.set(saturation, 0x0, 1)
        
        ipIsr.makeThresholdMask(
            maskedImage = maskedImage,
            threshold = saturation,
            growFootprints = 0,
            maskName = 'SAT',
        )
        ipIsr.interpolateFromMask(
            maskedImage = maskedImage,
            fwhm = 5.0,
            growFootprints = 1,
            maskName = 'SAT',
        )

        mask = maskedImage.getMask()
        bitmaskBad    = mask.getPlaneBitMask('BAD')
        bitmaskSat    = mask.getPlaneBitMask('SAT')
        bitmaskInterp = mask.getPlaneBitMask('INTRP')
        height        = maskedImage.getHeight()
        width         = maskedImage.getWidth()

        for j in range(height):
            for i in range(width):
                # Grown saturation mask; one around the mask at 9
                if i >= 8 and i <= 10:
                    if (i,j) in [(8,4),(8,16),(10,4),(10,16)]:
                        #Should not be saturated or interpolated at all
                        self.assertEqual(mask.get(i,j) & bitmaskInterp, 0)
                        self.assertEqual(mask.get(i,j) & bitmaskSat, 0)
                    elif (j >4 and j < 16) and (i == 8 or i == 10):
                        # Not saturated but interpolated over
                        self.assertEqual(mask.get(i,j) & bitmaskInterp, bitmaskInterp)
                    elif (j == 4 or j == 16):
                        # Interpolated over; bottom/top
                        self.assertEqual(mask.get(i,j) & bitmaskInterp, bitmaskInterp)
                    elif (j > 4 and j < 16 and i == 9):
                        # Both saturated and interpolated over; guts of it
                        self.assertEqual(mask.get(i,j) & bitmaskInterp, bitmaskInterp)
                        self.assertEqual(mask.get(i,j) & bitmaskSat,    bitmaskSat)
                    else:
                        # Neither; above or below the mask
                        self.assertEqual(mask.get(i,j), 0)
                else:
                    self.assertEqual(mask.get(i,j), 0)
Esempio n. 4
0
 def test_interpolateFromMask(self):
     """Expect number of interpolated pixels to be non-zero.
     """
     ipIsr.makeThresholdMask(self.mi, 200, growFootprints=2,
                             maskName='SAT')
     for growFootprints in range(0, 3):
         interpMaskedImage = ipIsr.interpolateFromMask(self.mi, 2.0,
                                                       growSaturatedFootprints=growFootprints,
                                                       maskNameList=['SAT'])
         numBit = countMaskedPixels(interpMaskedImage, "INTRP")
         self.assertEqual(numBit, 40800, msg=f"interpolateFromMask with growFootprints={growFootprints}")
Esempio n. 5
0
    def runDataRef(self, sensorRef):
        r"""Load the post instrument signature removal image

        \param[in]  sensorRef        sensor-level butler data reference

        \return     postIsrExposure  exposure to be passed to processCcdExposure
        """
        inputExposure = sensorRef.get("eimage", immediate=True)

        # eimages are int, but computation needs to be done on floating point values
        inputExposure = inputExposure.convertF()

        if self.config.doAddNoise:
            self.addNoise(inputExposure)

        if self.config.doSetVariance:
            self.setVariance(inputExposure)

        if self.config.maskEdgeBorder > 0:
            self.maskEdges(inputExposure)

        # eimages are transposed relative to the read direction.
        # Transpose the image to do interpolation in the serial direction
        mi = inputExposure.getMaskedImage()
        mi = isr.transposeMaskedImage(mi)

        # We may need to ingest the results of the processing and
        # ingestProcessed.py expects some specific header cards.
        # Set the header cards to values appropriate for an image
        # that has not been read out.
        md = inputExposure.getMetadata()
        md.add('RDNOISE', 0.)
        md.add('SATURATE', self.config.sat_val)
        md.add('GAINEFF', 1.)
        # Mask saturation
        isr.makeThresholdMask(
            maskedImage=mi,
            threshold=self.config.sat_val,
            growFootprints=0,
            maskName='SAT')
        # Interpolate
        isr.interpolateFromMask(
            maskedImage=mi,
            fwhm=self.config.interp_size,
            growFootprints=0,
            maskName='SAT',
        )
        inputExposure.setMaskedImage(isr.transposeMaskedImage(mi))
        return pipeBase.Struct(exposure=inputExposure)
Esempio n. 6
0
    def runDataRef(self, sensorRef):
        """Load the post instrument signature removal image

        \param[in]  sensorRef        sensor-level butler data reference

        \return     postIsrExposure  exposure to be passed to processCcdExposure
        """
        inputExposure = sensorRef.get("eimage", immediate=True)

        # eimages are int, but computation needs to be done on floating point values
        inputExposure = inputExposure.convertF()

        if self.config.doAddNoise:
            self.addNoise(inputExposure)

        if self.config.doSetVariance:
            self.setVariance(inputExposure)

        if self.config.maskEdgeBorder > 0:
            self.maskEdges(inputExposure)

        # eimages are transposed relative to the read direction.
        # Transpose the image to do interpolation in the serial direction
        mi = inputExposure.getMaskedImage()
        mi = isr.transposeMaskedImage(mi)

        # We may need to ingest the results of the processing and
        # ingestProcessed.py expects some specific header cards.
        # Set the header cards to values appropriate for an image
        # that has not been read out.
        md = inputExposure.getMetadata()
        md.add('RDNOISE', 0.)
        md.add('SATURATE', self.config.sat_val)
        md.add('GAINEFF', 1.)
        # Mask saturation
        isr.makeThresholdMask(
            maskedImage=mi,
            threshold=self.config.sat_val,
            growFootprints=0,
            maskName='SAT')
        # Interpolate
        isr.interpolateFromMask(
            maskedImage=mi,
            fwhm=self.config.interp_size,
            growFootprints=self.config.growSaturationFootprintSize,
            maskName='SAT',
        )
        inputExposure.setMaskedImage(isr.transposeMaskedImage(mi))
        return pipeBase.Struct(exposure=inputExposure)
 def test_interpolateFromMask(self):
     """Expect number of interpolated pixels to be non-zero.
     """
     ipIsr.makeThresholdMask(self.mi, 200, growFootprints=2, maskName='SAT')
     for growFootprints in range(0, 3):
         interpMaskedImage = ipIsr.interpolateFromMask(
             self.mi,
             2.0,
             growSaturatedFootprints=growFootprints,
             maskNameList=['SAT'])
         numBit = countMaskedPixels(interpMaskedImage, "INTRP")
         self.assertEqual(
             numBit,
             40800,
             msg=f"interpolateFromMask with growFootprints={growFootprints}"
         )
Esempio n. 8
0
    def test_makeThresholdMask(self):
        """Expect list of defects to have elements.
        """
        defectList = ipIsr.makeThresholdMask(self.mi, 200,
                                             growFootprints=2,
                                             maskName='SAT')

        self.assertEqual(len(defectList), 1)
    def test_makeThresholdMask(self):
        """Expect list of defects to have elements.
        """
        defectList = ipIsr.makeThresholdMask(self.mi,
                                             200,
                                             growFootprints=2,
                                             maskName='SAT')

        self.assertEqual(len(defectList), 1)
Esempio n. 10
0
    def testSaturation(self):
        """Test saturation threshold masking and interpolation.

        The test image used here is a simulated 20x20 square with a
        10-pixel long defect in the y-direction.
        """
        saturation = 1000

        bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0),
                               lsst.geom.Point2I(19, 19))
        maskedImage = afwImage.MaskedImageF(bbox)
        maskedImage.set(100, 0x0, 1)

        bbox = lsst.geom.Box2I(lsst.geom.Point2I(9, 5),
                               lsst.geom.Point2I(9, 15))
        submi = afwImage.MaskedImageF(maskedImage, bbox, afwImage.PARENT,
                                      False)
        submi.set(saturation, 0x0, 1)

        ipIsr.makeThresholdMask(
            maskedImage=maskedImage,
            threshold=saturation,
            growFootprints=0,
            maskName='SAT',
        )
        ipIsr.interpolateFromMask(
            maskedImage=maskedImage,
            fwhm=5.0,
            growSaturatedFootprints=1,
            maskNameList=['SAT'],
        )

        mask = maskedImage.getMask()
        bitmaskSat = mask.getPlaneBitMask('SAT')
        bitmaskInterp = mask.getPlaneBitMask('INTRP')
        height = maskedImage.getHeight()
        width = maskedImage.getWidth()

        for j in range(height):
            for i in range(width):
                # Grown saturation mask; one around the mask at 9
                if i >= 8 and i <= 10:
                    if (i, j) in [(8, 4), (8, 16), (10, 4), (10, 16)]:
                        # Should not be saturated or interpolated at all
                        self.assertEqual(
                            mask[i, j, afwImage.LOCAL] & bitmaskInterp, 0)
                        self.assertEqual(
                            mask[i, j, afwImage.LOCAL] & bitmaskSat, 0)
                    elif (j > 4 and j < 16) and (i == 8 or i == 10):
                        # Not saturated but interpolated over
                        self.assertEqual(
                            mask[i, j, afwImage.LOCAL] & bitmaskInterp,
                            bitmaskInterp)
                    elif (j == 4 or j == 16):
                        # Interpolated over; bottom/top
                        self.assertEqual(
                            mask[i, j, afwImage.LOCAL] & bitmaskInterp,
                            bitmaskInterp)
                    elif (j > 4 and j < 16 and i == 9):
                        # Both saturated and interpolated over; guts of it
                        self.assertEqual(
                            mask[i, j, afwImage.LOCAL] & bitmaskInterp,
                            bitmaskInterp)
                        self.assertEqual(
                            mask[i, j, afwImage.LOCAL] & bitmaskSat,
                            bitmaskSat)
                    else:
                        # Neither; above or below the mask
                        self.assertEqual(mask[i, j, afwImage.LOCAL], 0)
                else:
                    self.assertEqual(mask[i, j, afwImage.LOCAL], 0)