@@ -1930,5 +1930,48 @@ def test_drawreal_seg_fault():
19301930 np .testing .assert_array_equal (image .array , 0 )
19311931
19321932
1933+ @timer
1934+ def test_interpolatedimage_maxk_kspace_pixel_gap ():
1935+ # this code makes an image where there is a gap in the fourier
1936+ # space image of a certain number pixels where pixels go above
1937+ # and below the maxk threshold. At >five pixels, galsim should
1938+ # ignore the gap, but less than that it should increase maxk.
1939+
1940+ print ("\n | offset | orig | new |" )
1941+ print ("|--------|------------|--------------------|" )
1942+ for offset in [0 , 3 , 4 , 5 , 6 , 7 ]:
1943+ im = galsim .Gaussian (fwhm = 4.5 ).drawImage (scale = 1 )
1944+ iim = galsim .InterpolatedImage (im , scale = 1 )
1945+ orig_maxk = iim .maxk
1946+
1947+ kim = iim ._xim .copy ().calculate_fft ()
1948+ kx , ky = kim .get_pixel_centers ()
1949+ kx *= kim .scale
1950+ ky *= kim .scale
1951+ # this is the last pixel above threshold. galsim adds 1
1952+ # to the last pixel it finds above threshold to compute orig_maxk
1953+ # and so we subtract 1
1954+ maxk_ix = np .floor (orig_maxk / kim .scale ).astype (int ) - 1
1955+ if offset > 0 :
1956+ kim [maxk_ix + offset , maxk_ix ] = kim [0 , 0 ].real
1957+ new_im = kim .calculate_inverse_fft ()
1958+ new_maxk = galsim .InterpolatedImage (new_im , scale = 1 , pad_factor = 1 ).maxk
1959+
1960+ print ("| % 6d | %10.6f | %18.6f |" % (
1961+ offset ,
1962+ orig_maxk ,
1963+ new_maxk ),
1964+ )
1965+
1966+ if offset <= 5 :
1967+ # for offsets <=5, we should get an offset of offset pixels
1968+ # in the location of maxk
1969+ np .testing .assert_allclose (new_maxk - orig_maxk , offset * kim .scale , atol = 1e-12 , rtol = 0 )
1970+ else :
1971+ np .testing .assert_allclose (new_maxk , orig_maxk , atol = 1e-12 , rtol = 0 )
1972+
1973+ print ("|--------|------------|--------------------|" )
1974+
1975+
19331976if __name__ == "__main__" :
19341977 runtests (__file__ )
0 commit comments