Skip to content

Fix divide-by-zero in tilt_increment for duplicate tilt angles - #349

Open
felipemunoz8128 wants to merge 4 commits into
SBC-Utrecht:mainfrom
felipemunoz8128:fix-duplicate-tilt-angle-divide-by-zero
Open

Fix divide-by-zero in tilt_increment for duplicate tilt angles#349
felipemunoz8128 wants to merge 4 commits into
SBC-Utrecht:mainfrom
felipemunoz8128:fix-duplicate-tilt-angle-divide-by-zero

Conversation

@felipemunoz8128

Copy link
Copy Markdown

Fixes #348.

Bidirectional tilt schemes acquire two images at 0° (one per half). When the tilt angle list is sorted, adjacent 0.0 entries produce a pairwise difference of 0, making tilt_increment = 0 and overlap_frequency = inf. This zeros out the ramp filter, the wedge, and all correlation scores.

Fix: Use sorted(set(tilt_angles)) to compute tilt_increment from unique angles only. One line changed. The per-tilt weighting loop is unchanged and still uses all tilts including duplicates for dose/CTF weighting.

Bidirectional tilt schemes acquire two images at 0 degrees (one per
half). When the tilt angle list is sorted, these adjacent 0.0 entries
produce a pairwise difference of 0, making tilt_increment = 0 and
overlap_frequency = inf. This zeros out the ramp filter, the wedge,
and all correlation scores (-1000).

Use sorted(set(tilt_angles)) to compute tilt_increment from unique
angles only. The per-tilt weighting loop is unchanged and still uses
all tilts including duplicates.
@sroet

sroet commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator

Hey @felipemunoz8128, thanks for the fix. It seems small enough and I can understand what issues would pop up.

I am a bit surprised people would be making two 0 degree images, as I don't think you would get any extra information for the extra dose on the sample.

Do you mind adding a test that makes sure this function does not return any NaN/inf when given a set of tilt angles with a duplicate number in it? (can be 0, or a random pre-existing tilt, no real preference from me)

@github-actions

github-actions Bot commented Apr 10, 2026

Copy link
Copy Markdown

File Coverage Missing
All files 95%
src/pytom_tm/io.py 90% 30 50 66 102 134-140 161-165 172 191 228 233 278-279 524-532 557
src/pytom_tm/parallel.py 97% 20-21
src/pytom_tm/plotting.py 33% 36-44 48-51 54-70 77-78 98-103 119-127 133-150 165-173 177-194 198-206 210-217 223 229 234 281 304-384 392 395
src/pytom_tm/weights.py 97% 62 304-308 499 504 509 782
tests/test_angles.py 96% 68-69

Minimum allowed coverage is 94%

Generated by 🐒 cobertura-action against 2953896

@McHaillet

Copy link
Copy Markdown
Collaborator

I am a bit surprised people would be making two 0 degree images, as I don't think you would get any extra information for the extra dose on the sample.

I am also confused by this. I thought one would start at 0 and go to -54, and then go from +3 to +54

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.

Divide-by-zero in tilt_increment with bidirectional tilt series (duplicate 0° angles)

3 participants