Prior inspect peaks work#124
Conversation
|
@mgiammar I've implemented the inspect peaks, including frc and frame correlations. |
…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.
84d1ce8 to
5e97fce
Compare
|
@jdickerson95 have updated the TeamTomo dependencies to |
| from torch_motion_correction.deformation_field import ( # pyright: ignore[reportMissingImports] | ||
| DeformationField, | ||
| ) |
| s=self.extracted_box_size, | ||
| dim=(-2, -1), | ||
| ) | ||
| return cast(torch.Tensor, particle_movie.permute(1, 0, 2, 3).contiguous()) |
There was a problem hiding this comment.
Is cast call here necessary?
There was a problem hiding this comment.
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/FrameInspectionManagerplus 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.
| do_random_masking = self.preprocessing_filters.random_fourier_dropout.enabled | ||
| self.preprocessing_filters.random_fourier_dropout.enabled = False | ||
| cumulative_filter_image = self.preprocessing_filters.get_combined_filter( | ||
| ref_img_rfft=image_dft, | ||
| output_shape=image_dft.shape, | ||
| ) | ||
| self.preprocessing_filters.random_fourier_dropout.enabled = do_random_masking |
There was a problem hiding this comment.
Per-frame peak inspection should be updated in concert with the spatial peak inspection program to emit a npz file. May also need to address the underlying manager behavior.
There was a problem hiding this comment.
How does frame inspection play into this results file? Could have a (num_particles, num_frames, ...) array rather than just a (num_particles, ...) array.
| base_euler_angles : torch.Tensor | None, optional | ||
| Per-particle base ZYZ angles the offsets are relative to, shape ``(N, 3)``. |
There was a problem hiding this comment.
Should be a required argument, plus need to add particle defocus as a parameter
| df = self.particle_stack._df # pylint: disable=protected-access | ||
| particle_index = ( | ||
| df["particle_index"].to_numpy() if "particle_index" in df.columns else None | ||
| ) |
There was a problem hiding this comment.
NOTE: This will change with the other large backend refactor PR on dev-1.3 to prevent protected access
No description provided.