Skip to content

Restore real-space fourier_cropping in tomography.utils#15

Open
cedriclim1 wants to merge 1 commit into
feat/tomography-inr-fixesfrom
fix/tomo-fourier-cropping
Open

Restore real-space fourier_cropping in tomography.utils#15
cedriclim1 wants to merge 1 commit into
feat/tomography-inr-fixesfrom
fix/tomo-fourier-cropping

Conversation

@cedriclim1

Copy link
Copy Markdown
Owner

Problem

quantem.tomography.utils.fourier_cropping (real-space image in -> centered-FFT crop -> ifft -> real out) was removed when a fourier_cropping with a different contract landed in core/utils/imaging_utils.py (that one expects an already-FFT'd, corner-centered array — it is what imaging/drift.py uses).

Consequences for tomography users:

  • from quantem.tomography.utils import fourier_cropping — used verbatim by tomography tutorials 01 and 02 to bin tilt stacks to 100x100 — now raises ImportError.
  • Naively switching those callers to the core function silently produces garbage: a real-space image fed to the corner-centered crop returns a ~all-zero array (~98.5% zeros on the tutorial data), which then normalizes to q95=0 and NaNs the first backward pass.

Fix

Restore the original real-space implementation in tomography/utils.py (verbatim legacy behavior), with a docstring that explicitly distinguishes it from the core corner-centered variant.

Design alternative considered: instead of restoring the wrapper, the tutorials could be rewritten to call the core function on pre-FFT'd input. Restoring the wrapper was chosen because the symbol is public API that external scripts/notebooks (not just the tutorials repo) may import, the two functions serve genuinely different callers, and the legacy semantics (band-limited downsample of a real-space image) are what a tomography preprocessing step wants. Happy to flip to the tutorial-side fix if you prefer.

Evidence

  • New regression tests in tests/tomography/test_utils.py (TestFourierCropping): import works, output matches the legacy implementation bit-for-bit on random input, and a smooth blob stays centered and non-degenerate after cropping. All three fail on the base branch (ImportError) and pass with the fix.
  • Full suite uv run pytest tests --runslow: 432 passed, 1 skipped; only failure is the pre-existing, unrelated test_ptychography.py::TestPtychographyGradientEquivalence (reconstruct() unexpected keyword 'num_iter', fails on base too).
  • ruff check / format clean on touched files.

The tomography utility fourier_cropping (real-space image in, fft -> center
crop -> ifft -> real out) was removed when the corner-centered variant moved
to core.utils.imaging_utils. The two have incompatible contracts: the core
version expects an already-FFT'd corner-centered array, so callers passing
real-space tilt images (tutorials 01/02) either hit an ImportError or, if
switched naively to the core function, get ~all-zero stacks that normalize
to NaN. Restore the original implementation with regression tests covering
import, legacy parity, and non-degenerate real-space output.
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