def test_Cubic_ref(): """Test use of Cubic interpolant against some reference values """ import time t1 = time.time() interp = galsim.Cubic(tol=1.e-4) testobj = galsim.InterpolatedImage(ref_image.view(), x_interpolant=interp, dx=dx, normalization='sb') testKvals = np.zeros(len(KXVALS)) # Make test kValues for i in xrange(len(KXVALS)): posk = galsim.PositionD(KXVALS[i], KYVALS[i]) testKvals[i] = np.abs(testobj.kValue(posk)) # Compare with saved array refKvals = np.loadtxt(os.path.join(TESTDIR, "absfKCubic_test.txt")) print 'ref = ', refKvals print 'test = ', testKvals print 'kValue(0) = ', testobj.kValue(galsim.PositionD(0., 0.)) np.testing.assert_array_almost_equal( refKvals / testKvals, 1., 5, err_msg="kValues do not match reference values for Cubic interpolant.") t2 = time.time() print 'time for %s = %.2f' % (funcname(), t2 - t1)
def test_Cubic_spline(): """Test the spline tabulation of the k space Cubic interpolant. """ import time t1 = time.time() interp = galsim.InterpolantXY(galsim.Cubic(tol=1.e-4)) testobj = galsim.SBInterpolatedImage(image.view(), interp, dx=dx) testKvals = np.zeros(len(KXVALS)) # Make test kValues for i in xrange(len(KXVALS)): posk = galsim.PositionD(KXVALS[i], KYVALS[i]) testKvals[i] = np.abs(testobj.kValue(posk)) # Compare with saved array refKvals = np.loadtxt(os.path.join(TESTDIR, "absfKCubic_test.txt")) np.testing.assert_array_almost_equal( refKvals, testKvals, DECIMAL, err_msg="Spline-interpolated kValues do not match saved " + "data for k space Cubic interpolant.") t2 = time.time() print 'time for %s = %.2f' % (funcname(), t2 - t1)
g2 = galsim.Gaussian(sigma = 1.9, flux=3.1) g2.applyShear(-0.4,0.3) g2.applyShift(-0.3,0.5) g3 = galsim.Gaussian(sigma = 4.1, flux=1.6) g3.applyShear(0.1,-0.1) g3.applyShift(0.7,-0.2) final = g1 + g2 + g3 image = galsim.ImageD(128,128) dx = 0.4 final.draw(image=image, dx=dx) dir = '../../../tests/interpolant_comparison_files' # First make a Cubic interpolant interp = galsim.InterpolantXY(galsim.Cubic(tol=1.e-4)) testobj = galsim.SBInterpolatedImage(image.view(), interp, dx=dx) for i in xrange(len(kxvals)): posk = galsim.PositionD(kxvals[i], kyvals[i]) absoutk[i] = np.abs(testobj.kValue(posk)) print absoutk np.savetxt(os.path.join(dir,'absfKCubic_test.txt'), absoutk) # Then make a Quintic interpolant interp = galsim.InterpolantXY(galsim.Quintic(tol=1.e-4)) testobj = galsim.SBInterpolatedImage(image.view(), interp, dx=dx) for i in xrange(len(kxvals)): posk = galsim.PositionD(kxvals[i], kyvals[i]) absoutk[i] = np.abs(testobj.kValue(posk)) print absoutk np.savetxt(os.path.join(dir,'absfKQuintic_test.txt'), absoutk)
The parameters of the Sersic images come from a COSMOS best-fitting Sersic model catalog. """ import cPickle import numpy as np import galsim import test_interpolants SERSIC_IMAGE_SIZE = 512 # For initial image of the Sersic at Hubble resolution, make nice and large TEST_IMAGE_SIZE = SERSIC_IMAGE_SIZE # For speed could make this smaller # Dictionary for parsing the test_interpolants.interpolant_list into galsim Interpolants INTERPOLANT_DICT = { "nearest": galsim.Nearest(), "sinc": galsim.SincInterpolant(), "linear": galsim.Linear(), "cubic": galsim.Cubic(), "quintic": galsim.Quintic(), "lanczos3": galsim.Lanczos(3), "lanczos4": galsim.Lanczos(4), "lanczos5": galsim.Lanczos(5), "lanczos7": galsim.Lanczos(7) } # Output filenames DELTA_FILENAME = 'interpolant_test_parametric_output_delta.dat' ORIGINAL_FILENAME = 'interpolant_test_parametric_output_original.dat' NITEMS = 30 # For now, look at a few only LAM_OVER_DIAM_COSMOS = 814.e-9 / 2.4 # All the original images in Melanie's tests were from COSMOS # F814W, so this is a crude approximation to the PSF scale in
def test_interpolated_image(): """Test various ways to build an InterpolatedImage """ imgdir = 'SBProfile_comparison_images' file_name = os.path.join(imgdir,'gauss_smallshear.fits') imgdir2 = 'fits_files' file_name2 = os.path.join(imgdir2,'interpim_hdu_test.fits') config = { 'gal1' : { 'type' : 'InterpolatedImage', 'image' : file_name }, 'gal2' : { 'type' : 'InterpolatedImage', 'image' : file_name, 'x_interpolant' : 'linear' }, 'gal3' : { 'type' : 'InterpolatedImage', 'image' : file_name, 'x_interpolant' : 'cubic', 'normalization' : 'sb', 'flux' : 1.e4 }, 'gal4' : { 'type' : 'InterpolatedImage', 'image' : file_name, 'x_interpolant' : 'lanczos5', 'scale' : 0.7, 'flux' : 1.e5 }, 'gal5' : { 'type' : 'InterpolatedImage', 'image' : file_name, 'noise_pad' : 0.001 }, 'gal6' : { 'type' : 'InterpolatedImage', 'image' : file_name, 'noise_pad' : 'fits_files/blankimg.fits' }, 'gal7' : { 'type' : 'InterpolatedImage', 'image' : file_name, 'pad_image' : 'fits_files/blankimg.fits' }, 'galmulti' : { 'type' : 'InterpolatedImage', 'image' : file_name2, 'hdu' : 2 } } rng = galsim.UniformDeviate(1234) config['rng'] = galsim.UniformDeviate(1234) # A second copy starting with the same seed. gal1a = galsim.config.BuildGSObject(config, 'gal1')[0] im = galsim.fits.read(file_name) gal1b = galsim.InterpolatedImage(im) gsobject_compare(gal1a, gal1b) gal2a = galsim.config.BuildGSObject(config, 'gal2')[0] gal2b = galsim.InterpolatedImage(im, x_interpolant=galsim.Linear()) gsobject_compare(gal2a, gal2b) gal3a = galsim.config.BuildGSObject(config, 'gal3')[0] gal3b = galsim.InterpolatedImage(im, x_interpolant=galsim.Cubic(), normalization='sb', flux=1.e4) gsobject_compare(gal3a, gal3b) gal4a = galsim.config.BuildGSObject(config, 'gal4')[0] interp = galsim.Lanczos(n=5, conserve_dc=True) gal4b = galsim.InterpolatedImage(im, x_interpolant=interp, scale=0.7, flux=1.e5) gsobject_compare(gal4a, gal4b) gal5a = galsim.config.BuildGSObject(config, 'gal5')[0] gal5b = galsim.InterpolatedImage(im, rng=rng, noise_pad=0.001) gsobject_compare(gal5a, gal5b) gal6a = galsim.config.BuildGSObject(config, 'gal6')[0] gal6b = galsim.InterpolatedImage(im, rng=rng, noise_pad='fits_files/blankimg.fits') gsobject_compare(gal6a, gal6b) gal7a = galsim.config.BuildGSObject(config, 'gal7')[0] gal7b = galsim.InterpolatedImage(im, pad_image = 'fits_files/blankimg.fits') gsobject_compare(gal7a, gal7b) # Now test the reading from some particular HDU galmulti = galsim.config.BuildGSObject(config, 'galmulti')[0] im = galmulti.drawImage(scale=0.2, method='no_pixel') test_g2 = im.FindAdaptiveMom().observed_shape.g2 np.testing.assert_almost_equal( test_g2, 0.7, decimal=3, err_msg='Did not get right shape image after reading InterpolatedImage from HDU')