Skip to content

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

Open
felipemunoz8128 wants to merge 3 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 3 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/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 302-306 529 534 539

Minimum allowed coverage is 94%

Generated by 🐒 cobertura-action against 3a571cd

@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