Skip to content

BUG: preserve negative FFT interpolation weights - #20482

Open
mayanksingh-27 wants to merge 1 commit into
astropy:mainfrom
mayanksingh-27:fix-convolve-fft-negative-kernel-20403
Open

mayanksingh-27 wants to merge 1 commit into
astropy:mainfrom
mayanksingh-27:fix-convolve-fft-negative-kernel-20403

Conversation

@mayanksingh-27

Copy link
Copy Markdown

Description

Fixes #20403.

convolve_fft() could return 0.0 instead of an interpolated value when all of the following were true:

  • nan_treatment="interpolate" was used,
  • the input contained a NaN, and
  • the normalized kernel contained negative coefficients.

Before

The FFT interpolation path computes a per-pixel normalization weight. The code treated every weight smaller than a tiny positive threshold as “no weight” and replaced that output with zero.

That condition also matched valid negative weights produced by kernels with negative coefficients. As a result, valid interpolation results were discarded.

For the reproduction in #20403:

  • convolve(...) returned 26.666666666666668
  • convolve_fft(...) returned 0.0

After

The code now treats only weights whose absolute value is close to zero as absent. Valid negative weights are retained and used for normalization.

With the same input:

  • convolve(...) returns 26.666666666666668
  • convolve_fft(...) returns 26.666666666666664

The tiny difference is normal floating-point FFT precision.

Code changes

  • Updated the no-weight check in convolve_fft() to use the absolute normalization weight.
  • Added a regression test using a NaN-containing image and a normalized kernel with negative coefficients.
  • Added a convolution changelog entry.

Verification

I reproduced the issue locally against the latest main branch before making the change.

Tests run:

  • New regression test for negative interpolation weights
  • Full astropy/convolution/tests/test_convolve_fft.py suite: 620 passed

AI Disclosure

I used Codex (GPT-5) to help inspect the repository, explain the contributing guidance, assist with the initial code and test draft, and format this pull request description.

I reproduced the issue locally, reviewed the final code and tests, ran the verification commands, and take full responsibility for this pull request and all reviewer interactions.

  • I certify that I am human and that I take full responsibility for this pull request including all interactions with reviewers.

Merge method

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@mayanksingh-27

Copy link
Copy Markdown
Author

Used AI for writing the description of this pr(codex)

@pllim pllim added this to the v8.1.0 milestone Sep 25, 2026

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

convolve_fft with nan_treatment="interpolate" returns 0 instead of an interpolated value when the kernel has negative coefficients

2 participants