Skip to content

CTF estimator refactor - #1416

Open
garrettwrong wants to merge 44 commits into
developfrom
ctfest_tweaks
Open

garrettwrong wants to merge 44 commits into
developfrom
ctfest_tweaks

Conversation

@garrettwrong

@garrettwrong garrettwrong commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Reconciles some errors in the first Python implementation relative to the MATLAB.

  • incorrect taper call
  • model bounds
  • adjusted defaults for number of tapers and psd size

Refactoring:

  • Various optimizations.
  • Adds BFGS (replacement for repeated gd loop, left for repro).
  • Extends to any steerable basis (FFB and FLE under test, others are implemented via ctf tests extension).
  • Implements optional 1D and 2D plots
  • Moves most redundant function args to instance variables
  • Migrates IO into helper function(s)
  • Created main estimate method.
  • Cleanup CLI and main method calls.
  • Parameterize several internal hard-coded params/tols/stop conditions.

Still WIP, some todos.

  • Need to meet with Ayelet to answer a few questions.
  • Need to run against full experimental datasets to get results and times
  • Try with K2 datasets and attempt to implement alt model for K2 if still needed now.

I will probably prefer make a separate PR handling any source integration changes to support a "from micrograph" preprocessing example. Currently this will produce the STAR files on disk which the sources were designed to consume. That design isn't very good IMO, but that's another matter... If source changes bleed into this it will make the PR a bear.

@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.31522% with 43 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.44%. Comparing base (e4a05cc) to head (3da7678).

Files with missing lines Patch % Lines
src/aspire/ctf/ctf_estimator.py 89.50% 38 Missing ⚠️
src/aspire/commands/estimate_ctf.py 0.00% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1416      +/-   ##
===========================================
- Coverage    90.65%   90.44%   -0.21%     
===========================================
  Files          135      135              
  Lines        14932    15044     +112     
===========================================
+ Hits         13537    13607      +70     
- Misses        1395     1437      +42     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@garrettwrong

Copy link
Copy Markdown
Collaborator Author

Ran against several full datasets. Times are great; defocus and astigmatism values look good. Angle appears to be impacted by a transpose somewhere. I'll see if I can sniff that out in the code, but is also easy enough to fix after computed as well. I used the logic below to adjust

-ang - 90 # = (90 - ang) -180 # Transpose axes before arctan - 180

With the various fixes and improvements in place the code appears to work for the majority of one of the problem K2 datasets now, but I will still look at making an alternative model for that case then reach out to Ayelet after.

@garrettwrong

Copy link
Copy Markdown
Collaborator Author

Angle appears to be impacted by a transpose somewhere.

Angle has been resolved in 43a7017.

I'm scheduling a follow up with Ayelet to cover the few questions I had remaining and discuss what I see regarding some of micrographs with poor solutions.... but it won't be for a little bit... Probably this can be reviewed and merged in by then; soI think it would be most efficient to review this larger PR now and just have a smaller one with any followup tweaks or changes for the problem K2 micrographs.

@garrettwrong
garrettwrong requested a review from j-c-c October 23, 2026 14:16

@j-c-c j-c-c 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.

Looks good! Found a few typos (per my contractual obligation), but also a couple small potential bugs.

Comment thread src/aspire/ctf/ctf_estimator.py Resolved
Comment thread src/aspire/ctf/ctf_estimator.py Resolved
Comment thread src/aspire/ctf/ctf_estimator.py Resolved
Comment thread src/aspire/ctf/ctf_estimator.py Resolved
Comment thread src/aspire/ctf/ctf_estimator.py Resolved
Comment thread src/aspire/ctf/ctf_estimator.py Resolved
Comment thread src/aspire/ctf/ctf_estimator.py Resolved
Comment thread src/aspire/ctf/ctf_estimator.py Resolved
Comment thread src/aspire/ctf/ctf_estimator.py Resolved
Comment thread tests/test_CtfEstimate.py Resolved
@garrettwrong
garrettwrong requested a review from j-c-c October 26, 2026 17:05
@garrettwrong
garrettwrong marked this pull request as ready for review October 26, 2026 17:26
@garrettwrong
garrettwrong requested a review from janden as a code owner October 26, 2026 17:26
@garrettwrong garrettwrong changed the title [WIP] CTF estimator refactor CTF estimator refactor Oct 26, 2026

@j-c-c j-c-c 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.

Looks good!

@garrettwrong

Copy link
Copy Markdown
Collaborator Author

Cool, thanks. @janden this one should be ready for you now.

@garrettwrong garrettwrong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

reminder

) # Ensure output_file_dir exists
output_file_prefix = output_file_dir / input_file.stem

with mrcfile.open(input_file, mode="r", permissive=True) as mrc:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Replace this with Image.load or Image._load_raw to handle the warnings from published data with junk headers...

This branch has not been deployed

No deployments
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