Skip to content

Fix/tilt weighted wedge ctf centering#362

Merged
McHaillet merged 5 commits into
SBC-Utrecht:mainfrom
McHaillet:fix/tilt-weighted-wedge-ctf-centering
Jul 16, 2026
Merged

Fix/tilt weighted wedge ctf centering#362
McHaillet merged 5 commits into
SBC-Utrecht:mainfrom
McHaillet:fix/tilt-weighted-wedge-ctf-centering

Conversation

@McHaillet

@McHaillet McHaillet commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

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.

McHaillet and others added 3 commits July 15, 2026 16:39
…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>
@McHaillet

Copy link
Copy Markdown
Collaborator Author

Maybe easier to merge this before #359 BTW

@McHaillet
McHaillet requested a review from sroet July 16, 2026 09:23
@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

File Coverage Missing
All files 95%
src/pytom_tm/extract.py 98% 315-319
src/pytom_tm/io.py 89% 26 46 62 98 130-136 157-161 168 187 224 229 276-278 348 524-532 557
src/pytom_tm/parallel.py 97% 15-16
src/pytom_tm/plotting.py 33% 35-43 47-50 53-69 76-77 97-102 118-126 132-149 164-172 176-193 197-205 209-216 222 228 233 280 303-385 393 396
src/pytom_tm/weights.py 96% 60 300-304 553 558 563
tests/test_angles.py 96% 66-67

Minimum allowed coverage is 94%

Generated by 🐒 cobertura-action against c8582f4

@sroet sroet left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Comment thread src/pytom_tm/weights.py Outdated
McHaillet and others added 2 commits July 16, 2026 12:41
- 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>
@McHaillet
McHaillet requested a review from sroet July 16, 2026 10:49

@sroet sroet left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, feel free to merge on green

@McHaillet
McHaillet merged commit 91825b3 into SBC-Utrecht:main Jul 16, 2026
3 checks passed
@McHaillet
McHaillet deleted the fix/tilt-weighted-wedge-ctf-centering branch July 16, 2026 12:49
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