Skip to content

fix: bug in maxk algorithm for interpolated images#1356

Open
beckermr wants to merge 13 commits intomainfrom
beckermr/fix-maxk-interp-image
Open

fix: bug in maxk algorithm for interpolated images#1356
beckermr wants to merge 13 commits intomainfrom
beckermr/fix-maxk-interp-image

Conversation

@beckermr
Copy link
Copy Markdown
Contributor

@beckermr beckermr commented Apr 29, 2026

This PR fixes a small algorithmic bug in computing maxk for interpolated images.

I verified that the test failed without the bug fix.

@beckermr beckermr marked this pull request as draft April 29, 2026 21:41
Comment thread .github/workflows/ci.yml Outdated
Comment thread tests/test_interpolatedimage.py Outdated
Comment thread tests/test_interpolatedimage.py Outdated
@beckermr beckermr marked this pull request as ready for review April 30, 2026 13:54
@beckermr
Copy link
Copy Markdown
Contributor Author

@rmjarvis This one is ready for review! Getting the tests right was a pain since I don't have a great understand of how to call into the C++ layer properly. Hopefully the comments help explain what I am trying to do. I tried a bunch of versions where I remade new python-level interpolated images, tried comparing maxk for different image rotations/flips/etc. and none of those worked. The test here is a direct test of the details of the algorithm.

@beckermr beckermr requested a review from rmjarvis April 30, 2026 13:56
@beckermr beckermr changed the title fix: bug in maxk algorithm for interpolated fix: bug in maxk algorithm for interpolated images Apr 30, 2026
Comment thread tests/test_interpolatedimage.py Outdated
for offset in [3, 4, 5, 6, 7]:
im = galsim.Gaussian(fwhm=0.9 / 0.2).drawImage(scale=1)
iim = galsim.InterpolatedImage(im, scale=1)
orig_maxk = _compute_maxk_cpp(iim._xim, iim)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just iim.maxk? I would have thought that would call the C++ code for you.

Copy link
Copy Markdown
Contributor Author

@beckermr beckermr Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works for the initial maxk but doesn't come out right for the manipulated image. When I feed the new image back in, the maxk changes, but some how the fourier grid is different and so things don't match as I would expect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is what you get if you try and feed the new image into a new interpolated image object compared to the test I coded up:

offset orig new via direct C++ new via galsim II
3 1.963495 2.159845 3.141593
4 1.963495 2.225295 3.141593
5 1.963495 2.290745 3.141593
6 1.963495 1.963495 3.141593
7 1.963495 1.963495 3.141593

The columns are:

  • offset: the pixel offset
  • orig: the original maxk value (same no matter how it is computed)
  • new via direct C++: new maxk value computed via direct call into the C++ layer
  • new via galsim II: new maxk value by feeding the new image back into an interpolated image

You can see it always returns pi which is really odd. :/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed an update to the test suite that makes this table.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also pushed some code that shows how the FFTs of the images relate given galsim's storage conventions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants