def bypass_defects(self, datasetType, pythonType, butlerLocation, dataId): """Return a defect list based on butlerLocation returned by map_defects. Use all nonzero pixels in the Community Pipeline Bad Pixel Masks. @param[in] butlerLocation: Butler Location with path to defects FITS @param[in] dataId: data identifier @return meas.algorithms.DefectListT """ bpmFitsPath = butlerLocation.getLocationsWithRoot()[0] bpmImg = afwImage.ImageU(bpmFitsPath) idxBad = np.nonzero(bpmImg.getArray()) mim = afwImage.MaskedImageU(bpmImg.getDimensions()) mim.getMask().getArray()[idxBad] |= mim.getMask().getPlaneBitMask("BAD") return isr.getDefectListFromMask(mim, "BAD", growFootprints=0)
def testCopyMaskedImage(self): """Test copy constructor""" # # shallow copy # mi = self.mimage.Factory(self.mimage, False) val00 = self.mimage[0, 0, afwImage.LOCAL] nval00 = (100, 0xff, -1) # the new value we'll set self.assertNotEqual(val00, nval00) self.assertEqual(mi[0, 0, afwImage.LOCAL], val00) mi[0, 0, afwImage.LOCAL] = nval00 self.assertEqual(self.mimage[0, 0, afwImage.LOCAL], nval00) self.assertEqual(mi[0, 0, afwImage.LOCAL], nval00) mi[0, 0, afwImage.LOCAL] = val00 # reinstate initial value # # deep copy # mi = self.mimage.Factory(self.mimage, True) self.assertEqual(mi[0, 0, afwImage.LOCAL], val00) mi[0, 0, afwImage.LOCAL] = nval00 self.assertEqual(self.mimage[0, 0, afwImage.LOCAL], val00) self.assertEqual(mi[0, 0, afwImage.LOCAL], nval00) # # Copy with change of Image type # mi = self.mimage.convertD() self.assertEqual(mi[0, 0, afwImage.LOCAL], val00) mi[0, 0, afwImage.LOCAL] = nval00 self.assertEqual(self.mimage[0, 0, afwImage.LOCAL], val00) self.assertEqual(mi[0, 0, afwImage.LOCAL], nval00) # # Convert from U to F # mi = afwImage.MaskedImageU(lsst.geom.Extent2I(10, 20)) val00 = (10, 0x10, 1) mi.set(val00) self.assertEqual(mi[0, 0, afwImage.LOCAL], val00) fmi = mi.convertF() self.assertEqual(fmi[0, 0, afwImage.LOCAL], val00)
def testAssembly(self): ccdNames = ('R:0,0 S:1,0', 'R:0,0 S:0,1') detectorImageMap = {True: afwImage.ImageU(os.path.join(testPath, 'test_comp_trimmed.fits.gz'), allowUnsafe=True), False: afwImage.ImageU(os.path.join(testPath, 'test_comp.fits.gz'), allowUnsafe=True)} for cw in self.cameraList: camera = cw.camera imList = self.assemblyList[camera.getName()] for ccdName in ccdNames: det = camera[ccdName] if len(imList) == 1: # There's one test image because it's the same for all # amplifiers, not because there's only one amplifier. imList *= len(det) # Test going from possibly-separate amp images to detector # images. for trim, assemble in ((False, assembleAmplifierRawImage), (True, assembleAmplifierImage)): if not trim: outBbox = cameraGeomUtils.calcRawCcdBBox(det) else: outBbox = det.getBBox() outImage = afwImage.ImageU(outBbox) for amp, im in zip(det, imList): assemble(outImage, im, amp) self.assertImagesEqual(outImage, detectorImageMap[trim]) # Test going from detector images back to single-amplifier # images. detector_exposure = afwImage.ExposureU(afwImage.MaskedImageU(detectorImageMap[trim])) detector_exposure.setDetector(makeUpdatedDetector(det)) for amp, im in zip(det, imList): amp_exposure = AmplifierIsolator.apply(detector_exposure, amp) self.assertEqual(len(amp_exposure.getDetector()), 1) self.assertEqual(amp_exposure.getDetector().getBBox(), amp.getBBox()) self.assertAmplifiersEqual(amp, amp_exposure.getDetector()[0]) if not trim: self.assertEqual(cameraGeomUtils.calcRawCcdBBox(amp_exposure.getDetector()), amp_exposure.getBBox()) self.assertImagesEqual(im[amp.getRawBBox()], amp_exposure.image) else: self.assertEqual(amp_exposure.getDetector().getBBox(), amp_exposure.getBBox()) self.assertImagesEqual(im[amp.getRawDataBBox()], amp_exposure.image)