Skip to content

Fix odd-grid RFFT energy weights#9

Open
rogeriojorge wants to merge 1 commit into
mainfrom
agent/fix-odd-rfft-energy
Open

Fix odd-grid RFFT energy weights#9
rogeriojorge wants to merge 1 commit into
mainfrom
agent/fix-odd-rfft-energy

Conversation

@rogeriojorge

Copy link
Copy Markdown
Member

Summary

  • weight the last RFFT coefficient as a Nyquist singleton only when Nx is even
  • preserve the DC-only Nx=1 case
  • test DC, even-Nyquist, and odd-grid conjugate-pair energies

Root cause

The electromagnetic-energy diagnostic always assigned weight one to the final RFFT coefficient. That is correct for an even grid, where the final coefficient is the Nyquist singleton. For odd Nx, the final retained coefficient still has an omitted negative-frequency conjugate and must have weight two.

Impact

Electromagnetic and total-energy diagnostics now satisfy Parseval weighting for both odd and even Fourier resolutions. This is especially relevant because the supplied SPECTRAX examples commonly use odd Nx values.

Validation

  • python3 -m pytest -q — 6 passed
  • python3 -m flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics — 0
  • physical-space versus RFFT field energy for Nx = 1, 4, 5, 32, 33 — agreement to 7e-16 or better

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
spectrax/_diagnostics.py 74.44% <100.00%> (+0.58%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rogeriojorge rogeriojorge marked this pull request as ready for review July 13, 2026 02:57
@rogeriojorge rogeriojorge force-pushed the agent/fix-odd-rfft-energy branch from b3454d7 to c3a6598 Compare July 16, 2026 13:46
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.

1 participant