def test_multiFringes(self): """Test that multi-fringe results are handled correctly by the task. """ self.config.large = 16 task = FringeTask(name="multiFringeMock", config=self.config) config = isrMock.IsrMockConfig() config.fringeScale = [750.0, 240.0, 220.0] config.fringeX0 = [100.0, 150.0, 200.0] config.fringeY0 = [0.0, 200.0, 0.0] dataRef = isrMock.FringeDataRefMock(config=config) exp = dataRef.get("raw") exp.setFilter(afwImage.FilterLabel(physical='FILTER')) medianBefore = np.nanmedian(exp.getImage().getArray()) fringes = task.readFringes(dataRef, assembler=None) solution, rms = task.run(exp, **fringes.getDict()) medianAfter = np.nanmedian(exp.getImage().getArray()) stdAfter = np.nanstd(exp.getImage().getArray()) self.assertLess(medianAfter, medianBefore) self.assertFloatsAlmostEqual(medianAfter, 3000.925, atol=1e-4) self.assertFloatsAlmostEqual(stdAfter, 3549.9885, atol=1e-4) deviation = np.abs(solution - config.fringeScale) self.assertTrue(np.all(deviation / rms < 1.0))
def testRunDataRef(self, pedestal=0.0, stddevMax=1.0e-4): """Test the .runDataRef method for complete test converage. Paramters --------- pedestal : `float`, optional Pedestal to add into fringe frame. stddevMax : `float`, optional Maximum allowable standard deviation. """ xFreq = np.pi/10.0 xOffset = 1.0 yFreq = np.pi/15.0 yOffset = 0.5 scale = 1.0 fringe = createFringe(self.size, self.size, xFreq, xOffset, yFreq, yOffset) fMi = fringe.getMaskedImage() fMi += pedestal exp = createFringe(self.size, self.size, xFreq, xOffset, yFreq, yOffset) eMi = exp.getMaskedImage() eMi *= scale task = FringeTask(name="fringe", config=self.config) dataRef = FringeDataRef(fringe) task.runDataRef(exp, dataRef) mi = exp.getMaskedImage() mi -= afwMath.makeStatistics(mi, afwMath.MEAN).getValue() self.assertLess(afwMath.makeStatistics(mi, afwMath.STDEV).getValue(), stddevMax)
def testRunDataRef(self, pedestal=0.0, stddevMax=1.0e-4): """Test the .runDataRef method for complete test converage. Paramters --------- pedestal : `float`, optional Pedestal to add into fringe frame. stddevMax : `float`, optional Maximum allowable standard deviation. """ xFreq = np.pi / 10.0 xOffset = 1.0 yFreq = np.pi / 15.0 yOffset = 0.5 scale = 1.0 fringe = createFringe(self.size, self.size, xFreq, xOffset, yFreq, yOffset) fMi = fringe.getMaskedImage() fMi += pedestal exp = createFringe(self.size, self.size, xFreq, xOffset, yFreq, yOffset) eMi = exp.getMaskedImage() eMi *= scale task = FringeTask(name="fringe", config=self.config) dataRef = FringeDataRef(fringe) task.runDataRef(exp, dataRef) mi = exp.getMaskedImage() mi -= afwMath.makeStatistics(mi, afwMath.MEAN).getValue() self.assertLess( afwMath.makeStatistics(mi, afwMath.STDEV).getValue(), stddevMax)
def testBad(self, bad="BAD"): """Test fringe subtraction with bad inputs. Parameters ---------- bad : `str`, optional Mask plane to use. """ xFreq = np.pi / 10.0 xOffset = 1.0 yFreq = np.pi / 15.0 yOffset = 0.5 fringe = createFringe(self.size, self.size, xFreq, xOffset, yFreq, yOffset) exp = createFringe(self.size, self.size, xFreq, xOffset, yFreq, yOffset) # This is a bad CCD: entirely masked exp.maskedImage.image.set(0.0) mask = exp.maskedImage.mask mask.set(mask.getPlaneBitMask(bad)) self.config.stats.badMaskPlanes = [bad] task = FringeTask(name="fringe", config=self.config) task.run(exp, fringe) self.assertFloatsEqual(exp.maskedImage.image.array, 0.0)
def testRunDataRef(self, pedestal=0.0, precision=1.0e-4): """Test the .runDataRef method for complete test converage @param pedestal Pedestal to add into fringe frame @param precision Precision for assertAlmostEqual """ xFreq = numpy.pi / 10.0 xOffset = 1.0 yFreq = numpy.pi / 15.0 yOffset = 0.5 scale = 1.0 fringe = createFringe(self.size, self.size, xFreq, xOffset, yFreq, yOffset) fMi = fringe.getMaskedImage() fMi += pedestal exp = createFringe(self.size, self.size, xFreq, xOffset, yFreq, yOffset) eMi = exp.getMaskedImage() eMi *= scale task = FringeTask(name="fringe", config=self.config) dataRef = FringeDataRef(fringe) task.runDataRef(exp, dataRef) mi = exp.getMaskedImage() mi -= afwMath.makeStatistics(mi, afwMath.MEAN).getValue() self.assertLess(afwMath.makeStatistics(mi, afwMath.STDEV).getValue(), precision)
def test_multiFringes(self): """Test that multi-fringe results are handled correctly by the task. """ self.config.filters.append("_unknown_") self.config.large = 16 task = FringeTask(name="multiFringeMock", config=self.config) config = isrMock.IsrMockConfig() config.fringeScale = [750.0, 240.0, 220.0] config.fringeX0 = [100.0, 150.0, 200.0] config.fringeY0 = [0.0, 200.0, 0.0] dataRef = isrMock.FringeDataRefMock(config=config) exp = dataRef.get("raw") medianBefore = np.nanmedian(exp.getImage().getArray()) fringes = task.readFringes(dataRef, assembler=None) solution, rms = task.run(exp, **fringes.getDict()) medianAfter = np.nanmedian(exp.getImage().getArray()) stdAfter = np.nanstd(exp.getImage().getArray()) self.assertLess(medianAfter, medianBefore) self.assertFloatsAlmostEqual(medianAfter, 3002.233, atol=1e-4) self.assertFloatsAlmostEqual(stdAfter, 3549.9375, atol=1e-4) deviation = np.abs(solution - config.fringeScale) self.assertTrue(np.all(deviation / rms < 1.0))
def test_readFringes(self): """Test that fringes can be successfully accessed from the butler. """ task = FringeTask() dataRef = isrMock.DataRefMock() result = task.readFringes(dataRef, assembler=None) self.assertIsInstance(result, pipeBase.Struct)
def test_readFringes(self): """Test that fringes can be successfully accessed from the butler. """ task = FringeTask() dataRef = isrMock.DataRefMock() result = task.readFringes(dataRef, assembler=None) self.assertIsInstance(result, pipeBase.Struct)
def testMultiple(self, pedestal=0.0): """Test subtraction of multiple fringe frames Paramters --------- pedestal : `float`, optional Pedestal to add into fringe frame. """ xFreqList = [0.1, 0.13, 0.06] xOffsetList = [0.0, 0.1, 0.2] yFreqList = [0.09, 0.12, 0.07] yOffsetList = [0.3, 0.2, 0.1] fringeList = [ createFringe(self.size, self.size, xFreq, xOffset, yFreq, yOffset) for xFreq, xOffset, yFreq, yOffset in zip( xFreqList, xOffsetList, yFreqList, yOffsetList) ] for fringe in fringeList: fMi = fringe.getMaskedImage() fMi += pedestal # Generate science frame scales = [0.33, 0.33, 0.33] image = afwImage.ImageF(self.size, self.size) image.set(0) for s, f in zip(scales, fringeList): image.scaledPlus(s, f.getMaskedImage().getImage()) mi = afwImage.makeMaskedImage(image) exp = afwImage.makeExposure(mi) exp.setFilter(afwImage.FilterLabel(physical='FILTER')) task = FringeTask(name="multiFringe", config=self.config) self.checkFringe(task, exp, fringeList, stddevMax=1.0e-2)
def testSingle(self, pedestal=0.0, stddevMax=1.0e-4): """Test subtraction of a single fringe frame. Parameters ---------- pedestal : `float`, optional Pedestal to add into fringe frame stddevMax : `float`, optional Maximum allowable standard deviation. """ xFreq = np.pi / 10.0 xOffset = 1.0 yFreq = np.pi / 15.0 yOffset = 0.5 scale = 1.0 fringe = createFringe(self.size, self.size, xFreq, xOffset, yFreq, yOffset) fMi = fringe.getMaskedImage() fMi += pedestal exp = createFringe(self.size, self.size, xFreq, xOffset, yFreq, yOffset) eMi = exp.getMaskedImage() eMi *= scale task = FringeTask(name="fringe", config=self.config) self.checkFringe(task, exp, fringe, stddevMax)
def setUp(self): self.size = 512 self.config = FringeTask.ConfigClass() self.config.filters = ['FILTER', 'y'] self.config.num = 5000 self.config.small = 1 self.config.large = 128 self.config.pedestal = False self.config.iterations = 10
def setUp(self): self.size = 512 self.config = FringeTask.ConfigClass() self.config.filters = ['FILTER'] self.config.num = 5000 self.config.small = 1 self.config.large = 128 self.config.pedestal = False afwImageUtils.defineFilter('FILTER', lambdaEff=0)
def testBad(self, bad="BAD"): """Test fringe subtraction with bad inputs. Parameters ---------- bad : `str`, optional Mask plane to use. """ xFreq = np.pi/10.0 xOffset = 1.0 yFreq = np.pi/15.0 yOffset = 0.5 fringe = createFringe(self.size, self.size, xFreq, xOffset, yFreq, yOffset) exp = createFringe(self.size, self.size, xFreq, xOffset, yFreq, yOffset) # This is a bad CCD: entirely masked exp.maskedImage.image.set(0.0) mask = exp.maskedImage.mask mask.set(mask.getPlaneBitMask(bad)) self.config.stats.badMaskPlanes = [bad] task = FringeTask(name="fringe", config=self.config) task.run(exp, fringe) self.assertFloatsEqual(exp.maskedImage.image.array, 0.0)