-
Notifications
You must be signed in to change notification settings - Fork 25
ImageSource.save Optics Block #1337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
ca93e2b
initial ImageSource.save with optics block
j-c-c 7f47993
add _rlnImageSize column to metadata when saving.
j-c-c a2e7aa8
Add _rlnImageSize to coordinate source test.
j-c-c 8a6bf92
use rlnImageName to get n_rows
j-c-c 0ea7134
test for sim save with optics block
j-c-c 909fcd5
add _rlnImageDimensionality
j-c-c 2481513
test save/load roundtrip w/ phase_flip.
j-c-c 65dba23
update coord source test
j-c-c c429f24
cleanup
j-c-c 98cf5e1
remove unused var
j-c-c c386447
missing optics fields warning. warning test. code comments.
j-c-c cfa30a8
removed unused import.
j-c-c 06d7b45
deprecate _rlnAmplitude in favor of private __amplitude field.
j-c-c fe65e40
use _aspireAmplitude to retain ampitudes for saved files
j-c-c 56e600b
ensure pixel size is added to mrc header
j-c-c b92c305
test mrc pixel_size in header
j-c-c 118482a
Use defaultdict
j-c-c c56aba5
Remove old file compatibility
j-c-c a0b0a20
Remove _aspireAmplitude from relion_metadata_fields dict.
j-c-c 362c1bd
Test save on source slices
j-c-c 57c6853
Always write an optics block
j-c-c e4dc91c
Gallery example simulation -> relion
j-c-c fff6b7e
clean up gallery
j-c-c 58394be
_aspireMetadata 'no_ctf' tag for missing optics fields. Detect ASPIRE…
j-c-c 873d3ce
test cleanup
j-c-c f13e024
optics group level not_ctf flag
j-c-c f5c334a
clean up gallery
j-c-c 6acb49d
tox
j-c-c 0e8dda6
typo
j-c-c 63e6983
gallery comment update
j-c-c 41adb21
float64 amplitude code comment
j-c-c File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| """ | ||
| Simulated Stack to RELION Reconstruction | ||
| ======================================== | ||
|
|
||
| This experiment shows how to: | ||
|
|
||
| 1. build a synthetic dataset with ASPIRE, | ||
| 2. write the stack via ``ImageSource.save`` so RELION can consume it, and | ||
| 3. call :code:`relion_reconstruct` on the saved STAR file. | ||
| """ | ||
|
|
||
| # %% | ||
| # Imports | ||
| # ------- | ||
|
|
||
| import logging | ||
| from pathlib import Path | ||
|
|
||
| import numpy as np | ||
|
|
||
| from aspire.downloader import emdb_2660 | ||
| from aspire.noise import WhiteNoiseAdder | ||
| from aspire.operators import RadialCTFFilter | ||
| from aspire.source import Simulation | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| # %% | ||
| # Configuration | ||
| # ------------- | ||
| # We set a few parameters to initialize the Simulation. | ||
| # You can safely alter ``n_particles`` (or change the defocus values, etc.) when | ||
| # trying this interactively; the defaults here are chosen for demonstrative purposes. | ||
|
|
||
| output_dir = Path("relion_save_demo") | ||
| output_dir.mkdir(exist_ok=True) | ||
|
|
||
| n_particles = 512 | ||
| snr = 0.5 | ||
| defocus = np.linspace( | ||
| 15000, 25000, 7 | ||
| ) # defocus values for the radial CTF filters (angstroms) | ||
| star_file = f"sim_n{n_particles}.star" | ||
| star_path = output_dir / star_file | ||
|
|
||
| # %% | ||
| # Volume and Filters | ||
| # ------------------ | ||
| # Start from the EMDB-2660 ribosome map and build a small set of radial CTF filters | ||
| # that RELION will recover as optics groups. | ||
|
|
||
| vol = emdb_2660() | ||
| ctf_filters = [RadialCTFFilter(defocus=d) for d in defocus] | ||
|
|
||
|
|
||
| # %% | ||
| # Simulate, Add Noise, Save | ||
| # ------------------------- | ||
| # Initialize the Simulation: | ||
| # mix the CTFs across the stack, add white noise at a target SNR, | ||
| # and write the particles and metadata to a RELION-compatible STAR/MRC stack. | ||
|
|
||
| sim = Simulation( | ||
| n=n_particles, | ||
| vols=vol, | ||
| unique_filters=ctf_filters, | ||
| noise_adder=WhiteNoiseAdder.from_snr(snr), | ||
| ) | ||
| sim.save(star_path, overwrite=True) | ||
|
|
||
|
|
||
| # %% | ||
| # Running ``relion_reconstruct`` | ||
| # ------------------------------ | ||
| # ``relion_reconstruct`` is an external RELION command, so we just show the call. | ||
| # Run this, from the output directory, in a RELION-enabled shell after generating | ||
| # the STAR file above. | ||
|
|
||
| logger.info(f"relion_reconstruct --i {star_file} " f"--o 'relion_recon.mrc' --ctf") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe document why float64.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Added a comment. Thanks!