Skip to content

Commit 69afde0

Browse files
beckermrrmjarvis
authored andcommitted
fix: use simpler test code
1 parent 3be4322 commit 69afde0

1 file changed

Lines changed: 8 additions & 32 deletions

File tree

tests/test_interpolatedimage.py

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,30 +1897,10 @@ def test_interpolatedimage_maxk_kspace_pixel_gap():
18971897
# and below the maxk threshold. At >five pixels, galsim should
18981898
# ignore the gap, but less than that it should increase maxk.
18991899

1900-
def _compute_maxk_cpp(xim, iim):
1901-
# this little function exists only to invoke the C++
1902-
# maxk code...
1903-
# we use copies to avoid side effects
1904-
ikim = xim.copy()
1905-
sbii = galsim._galsim.SBInterpolatedImage(
1906-
ikim._image,
1907-
ikim.bounds._b,
1908-
iim._pad_image.copy().bounds._b,
1909-
iim._x_interpolant._i,
1910-
iim._k_interpolant._i,
1911-
0,
1912-
0,
1913-
iim.gsparams._gsp,
1914-
)
1915-
sbii.calculateMaxK(0) # this call is needed to invoke the C++ code
1916-
return sbii.maxK()
1917-
1918-
print("\n| offset | orig | new via direct C++ | new via galsim II |")
1919-
print("|--------|------------|--------------------|-------------------|")
1900+
print("\n| offset | orig | new |")
1901+
print("|--------|------------|--------------------|")
19201902
for offset in [0, 3, 4, 5, 6, 7]:
19211903
im = galsim.Gaussian(fwhm=0.9 / 0.2).drawImage(scale=1)
1922-
new_im = im.copy().calculate_fft().calculate_inverse_fft()
1923-
np.testing.assert_allclose(im.array, new_im[im.bounds].array, atol=1e-6, rtol=1e-6)
19241904
iim = galsim.InterpolatedImage(im, scale=1)
19251905
orig_maxk = iim.maxk
19261906

@@ -1933,19 +1913,15 @@ def _compute_maxk_cpp(xim, iim):
19331913
# and so we subtract 1
19341914
maxk_ix = np.floor(orig_maxk / kim.scale).astype(int) - 1
19351915
if offset > 0:
1936-
kim[maxk_ix, maxk_ix + offset] = kim[0, 0].real
1916+
val = kim[maxk_ix + offset, maxk_ix]
1917+
kim[maxk_ix + offset, maxk_ix] = val / np.abs(val) * kim[0, 0].real
19371918
new_im = kim.calculate_inverse_fft()
1938-
new_maxk = _compute_maxk_cpp(new_im, iim)
1939-
new_im = new_im[iim._image.bounds]
1940-
1941-
if offset == 0:
1942-
np.testing.assert_allclose(im.array, new_im.array, atol=1e-6, rtol=1e-6)
1919+
new_maxk = galsim.InterpolatedImage(new_im, scale=1, pad_factor=1).maxk
19431920

1944-
print("| % 6d | %10.6f | %18.6f | %17.6f |" % (
1921+
print("| % 6d | %10.6f | %18.6f |" % (
19451922
offset,
19461923
orig_maxk,
1947-
new_maxk,
1948-
galsim.InterpolatedImage(new_im, scale=1).maxk),
1924+
new_maxk),
19491925
)
19501926

19511927
if offset <= 5:
@@ -1955,7 +1931,7 @@ def _compute_maxk_cpp(xim, iim):
19551931
else:
19561932
np.testing.assert_allclose(new_maxk, orig_maxk, atol=1e-12, rtol=0)
19571933

1958-
print("|--------|------------|--------------------|-------------------|")
1934+
print("|--------|------------|--------------------|")
19591935

19601936

19611937
if __name__ == "__main__":

0 commit comments

Comments
 (0)