def test_ne(): """ Check that inequality works as expected.""" gsp = galsim.GSParams(maxk_threshold=1.1e-3, folding_threshold=5.1e-3) gal1 = galsim.Gaussian(fwhm=1) gal2 = galsim.Gaussian(fwhm=2) # Sum. Params are objs to add and potentially gsparams. gals = [ galsim.Sum(gal1), galsim.Sum(gal1, gal2), galsim.Sum(gal2, gal1), # Not! commutative. galsim.Sum(galsim.Sum(gal1, gal2), gal2), galsim.Sum(gal1, galsim.Sum(gal2, gal2)), # Not! associative. galsim.Sum(gal1, gsparams=gsp) ] all_obj_diff(gals) # Convolution. Params are objs to convolve and potentially gsparams. # The following should test unequal gals = [ galsim.Convolution(gal1), galsim.Convolution(gal1, gal2), galsim.Convolution(gal2, gal1), # Not! commutative. galsim.Convolution(gal1, gal2, real_space=True), galsim.Convolution(galsim.Convolution(gal1, gal2), gal2), galsim.Convolution(gal1, galsim.Convolution(gal2, gal2)), # Not! associative. galsim.Convolution(gal1, gsparams=gsp) ] all_obj_diff(gals) # Deconvolution. Only params here are obj to deconvolve and gsparams. gals = [ galsim.Deconvolution(gal1), galsim.Deconvolution(gal2), galsim.Deconvolution(gal1, gsparams=gsp) ] all_obj_diff(gals) # AutoConvolution. Only params here are obj to deconvolve and gsparams. gals = [ galsim.AutoConvolution(gal1), galsim.AutoConvolution(gal2), galsim.AutoConvolution(gal1, gsparams=gsp) ] all_obj_diff(gals) # AutoCorrelation. Only params here are obj to deconvolve and gsparams. gals = [ galsim.AutoCorrelation(gal1), galsim.AutoCorrelation(gal2), galsim.AutoCorrelation(gal1, gsparams=gsp) ] all_obj_diff(gals)
def test_ne(): import time t1 = time.time() gsp = galsim.GSParams(maxk_threshold=1.1e-3, folding_threshold=5.1e-3) gal1 = galsim.Gaussian(fwhm=1) gal2 = galsim.Gaussian(fwhm=2) # Sum. Params are objs to add and potentially gsparams. gals = [galsim.Sum(gal1), galsim.Sum(gal1, gal2), galsim.Sum(gal2, gal1), # Not! commutative. galsim.Sum(galsim.Sum(gal1, gal2), gal2), galsim.Sum(gal1, galsim.Sum(gal2, gal2)), # Not! associative. galsim.Sum(gal1, gsparams=gsp)] all_obj_diff(gals) # Convolution. Params are objs to convolve and potentially gsparams. # The following should test unequal gals = [galsim.Convolution(gal1), galsim.Convolution(gal1, gal2), galsim.Convolution(gal2, gal1), # Not! commutative. galsim.Convolution(gal1, gal2, real_space=True), galsim.Convolution(galsim.Convolution(gal1, gal2), gal2), galsim.Convolution(gal1, galsim.Convolution(gal2, gal2)), # Not! associative. galsim.Convolution(gal1, gsparams=gsp)] all_obj_diff(gals) # Deconvolution. Only params here are obj to deconvolve and gsparams. gals = [galsim.Deconvolution(gal1), galsim.Deconvolution(gal2), galsim.Deconvolution(gal1, gsparams=gsp)] all_obj_diff(gals) # AutoConvolution. Only params here are obj to deconvolve and gsparams. gals = [galsim.AutoConvolution(gal1), galsim.AutoConvolution(gal2), galsim.AutoConvolution(gal1, gsparams=gsp)] all_obj_diff(gals) # AutoCorrelation. Only params here are obj to deconvolve and gsparams. gals = [galsim.AutoCorrelation(gal1), galsim.AutoCorrelation(gal2), galsim.AutoCorrelation(gal1, gsparams=gsp)] all_obj_diff(gals) t2 = time.time() print 'time for %s = %.2f'%(funcname(),t2-t1)
def test_convolve_noise(): """Test that noise propagation works properly for compount objects. """ obj1 = galsim.Gaussian(sigma=1.7) obj2 = galsim.Gaussian(sigma=2.3) obj1.noise = galsim.UncorrelatedNoise(variance=0.3, scale=0.2) obj2.noise = galsim.UncorrelatedNoise(variance=0.5, scale=0.2) obj3 = galsim.Gaussian(sigma=2.9) # Convolve convolves the noise from a single component conv2 = galsim.Convolution([obj1, obj3]) noise = galsim.Convolve([obj1.noise._profile, obj3, obj3]) # xValue is too slow here. Use drawImage to get variance. (Just as CorrelatedNoise does.) variance = noise.drawImage(nx=1, ny=1, scale=1., method='sb')(1, 1) np.testing.assert_almost_equal( conv2.noise.getVariance(), variance, err_msg= "Convolution of two objects did not correctly propagate noise varinace" ) conv2 = galsim.Convolution([obj2, obj3]) noise = galsim.Convolve([obj2.noise._profile, obj3, obj3]) variance = noise.drawImage(nx=1, ny=1, scale=1., method='sb')(1, 1) np.testing.assert_almost_equal( conv2.noise.getVariance(), variance, err_msg= "Convolution of two objects did not correctly propagate noise varinace" ) # Convolution of multiple objects with noise attributes raises a warning and fails # to propagate noise properly. (It takes the input noise from the first one.) conv2 = galsim.Convolution(obj1, obj2) conv3 = galsim.Convolution(obj1, obj2, obj3) with assert_warns(galsim.GalSimWarning): assert conv2.noise == obj1.noise.convolvedWith(obj2) with assert_warns(galsim.GalSimWarning): assert conv3.noise == obj1.noise.convolvedWith( galsim.Convolve(obj2, obj3)) # Convolution with only one object uses that object's noise conv1 = galsim.Convolution(obj1) assert conv1.noise == obj1.noise # Other types don't propagate noise and give a warning about it. deconv = galsim.Deconvolution(obj2) autoconv = galsim.AutoConvolution(obj2) autocorr = galsim.AutoCorrelation(obj2) four = galsim.FourierSqrt(obj2) with assert_warns(galsim.GalSimWarning): assert deconv.noise is None with assert_warns(galsim.GalSimWarning): assert autoconv.noise is None with assert_warns(galsim.GalSimWarning): assert autocorr.noise is None with assert_warns(galsim.GalSimWarning): assert four.noise is None obj2.noise = None # Remove obj2 noise for the rest. conv2 = galsim.Convolution(obj1, obj2) noise = galsim.Convolve([obj1.noise._profile, obj2, obj2]) variance = noise.drawImage(nx=1, ny=1, scale=1., method='sb')(1, 1) np.testing.assert_almost_equal( conv2.noise.getVariance(), variance, err_msg= "Convolution of two objects did not correctly propagate noise varinace" ) conv3 = galsim.Convolution(obj1, obj2, obj3) noise = galsim.Convolve([obj1.noise._profile, obj2, obj2, obj3, obj3]) variance = noise.drawImage(nx=1, ny=1, scale=1., method='sb')(1, 1) np.testing.assert_almost_equal( conv3.noise.getVariance(), variance, err_msg= "Convolution of three objects did not correctly propagate noise varinace" ) deconv = galsim.Deconvolution(obj2) autoconv = galsim.AutoConvolution(obj2) autocorr = galsim.AutoCorrelation(obj2) four = galsim.FourierSqrt(obj2) assert deconv.noise is None assert autoconv.noise is None assert autocorr.noise is None assert four.noise is None