Skip to content

Commit 2ba2058

Browse files
authored
Merge pull request #5 from GalSim-developers/merge-main-fix-tests-1
test: merge latest changes from main into JAX tests
2 parents 4cf0712 + 26f9732 commit 2ba2058

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

src/SBInterpolatedImage.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,9 +1174,11 @@ namespace galsim {
11741174
for(int ix=0; ix<=max_ix; ++ix) {
11751175
xdbg<<"Start search for ix = "<<ix<<std::endl;
11761176
// Search along the two sides with either kx = ix or ky = ix.
1177+
double norm_kval = INFINITY; // something we know is above threshold
1178+
11771179
for(int iy=0; iy<=ix; ++iy) {
11781180
// The bottom side of the square in the lower-right quadrant.
1179-
double norm_kval = fast_norm((*_kimage)(iy,-ix));
1181+
norm_kval = fast_norm((*_kimage)(iy,-ix));
11801182
xdbg<<"norm_kval at "<<iy<<','<<-ix<<" = "<<norm_kval<<std::endl;
11811183
if (norm_kval <= thresh && iy != ix && ix != No2) {
11821184
// The top side of the square in the upper-right quadrant.
@@ -1205,8 +1207,13 @@ namespace galsim {
12051207
}
12061208
}
12071209
xdbg<<"Done ix = "<<ix<<". Current count = "<<n_below_thresh<<std::endl;
1210+
// we can get here either if the loop above finishes normally or if it hits
1211+
// the break statement. So we have to test the last value of norm_kval to
1212+
// see if the break statement was hit. If it was not, then we can increment
1213+
// the counter for the # below thresh.
1214+
if (norm_kval <= thresh) ++n_below_thresh;
12081215
// If we get through 5 rows with nothing above the threshold, stop looking.
1209-
if (++n_below_thresh == 5) break;
1216+
if (n_below_thresh == 5) break;
12101217
}
12111218
xdbg<<"Finished. maxk_ix = "<<maxk_ix<<std::endl;
12121219
// Add 1 to get the first row that is below the threshold.

tests/test_interpolatedimage.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
19331976
if __name__ == "__main__":
19341977
runtests(__file__)

0 commit comments

Comments
 (0)