Fix/tilt weighted wedge ctf centering#362
Merged
McHaillet merged 5 commits intoJul 16, 2026
Merged
Conversation
…adial grid _create_tilt_weighted_wedge() mirrored a reduced-form CTF into a full non-reduced 2D plane by hand (flip + concatenate) before rotating it into the 3D wedge. That reconstruction placed the zero frequency at index image_size // 2 - 1 instead of image_size // 2, one pixel off from the volume's rotation center and from the x-axis convention used everywhere else, causing an asymmetric per-tilt CTF contribution whenever ctf_params_per_tilt was supplied. Generalize radial_reduced_grid() into radial_grid(shape, reduced, fftshifted, shape_is_reduced), which can directly produce a full (non-reduced) grid with the zero frequency centered or in the corner. create_ctf() gains matching reduced/fftshifted parameters. This lets _create_tilt_weighted_wedge() build the correctly centered CTF plane directly instead of manually mirroring it, and lets the Gaussian low/high/band-pass filters, radial_average(), and profile_to_weighting() drop their now-redundant trailing fftshift/ifftshift calls, since radial_grid() defaults to the natural (corner-origin) rfftn layout they all need. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The rotate/crop/flip step in _create_tilt_weighted_wedge that turns the full-size rotated tilt plane back into reduced Fourier form was inlined and easy to misread. Pull it into a small private helper with a docstring that explains why the flip is required: for even box sizes the Nyquist bin is aliased and only stored at index 0 of the fftshifted array, so a plain forward slice from the center would silently drop it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Collaborator
Author
|
Maybe easier to merge this before #359 BTW |
|
Minimum allowed coverage is Generated by 🐒 cobertura-action against c8582f4 |
sroet
requested changes
Jul 16, 2026
sroet
left a comment
Collaborator
There was a problem hiding this comment.
LGTM very nice reduction of complexity! one some comment(s)
Also, as this is changing the default behavior and API of our code, please update the version accordingly
# Conflicts: # src/pytom_tm/weights.py
- radial_grid's last_axis() used a float step in np.arange, which is unnecessary since the values are divided by an int afterwards (review nitpick from sroet). - Bump version to 0.14.0 since radial_reduced_grid was renamed to radial_grid with a changed signature/default, and create_ctf's signature changed too - both are public API changes. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
sroet
approved these changes
Jul 16, 2026
sroet
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, feel free to merge on green
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I want to make a PR later that addresses #352, which needs to modify the rotations of CTFs to create the tilt weighted wedge. I read through that function and found it quite unreadable, so I made a few updates that hopefully improve readability.
I also noticed that the radial grid is created with its center in the middle of images/volumes, which means all the CTF and bandpass filters need to shift it back. It makes much more sense to do this at the grid creation already.