def testClone(self): """Test copying an exposure with an attached Blob. """ im = ExposureF(10, 10) # Extra components must be ALL CAPS for fits storage. im.getInfo().setComponent("BLOB", self.blob) im2 = im.clone() im3 = copy.deepcopy(im) im4 = ExposureF(im, deep=False) im5 = ExposureF(im, deep=True) for i in [im2, im3, im4, im5]: self.assertEqual(i.getInfo().getComponent("BLOB"), self.blob)
def testPersistence(self): """Test persisting an exposure with an attached Blob. """ im = ExposureF(10, 10) # Extra components must be ALL CAPS for fits storage. im.getInfo().setComponent("BLOB", self.blob) with lsst.utils.tests.getTempFilePath(".fits") as tmpFile: im.writeFits(tmpFile) newIm = ExposureF(tmpFile) self.assertEqual(newIm.getInfo().getComponent("BLOB"), self.blob) reader = ExposureFitsReader(tmpFile) newBlob = reader.readComponent("BLOB") self.assertEqual(newBlob, self.blob)
class FilterFractionTest(lsst.utils.tests.TestCase): def setUp(self): # Set up a Coadd with CoaddInputs tables that have blank filter columns to be filled # in by later test code. self.coadd = ExposureF(30, 90) # WCS is arbitrary, since it'll be the same for all images wcs = makeSkyWcs(crpix=Point2D(0, 0), crval=SpherePoint(45.0, 45.0, degrees), cdMatrix=makeCdMatrix(scale=0.17 * degrees)) self.coadd.setWcs(wcs) schema = ExposureCatalog.Table.makeMinimalSchema() self.filterKey = schema.addField("filter", type=str, doc="", size=16) weightKey = schema.addField("weight", type=float, doc="") # First input image covers the first 2/3, second covers the last 2/3, so they # overlap in the middle 1/3. inputs = ExposureCatalog(schema) self.input1 = inputs.addNew() self.input1.setId(1) self.input1.setBBox(Box2I(Point2I(0, 0), Point2I(29, 59))) self.input1.setWcs(wcs) self.input1.set(weightKey, 2.0) self.input2 = inputs.addNew() self.input2.setId(2) self.input2.setBBox(Box2I(Point2I(0, 30), Point2I(29, 89))) self.input2.setWcs(wcs) self.input2.set(weightKey, 3.0) # Use the same catalog for visits and CCDs since the algorithm we're testing only cares # about CCDs. self.coadd.getInfo().setCoaddInputs(CoaddInputs(inputs, inputs)) # Set up a catalog with centroids and a FilterFraction plugin. # We have one record in each region (first input only, both inputs, second input only) schema = SourceCatalog.Table.makeMinimalSchema() centroidKey = Point2DKey.addFields(schema, "centroid", doc="position", unit="pixel") schema.getAliasMap().set("slot_Centroid", "centroid") self.plugin = FilterFractionPlugin( config=FilterFractionPlugin.ConfigClass(), schema=schema, name="subaru_FilterFraction", metadata=PropertyList()) catalog = SourceCatalog(schema) self.record1 = catalog.addNew() self.record1.set(centroidKey, Point2D(14.0, 14.0)) self.record12 = catalog.addNew() self.record12.set(centroidKey, Point2D(14.0, 44.0)) self.record2 = catalog.addNew() self.record2.set(centroidKey, Point2D(14.0, 74.0)) def tearDown(self): del self.coadd del self.input1 del self.input2 del self.record1 del self.record2 del self.record12 del self.plugin def testSingleFilter(self): """Test that we get FilterFraction=1 for filters with only one version.""" self.input1.set(self.filterKey, "g") self.input2.set(self.filterKey, "g") self.plugin.measure(self.record1, self.coadd) self.plugin.measure(self.record12, self.coadd) self.plugin.measure(self.record2, self.coadd) self.assertEqual(self.record1.get("subaru_FilterFraction_unweighted"), 1.0) self.assertEqual(self.record12.get("subaru_FilterFraction_unweighted"), 1.0) self.assertEqual(self.record2.get("subaru_FilterFraction_unweighted"), 1.0) self.assertEqual(self.record1.get("subaru_FilterFraction_weighted"), 1.0) self.assertEqual(self.record12.get("subaru_FilterFraction_weighted"), 1.0) self.assertEqual(self.record2.get("subaru_FilterFraction_weighted"), 1.0) def testTwoFiltersI(self): """Test that we get the right answers for a mix of i and i2.""" self.input1.set(self.filterKey, "i") self.input2.set(self.filterKey, "i2") self.plugin.measure(self.record1, self.coadd) self.plugin.measure(self.record12, self.coadd) self.plugin.measure(self.record2, self.coadd) self.assertEqual(self.record1.get("subaru_FilterFraction_unweighted"), 0.0) self.assertEqual(self.record12.get("subaru_FilterFraction_unweighted"), 0.5) self.assertEqual(self.record2.get("subaru_FilterFraction_unweighted"), 1.0) self.assertEqual(self.record1.get("subaru_FilterFraction_weighted"), 0.0) self.assertEqual(self.record12.get("subaru_FilterFraction_weighted"), 0.6) self.assertEqual(self.record2.get("subaru_FilterFraction_weighted"), 1.0) def testTwoFiltersR(self): """Test that we get the right answers for a mix of r and r2.""" self.input1.set(self.filterKey, "r") self.input2.set(self.filterKey, "r2") self.plugin.measure(self.record1, self.coadd) self.plugin.measure(self.record12, self.coadd) self.plugin.measure(self.record2, self.coadd) self.assertEqual(self.record1.get("subaru_FilterFraction_unweighted"), 0.0) self.assertEqual(self.record12.get("subaru_FilterFraction_unweighted"), 0.5) self.assertEqual(self.record2.get("subaru_FilterFraction_unweighted"), 1.0) self.assertEqual(self.record1.get("subaru_FilterFraction_weighted"), 0.0) self.assertEqual(self.record12.get("subaru_FilterFraction_weighted"), 0.6) self.assertEqual(self.record2.get("subaru_FilterFraction_weighted"), 1.0) def testInvalidCombination(self): """Test that we get a fatal exception for weird combinations of filters.""" self.input1.set(self.filterKey, "i") self.input2.set(self.filterKey, "r") with self.assertRaises(FatalAlgorithmError): self.plugin.measure(self.record12, self.coadd)
def setUp(self): """Constructs a CCD with two amplifiers and prepares for ISR""" np.random.seed(12345) baseValue = 100.0 gain = 1.0 readNoise = 123456789.0 saturation = 987654321.0 height = 234 imageSize = Extent2I(123, height) overscanSize = Extent2I(16, height) self.sigma = 1.234 # Set up the various regions overscan1 = Box2I(Point2I(0, 0), overscanSize) image1 = Box2I(Point2I(overscanSize[0], 0), imageSize) image2 = Box2I(Point2I(overscanSize[0] + imageSize[0], 0), imageSize) overscan2 = Box2I(Point2I(overscanSize[0] + 2*imageSize[0], 0), overscanSize) leftBox = Box2I(overscan1.getMin(), Extent2I(overscan1.getWidth() + image1.getWidth(), height)) rightBox = Box2I(image2.getMin(), Extent2I(image2.getWidth() + overscan2.getWidth(), height)) target1 = Box2I(Point2I(0, 0), imageSize) target2 = Box2I(Point2I(image1.getWidth(), 0), imageSize) # Set the pixels exposure = ExposureF(Box2I(Point2I(0, 0), Extent2I(imageSize[0]*2 + overscanSize[0]*2, height))) yy = np.arange(0, height, 1, dtype=np.float32) leftImage = ExposureF(exposure, leftBox) leftImage.image.array[:] = baseValue + yy[:, np.newaxis] rightImage = ExposureF(exposure, rightBox) rightImage.image.array[:] = baseValue - yy[:, np.newaxis] leftOverscan = ExposureF(exposure, overscan1) leftOverscan.image.array += np.random.normal(0.0, self.sigma, leftOverscan.image.array.shape) rightOverscan = ExposureF(exposure, overscan2) rightOverscan.image.array += np.random.normal(0.0, self.sigma, leftOverscan.image.array.shape) exposure.mask.array[:] = 0.0 exposure.variance.array[:] = np.nan # Construct the detectors amps = AmpInfoCatalog(AmpInfoTable.makeMinimalSchema()) makeAmplifier(amps, "left", target1, image1, overscan1, gain, readNoise, saturation) makeAmplifier(amps, "right", target2, image2, overscan2, gain, readNoise, saturation) ccdBox = Box2I(Point2I(0, 0), Extent2I(image1.getWidth() + image2.getWidth(), height)) ccd = Detector("detector", 1, SCIENCE, "det1", ccdBox, amps, Orientation(), Extent2D(1.0, 1.0), {}) exposure.setDetector(ccd) header = PropertyList() header.add("EXPTIME", 0.0) exposure.getInfo().setVisitInfo(VisitInfo(header)) self.exposure = exposure self.config = IsrTask.ConfigClass() # Disable everything we don't care about self.config.doBias = False self.config.doDark = False self.config.doFlat = False self.config.doFringe = False self.config.doDefect = False self.config.doAddDistortionModel = False self.config.doWrite = False self.config.expectWcs = False self.config.doLinearize = False self.config.doCrosstalk = False self.config.doBrighterFatter = False self.config.doAttachTransmissionCurve = False # Set the things that match our test setup self.config.overscanFitType = "CHEB" self.config.overscanOrder = 1 self.config.doEmpiricalReadNoise = True self.task = IsrTask(config=self.config)
def setUp(self): """Constructs a CCD with two amplifiers and prepares for ISR""" np.random.seed(12345) baseValue = 100.0 gain = 1.0 readNoise = 123456789.0 saturation = 987654321.0 height = 234 imageSize = Extent2I(123, height) overscanSize = Extent2I(16, height) self.sigma = 1.234 # Set up the various regions overscan1 = Box2I(Point2I(0, 0), overscanSize) image1 = Box2I(Point2I(overscanSize[0], 0), imageSize) image2 = Box2I(Point2I(overscanSize[0] + imageSize[0], 0), imageSize) overscan2 = Box2I(Point2I(overscanSize[0] + 2 * imageSize[0], 0), overscanSize) leftBox = Box2I( overscan1.getMin(), Extent2I(overscan1.getWidth() + image1.getWidth(), height)) rightBox = Box2I( image2.getMin(), Extent2I(image2.getWidth() + overscan2.getWidth(), height)) target1 = Box2I(Point2I(0, 0), imageSize) target2 = Box2I(Point2I(image1.getWidth(), 0), imageSize) # Set the pixels exposure = ExposureF( Box2I(Point2I(0, 0), Extent2I(imageSize[0] * 2 + overscanSize[0] * 2, height))) yy = np.arange(0, height, 1, dtype=np.float32) leftImage = ExposureF(exposure, leftBox) leftImage.image.array[:] = baseValue + yy[:, np.newaxis] rightImage = ExposureF(exposure, rightBox) rightImage.image.array[:] = baseValue - yy[:, np.newaxis] leftOverscan = ExposureF(exposure, overscan1) leftOverscan.image.array += np.random.normal( 0.0, self.sigma, leftOverscan.image.array.shape) rightOverscan = ExposureF(exposure, overscan2) rightOverscan.image.array += np.random.normal( 0.0, self.sigma, leftOverscan.image.array.shape) exposure.mask.array[:] = 0.0 exposure.variance.array[:] = np.nan # Construct the detectors amp1 = makeAmplifier("left", target1, image1, overscan1, gain, readNoise, saturation) amp2 = makeAmplifier("right", target2, image2, overscan2, gain, readNoise, saturation) ccdBox = Box2I(Point2I(0, 0), Extent2I(image1.getWidth() + image2.getWidth(), height)) camBuilder = cameraGeom.Camera.Builder("fakeCam") detBuilder = camBuilder.add("detector", 1) detBuilder.setSerial("det1") detBuilder.setBBox(ccdBox) detBuilder.setPixelSize(Extent2D(1.0, 1.0)) detBuilder.setOrientation(cameraGeom.Orientation()) detBuilder.append(amp1) detBuilder.append(amp2) cam = camBuilder.finish() exposure.setDetector(cam.get('detector')) header = PropertyList() header.add("EXPTIME", 0.0) exposure.getInfo().setVisitInfo(VisitInfo(header)) self.exposure = exposure self.config = IsrTask.ConfigClass() # Disable everything we don't care about self.config.doBias = False self.config.doDark = False self.config.doFlat = False self.config.doFringe = False self.config.doDefect = False self.config.doWrite = False self.config.expectWcs = False self.config.doLinearize = False self.config.doCrosstalk = False self.config.doBrighterFatter = False self.config.doAttachTransmissionCurve = False self.config.doAssembleCcd = False self.config.doNanMasking = False self.config.doInterpolate = False self.config.maskNegativeVariance = False # This runs on mocks. # Set the things that match our test setup self.config.overscan.fitType = "CHEB" self.config.overscan.order = 1 self.config.doEmpiricalReadNoise = True self.task = IsrTask(config=self.config)