def flatCorrection(self, exposure, flatExposure): """Apply flat correction in place DECam flat products have been trimmed and are smaller than the raw exposure. The size of edge trim is computed based on the dimensions of the input data. Only process the inner part of the raw exposure, and mask the outer pixels as EDGE. @param[in,out] exposure: exposure to process @param[in] flatExposure: flatfield exposure """ nEdge = _computeEdgeSize(exposure, flatExposure) if nEdge > 0: rawMaskedImage = exposure.getMaskedImage()[nEdge:-nEdge, nEdge:-nEdge] else: rawMaskedImage = exposure.getMaskedImage() flatCorrection( rawMaskedImage, flatExposure.getMaskedImage(), self.config.flatScalingType, self.config.flatUserScale ) # Mask the unprocessed edge pixels as EDGE SourceDetectionTask.setEdgeBits( exposure.getMaskedImage(), rawMaskedImage.getBBox(), exposure.getMaskedImage().getMask().getPlaneBitMask("EDGE"), )
def test_flatCorrectionUnknown(self): """Raise if an unknown scaling is used. The `scaling` parameter must be a known type. If not, the flat correction will raise a RuntimeError. """ flatExp = isrMock.FlatMock().run() flatMi = flatExp.getMaskedImage() with self.assertRaises(RuntimeError): ipIsr.flatCorrection(self.mi, flatMi, "UNKNOWN", userScale=1.0, trimToFit=True)
def doFlat(self, scaling): maskedImage = afwImage.MaskedImageF(afwGeom.Box2I(self.pmin, self.pmax)) maskedImage.getImage().set(10) flat = afwImage.MaskedImageF(afwGeom.Box2I(self.pmin, self.pmax)) flat.getImage().set(1) flatexposure = afwImage.ExposureF(flat, None) dmetadata = flatexposure.getMetadata() dmetadata.setString(self.filenameKeyword, 'Unittest Flat') ipIsr.flatCorrection(maskedImage, flatexposure.getMaskedImage(), 'USER', scaling) height = maskedImage.getHeight() width = maskedImage.getWidth() for j in range(height): for i in range(width): self.assertAlmostEqual(maskedImage.image[i, j, afwImage.LOCAL], 10 / (1./scaling), 5)
def process(self, clipboard): """ """ self.log.log(Log.INFO, "Doing Flat correction.") #grab exposure from clipboard exposure = clipboard.get(self.policy.getString("inputKeys.exposure")) flatexposure = clipboard.get(self.policy.getString("inputKeys.flatexposure")) scalingtype = self.policy.getString("parameters.flatScalingType") if scalingtype == "USER": scalingvalue = self.policy.getDouble("parameters.flatScalingValue") ipIsr.flatCorrection(exposure, flatexposure, "USER", scalingvalue) else: ipIsr.flatCorrection(exposure, flatexposure, scalingtype) #output products clipboard.put(self.policy.get("outputKeys.flatCorrectedExposure"), exposure)
def doFlat(self, scaling): maskedImage = afwImage.MaskedImageF( lsst.geom.Box2I(self.pmin, self.pmax)) maskedImage.getImage().set(10) flat = afwImage.MaskedImageF(lsst.geom.Box2I(self.pmin, self.pmax)) flat.getImage().set(1) flatexposure = afwImage.ExposureF(flat, None) dmetadata = flatexposure.getMetadata() dmetadata.setString(self.filenameKeyword, 'Unittest Flat') ipIsr.flatCorrection(maskedImage, flatexposure.getMaskedImage(), 'USER', scaling) height = maskedImage.getHeight() width = maskedImage.getWidth() for j in range(height): for i in range(width): self.assertAlmostEqual(maskedImage.image[i, j, afwImage.LOCAL], 10 / (1. / scaling), 5)
def flatCorrection(self, exposure, flatExposure): """Apply flat correction in place DECam flat products have been trimmed and are smaller than the raw exposure. The size of edge trim is computed based on the dimensions of the input data. Only process the inner part of the raw exposure, and mask the outer pixels as EDGE. @param[in,out] exposure: exposure to process @param[in] flatExposure: flatfield exposure """ nEdge = _computeEdgeSize(exposure, flatExposure) if nEdge > 0: rawMaskedImage = exposure.getMaskedImage()[nEdge:-nEdge, nEdge:-nEdge] else: rawMaskedImage = exposure.getMaskedImage() flatCorrection(rawMaskedImage, flatExposure.getMaskedImage(), self.config.flatScalingType, self.config.flatUserScale) # Mask the unprocessed edge pixels as EDGE SourceDetectionTask.setEdgeBits( exposure.getMaskedImage(), rawMaskedImage.getBBox(), exposure.getMaskedImage().getMask().getPlaneBitMask("EDGE"))
def test_flatCorrection(self): """Expect round-trip application to be equal. Expect RuntimeError if sizes are different. """ flatExp = isrMock.FlatMock().run() flatMi = flatExp.getMaskedImage() mi = self.mi.clone() for scaling in ('USER', 'MEAN', 'MEDIAN'): # The `invert` parameter controls the direction of the # application. This will apply, and un-apply the flat. ipIsr.flatCorrection(self.mi, flatMi, scaling, userScale=1.0, trimToFit=True) ipIsr.flatCorrection(self.mi, flatMi, scaling, userScale=1.0, trimToFit=True, invert=True) self.assertMaskedImagesAlmostEqual(self.mi, mi, atol=1e-3, msg=f"flatCorrection with scaling {scaling}") flatMi = flatMi[1:-1, 1:-1, afwImage.LOCAL] with self.assertRaises(RuntimeError): ipIsr.flatCorrection(self.mi, flatMi, 'USER', userScale=1.0, trimToFit=False)
def test_flatCorrection(self): """Expect round-trip application to be equal. Expect RuntimeError if sizes are different. """ flatExp = isrMock.FlatMock().run() flatMi = flatExp.getMaskedImage() mi = self.mi.clone() for scaling in ('USER', 'MEAN', 'MEDIAN'): # The `invert` parameter controls the direction of the # application. This will apply, and un-apply the flat. ipIsr.flatCorrection(self.mi, flatMi, scaling, userScale=1.0, trimToFit=True) ipIsr.flatCorrection(self.mi, flatMi, scaling, userScale=1.0, trimToFit=True, invert=True) self.assertMaskedImagesAlmostEqual( self.mi, mi, atol=1e-3, msg=f"flatCorrection with scaling {scaling}") flatMi = flatMi[1:-1, 1:-1, afwImage.LOCAL] with self.assertRaises(RuntimeError): ipIsr.flatCorrection(self.mi, flatMi, 'USER', userScale=1.0, trimToFit=False)