Skip to content

Prior inspect peaks work - #124

Merged
mgiammar merged 7 commits into
Lucaslab-Berkeley:development_v1.3from
mgiammar:mdg_inspect_peaks
Jul 28, 2026
Merged

Prior inspect peaks work#124
mgiammar merged 7 commits into
Lucaslab-Berkeley:development_v1.3from
mgiammar:mdg_inspect_peaks

Conversation

@mgiammar

Copy link
Copy Markdown
Member

No description provided.

@jdickerson95
jdickerson95 marked this pull request as ready for review April 30, 2026 20:44
@jdickerson95

Copy link
Copy Markdown
Contributor

@mgiammar I've implemented the inspect peaks, including frc and frame correlations.
I've also updated Leopard-EM to use the new deformation field class, so the tests will definitely fail until a new version of the monorepo is released.

@mgiammar mgiammar added the enhancement New feature or request label May 16, 2026
…uted match-template

Squashed rebuild of the mdg_inspect_peaks PR (Lucaslab-Berkeley#124) on top of
development_v1.3 to remove duplicated upstream history. Tree is
identical to prior branch tip 84d1ce8.
@mgiammar
mgiammar force-pushed the mdg_inspect_peaks branch from 84d1ce8 to 5e97fce Compare June 8, 2026 22:02
@mgiammar

mgiammar commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

@jdickerson95 have updated the TeamTomo dependencies to >=v0.5.2 so those aspects of CI should pass now

Comment thread src/leopard_em/pydantic_models/config/movie_config.py Outdated
Comment thread src/leopard_em/pydantic_models/data_structures/particle_stack.py
Comment thread src/leopard_em/pydantic_models/managers/peak_inspection_manager.py Outdated
Comment thread src/leopard_em/pydantic_models/custom_types.py Outdated
Comment thread src/leopard_em/utils/backend_setup.py Outdated
Comment thread src/leopard_em/utils/image_processing.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a peak-inspection workflow that exposes full local scoring tensors (cross-correlation maps or FRC spectra) for offline inspection, and adds a per-frame inspection manager for movie frame-by-frame scoring with optional fixed whitening/normalization reuse. It also refactors parts of the refine/inspect backend setup for multi-device execution and adds random Fourier dropout support in preprocessing.

Changes:

  • Add PeakInspectionManager / FrameInspectionManager plus CLI examples and config templates for inspecting local score tensors and per-frame results.
  • Extend backend correlation codepaths to optionally skip projection normalization and to compute FRC outputs.
  • Refactor image filtering/normalization utilities and backend setup helpers; add tests to lock in reducer/stacking behavior.

Reviewed changes

Copilot reviewed 29 out of 29 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/pydantic_models/test_particle_stack.py Adds coverage for aligned-movie particle extraction and movie→image stack API behavior.
tests/pydantic_models/test_frame_inspection_manager.py New unit tests for frame inspection reduction/stacking and CSV output behavior.
tests/backend/test_core_refine_template.py New deterministic snapshot test for _reduce_refine_best_zscore.
tests/backend/test_core_match_template.py Avoids division-by-zero in set-overlap assertions.
src/leopard_em/utils/image_processing.py Splits normalization into a reusable get_image_normalization_factor and adds optional precomputed filter/normalization inputs.
src/leopard_em/utils/ctf_utils.py Adds helper to move tensor-valued CTF kwargs onto a target device.
src/leopard_em/utils/backend_setup.py Refactors backend input setup; adds per-frame filter setup helper and deformation-field type updates.
src/leopard_em/pydantic_models/results/match_template_result.py Tweaks error message formatting for write-permission / overwrite checks.
src/leopard_em/pydantic_models/managers/refine_template_manager.py Allows optional template_tensor override and updates deformation-field handling.
src/leopard_em/pydantic_models/managers/peak_inspection_manager.py New manager to run inspect backend and optionally save self-describing outputs.
src/leopard_em/pydantic_models/managers/match_template_manager.py Disables random Fourier dropout for image-side filtering during match-template setup.
src/leopard_em/pydantic_models/managers/frame_inspection_manager.py New per-frame inspection manager (frame iteration, fixed filters, CSV summaries, optional dose-weighting).
src/leopard_em/pydantic_models/managers/init.py Exports the new managers.
src/leopard_em/pydantic_models/data_structures/particle_stack.py Adds per-frame particle movie extraction; updates deformation-field integration and refactors movie extraction internals.
src/leopard_em/pydantic_models/config/movie_config.py Switches deformation field loading to DeformationField.from_csv.
src/leopard_em/pydantic_models/config/correlation_filters.py Adds RandomFourierDropoutConfig and integrates it into combined filters.
src/leopard_em/backend/cross_correlation.py Adds optional projection normalization toggle and implements batched FRC scoring.
src/leopard_em/backend/core_refine_template.py Refactors multi-device tensor movement/stream handling; factors correlation batching and reducer logic.
src/leopard_em/backend/core_differentiable_refine.py Ensures tensor-valued CTF kwargs are moved onto the active device before CTF stack construction.
src/leopard_em/analysis/inspect_peaks.py New inspect backend entrypoint producing full local hypothesis tensors (CC or FRC), multi-device compatible.
src/leopard_em/analysis/inspect_peaks_result.py New save/load helpers for self-describing .npz inspection outputs.
src/leopard_em/analysis/init.py Re-exports inspection result save/load helpers.
pyproject.toml Bumps required Python to 3.11 and updates TeamTomo dependency versions / adds FRC dependency.
programs/inspect_peaks/run_inspect_peaks.py New example script for peak inspection producing a self-describing .npz.
programs/inspect_peaks/run_frame_inspection.py New example script for per-frame inspection producing refine-like CSVs.
programs/inspect_peaks/inspect_peaks_example_config.yaml New example YAML config for peak inspection.
programs/inspect_peaks/frame_inspection_example_config.yaml New example YAML config for per-frame inspection.
.github/workflows/python-publish.yml Updates CI python versions and bumps GitHub release action major version.
.github/workflows/pylint.yml Updates lint workflow python versions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/leopard_em/pydantic_models/managers/match_template_manager.py Outdated
Comment thread programs/inspect_peaks/run_frame_inspection.py
Comment thread src/leopard_em/analysis/inspect_peaks_result.py
Comment thread src/leopard_em/analysis/inspect_peaks_result.py Outdated
Comment thread src/leopard_em/pydantic_models/managers/peak_inspection_manager.py
mgiammar added 2 commits July 28, 2026 12:49
- Introduced per-frame inspection capabilities in `inspect_peaks_result.py`, allowing independent scoring of each movie frame.
- Updated `InspectionResult` to include a `frame_index` for tracking frame-specific results.
- Modified `save_inspection_result` to handle per-frame data, including new axes for frame-specific results.
- Refactored `FrameInspectionManager` to streamline per-frame processing and result collection, including a new method for saving results to `.npz` files.
- Added tests for saving and loading inspection results, ensuring correct handling of both spatial and per-frame data formats.
- Adjusted `PreprocessingFilters` to conditionally apply random Fourier dropout during filter combination.
- Removed unused methods related to cross-correlation peak reduction and CSV output from `FrameInspectionManager`.
@mgiammar
mgiammar merged commit 5ff3055 into Lucaslab-Berkeley:development_v1.3 Jul 28, 2026
8 checks passed
mgiammar added a commit to mgiammar/Leopard-EM that referenced this pull request Aug 12, 2026
* feat: inspect peaks, fourier dropout, frame correlations, and distributed match-template

Squashed rebuild of the mdg_inspect_peaks PR (Lucaslab-Berkeley#124) on top of
development_v1.3 to remove duplicated upstream history. Tree is
identical to prior branch tip 84d1ce8.

* feat: pull out mean/std normalization into z-score from refinement core

* feat: implement peak inspection result saving/loading and refactor related components

* refactor: streamline peak inspection methods

* refactor: major restructuring of the per-frame inspect peaks manager

* Enhance per-frame inspection and result handling

- Introduced per-frame inspection capabilities in `inspect_peaks_result.py`, allowing independent scoring of each movie frame.
- Updated `InspectionResult` to include a `frame_index` for tracking frame-specific results.
- Modified `save_inspection_result` to handle per-frame data, including new axes for frame-specific results.
- Refactored `FrameInspectionManager` to streamline per-frame processing and result collection, including a new method for saving results to `.npz` files.
- Added tests for saving and loading inspection results, ensuring correct handling of both spatial and per-frame data formats.
- Adjusted `PreprocessingFilters` to conditionally apply random Fourier dropout during filter combination.
- Removed unused methods related to cross-correlation peak reduction and CSV output from `FrameInspectionManager`.

* fix: filter warnings raised internally by mrcfile
mgiammar added a commit that referenced this pull request Aug 13, 2026
* ci(dependabot): bump softprops/action-gh-release from 2 to 3 (#122)

Bumps [softprops/action-gh-release](https://github.com/softprops/action-gh-release) from 2 to 3.
- [Release notes](https://github.com/softprops/action-gh-release/releases)
- [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md)
- [Commits](softprops/action-gh-release@v2...v3)

---
updated-dependencies:
- dependency-name: softprops/action-gh-release
  dependency-version: '3'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bugfix to send correlation mean/var to proper devices on multi-GPU refine template (#125)

* (docs) migrate to zensical as build backend

* (docs) API build for zensical

* (docs) update paper ref and citation to published manuscript

* (CI/CD) update deployment pipeline for documentation with zensical

* ci(dependabot): bump codecov/codecov-action from 6 to 7 (#128)

Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 6 to 7.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](codecov/codecov-action@v6...v7)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* (fix): CI/CD disable pre-release install dependencies

* Prior inspect peaks work (#124)

* feat: inspect peaks, fourier dropout, frame correlations, and distributed match-template

Squashed rebuild of the mdg_inspect_peaks PR (#124) on top of
development_v1.3 to remove duplicated upstream history. Tree is
identical to prior branch tip 84d1ce8.

* feat: pull out mean/std normalization into z-score from refinement core

* feat: implement peak inspection result saving/loading and refactor related components

* refactor: streamline peak inspection methods

* refactor: major restructuring of the per-frame inspect peaks manager

* Enhance per-frame inspection and result handling

- Introduced per-frame inspection capabilities in `inspect_peaks_result.py`, allowing independent scoring of each movie frame.
- Updated `InspectionResult` to include a `frame_index` for tracking frame-specific results.
- Modified `save_inspection_result` to handle per-frame data, including new axes for frame-specific results.
- Refactored `FrameInspectionManager` to streamline per-frame processing and result collection, including a new method for saving results to `.npz` files.
- Added tests for saving and loading inspection results, ensuring correct handling of both spatial and per-frame data formats.
- Adjusted `PreprocessingFilters` to conditionally apply random Fourier dropout during filter combination.
- Removed unused methods related to cross-correlation peak reduction and CSV output from `FrameInspectionManager`.

* fix: filter warnings raised internally by mrcfile

* Tracking possible detections via correlation table (and zipfft integration) (#126)

* feat: only update statistics on valid correlation region

Under the standard benchmark setup, this should be excluding ~25% of pixels during the conditional update based on MIP value. Benchmarking the code did not show a significant performance change, however. Statistics updates though are not consuming the majority of computation time.

* feat: add correlation table to multi-GPU match template

* fix: update correlation table for stability

* feat: initial integration with zipFFT

* test: update unit tests for zipFFT consistency

* fix: minor bug fixes for zipfft match template

* fix: changed to mitigate errors on feature integration

* feat: integrate all stats updates together and simplify backend logic

* lint: work towards passing linter

* ci(dependabot): bump softprops/action-gh-release from 2 to 3 (#122)

Bumps [softprops/action-gh-release](https://github.com/softprops/action-gh-release) from 2 to 3.
- [Release notes](https://github.com/softprops/action-gh-release/releases)
- [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md)
- [Commits](softprops/action-gh-release@v2...v3)

---
updated-dependencies:
- dependency-name: softprops/action-gh-release
  dependency-version: '3'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bugfix to send correlation mean/var to proper devices on multi-GPU refine template (#125)

* feat: add CorrelationTable model and integrate into match template results

* test: add basic test coverage for correlation table

* fix: add tensordict dependency and update pytest filterwarnings

* fix: import errors after merge conflict resolution

* feat: add hdf5-backed version of MatchTemplateResult

* feat: integrate into match template manager

* test: add unit tests covering new result functionality

* feat: (untested) initial work on hdf5 backed result formats

* fix: failing CI from old file path attributes

* (fix) resolve edge-case in unit test data setup

* feat: add corr table for distributed backend, address review comments

* feat: add option to skip re-download of example data

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Josh Dickerson <jdickerson@mrc-lmb.cam.ac.uk>

* (docs) add updates to data format sections

* (docs) add information on zipFFT backend

* (docs) restrict documentation dependencies

* (docs) add documentation on inspect peaks/frames

* (docs) remove python 3.10 as supported version

* (lint) fix pylint errors towards allowing CI/CD

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Josh Dickerson <jdickerson@mrc-lmb.cam.ac.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants