def testRegularizationSidelobes(self): """Test that artificial chromatic sidelobes are suppressed. """ clampFrequency = 2. regularizationWidth = 2 noiseLevel = 0.1 sourceAmplitude = 100. modelImages = self.makeTestImages(seed=5, nSrc=5, psfSize=3., noiseLevel=noiseLevel, detectionSigma=5., sourceSigma=sourceAmplitude, fluxRange=2.) templateImage = np.mean([model.array for model in modelImages], axis=0) sidelobeImages = self.makeTestImages(seed=5, nSrc=5, psfSize=1.5, noiseLevel=noiseLevel/10., detectionSigma=5., sourceSigma=sourceAmplitude*5., fluxRange=2.) statsCtrl = self.prepareStats() signList = [-1., 0., 1.] sidelobeShift = (0., 4.) for model, sidelobe, sign in zip(modelImages, sidelobeImages, signList): sidelobe.array *= sign model.array += applyDcr(sidelobe.array, sidelobeShift, useInverse=False) model.array += applyDcr(sidelobe.array, sidelobeShift, useInverse=True) dcrModels = DcrModel(modelImages=modelImages, mask=self.mask) refModels = [dcrModels[subfilter].clone() for subfilter in range(self.dcrNumSubfilters)] dcrModels.regularizeModelFreq(modelImages, self.bbox, statsCtrl, clampFrequency, regularizationWidth=regularizationWidth) for model, refModel, sign in zip(modelImages, refModels, signList): # Make sure the test parameters do reduce the outliers self.assertGreater(np.sum(np.abs(refModel.array - templateImage)), np.sum(np.abs(model.array - templateImage)))
def testRegularizationSidelobes(self): """Test that artificial chromatic sidelobes are suppressed. """ clampFrequency = 2. regularizationWidth = 2 noiseLevel = 0.1 sourceAmplitude = 100. modelImages = self.makeTestImages(seed=5, nSrc=5, psfSize=3., noiseLevel=noiseLevel, detectionSigma=5., sourceSigma=sourceAmplitude, fluxRange=2.) templateImage = np.mean([model.array for model in modelImages], axis=0) sidelobeImages = self.makeTestImages(seed=5, nSrc=5, psfSize=1.5, noiseLevel=noiseLevel/10., detectionSigma=5., sourceSigma=sourceAmplitude*5., fluxRange=2.) statsCtrl = self.prepareStats() signList = [-1., 0., 1.] sidelobeShift = (0., 4.) for model, sidelobe, sign in zip(modelImages, sidelobeImages, signList): sidelobe.array *= sign model.array += applyDcr(sidelobe.array, sidelobeShift, useInverse=False) model.array += applyDcr(sidelobe.array, sidelobeShift, useInverse=True) dcrModels = DcrModel(modelImages=modelImages, mask=self.mask) refModels = [dcrModels[subfilter].clone() for subfilter in range(self.dcrNumSubfilters)] dcrModels.regularizeModelFreq(modelImages, self.bbox, statsCtrl, clampFrequency, regularizationWidth=regularizationWidth) for model, refModel, sign in zip(modelImages, refModels, signList): # Make sure the test parameters do reduce the outliers self.assertGreater(np.sum(np.abs(refModel.array - templateImage)), np.sum(np.abs(model.array - templateImage)))
def testApplyDcr(self): """Test that the image transformation reduces to a simple shift. """ dxVals = [-2, 1, 0, 1, 2] dyVals = [-2, 1, 0, 1, 2] x0 = 13 y0 = 27 inputImage = afwImage.MaskedImageF(self.bbox) image = inputImage.image.array image[y0, x0] = 1. for dx in dxVals: for dy in dyVals: shift = (dy, dx) shiftedImage = applyDcr(image, shift, useInverse=False) # Create a blank reference image, and add the fake point source at the shifted location. refImage = afwImage.MaskedImageF(self.bbox) refImage.image.array[y0 + dy, x0 + dx] = 1. self.assertFloatsAlmostEqual(shiftedImage, refImage.image.array, rtol=1e-12, atol=1e-12)
def testApplyDcr(self): """Test that the image transformation reduces to a simple shift. """ dxVals = [-2, 1, 0, 1, 2] dyVals = [-2, 1, 0, 1, 2] x0 = 13 y0 = 27 inputImage = afwImage.MaskedImageF(self.bbox) image = inputImage.image.array image[y0, x0] = 1. for dx in dxVals: for dy in dyVals: shift = (dy, dx) shiftedImage = applyDcr(image, shift, useInverse=False) # Create a blank reference image, and add the fake point source at the shifted location. refImage = afwImage.MaskedImageF(self.bbox) refImage.image.array[y0 + dy, x0 + dx] = 1. self.assertFloatsAlmostEqual(shiftedImage, refImage.image.array, rtol=1e-12, atol=1e-12)