def testNoise(self): """ Test that ExampleCCDNoise puts the expected counts on an image by generating a flat image, adding noise and background to it, and calculating the variance of counts in the image. """ lsstDefaults = LSSTdefaults() gain = 2.5 readnoise = 6.0 photParams = PhotometricParameters(gain=gain, readnoise=readnoise) img = galsim.Image(100, 100) noise = ExampleCCDNoise(seed=42) m5 = 24.5 bandpass = Bandpass() bandpass.readThroughput( os.path.join(getPackageDir('throughputs'), 'baseline', 'total_r.dat')) background = calcSkyCountsPerPixelForM5( m5, bandpass, FWHMeff=lsstDefaults.FWHMeff('r'), photParams=photParams) noisyImage = noise.addNoiseAndBackground( img, bandpass, m5=m5, FWHMeff=lsstDefaults.FWHMeff('r'), photParams=photParams) mean = 0.0 var = 0.0 for ix in range(1, 101): for iy in range(1, 101): mean += noisyImage(ix, iy) mean = mean / 10000.0 for ix in range(1, 101): for iy in range(1, 101): var += (noisyImage(ix, iy) - mean) * (noisyImage(ix, iy) - mean) var = var / 9999.0 varElectrons = background * gain + readnoise varADU = varElectrons / (gain * gain) msg = 'background %e mean %e ' % (background, mean) self.assertLess(np.abs(background / mean - 1.0), 0.05, msg=msg) msg = 'var %e varADU %e ; ratio %e ; background %e' % ( var, varADU, var / varADU, background) self.assertLess(np.abs(var / varADU - 1.0), 0.05, msg=msg)
def testNoise(self): """ Test that ExampleCCDNoise puts the expected counts on an image by generating a flat image, adding noise and background to it, and calculating the variance of counts in the image. """ lsstDefaults = LSSTdefaults() gain = 2.5 readnoise = 6.0 photParams=PhotometricParameters(gain=gain, readnoise=readnoise) img = galsim.Image(100,100) noise = ExampleCCDNoise(seed=42) m5 = 24.5 bandpass = Bandpass() bandpass.readThroughput(os.path.join(lsst.utils.getPackageDir('throughputs'),'baseline','total_r.dat')) background = calcSkyCountsPerPixelForM5(m5, bandpass, seeing=lsstDefaults.seeing('r'), photParams=photParams) noisyImage = noise.addNoiseAndBackground(img, bandpass, m5=m5, seeing=lsstDefaults.seeing('r'), photParams=photParams) mean = 0.0 var = 0.0 for ix in range(1,101): for iy in range(1,101): mean += noisyImage(ix, iy) mean = mean/10000.0 for ix in range(1,101): for iy in range(1,101): var += (noisyImage(ix, iy) - mean)*(noisyImage(ix, iy) - mean) var = var/9999.0 varElectrons = background*gain + readnoise varADU = varElectrons/(gain*gain) msg = 'background %e mean %e ' % (background, mean) self.assertTrue(numpy.abs(background/mean - 1.0) < 0.05, msg=msg) msg = 'var %e varADU %e ; ratio %e ; background %e' % (var, varADU, var/varADU, background) self.assertTrue(numpy.abs(var/varADU - 1.0) < 0.05, msg=msg)
class testGalSimGalaxiesNoisy(testGalSimGalaxiesNoiseless): #defined in galSimInterface/galSimUtilities.py noise_and_background = ExampleCCDNoise(99)
class testGalSimStarsWithNoise(testGalSimStarsNoiseless): #defined in galSimInterface/galSimUtilities.py noise_and_background = ExampleCCDNoise(seed=99)
class noisyCatalog(testGalaxyCatalog): """ Adds a noise and sky background wrapper to testGalaxyCatalog """ PSF = SNRdocumentPSF() noise_and_background = ExampleCCDNoise(seed=42)
class backgroundCatalog(testGalaxyCatalog): """ Add sky background but no noise to testGalaxyCatalog """ PSF = SNRdocumentPSF() noise_and_background = ExampleCCDNoise(addNoise=False, seed=42)