.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_tutorials/tutorials/orient3d_simulation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_tutorials_tutorials_orient3d_simulation.py: 3D Image Orientation ==================== This script illustrates the estimation of orientation angles using a synchronization matrix and the voting method, based on simulated data projected from a 3D cryo-EM map. .. GENERATED FROM PYTHON SOURCE LINES 8-28 .. code-block:: Python import os import numpy as np from aspire.abinitio import CLSyncVoting from aspire.operators import RadialCTFFilter from aspire.source import OrientedSource, Simulation from aspire.utils import mean_aligned_angular_distance from aspire.volume import Volume file_path = os.path.join( os.path.dirname(os.getcwd()), "data", "clean70SRibosome_vol_65p.mrc" ) print( "This script illustrates orientation estimation using " "synchronization matrix and voting method" ) .. rst-class:: sphx-glr-script-out .. code-block:: none This script illustrates orientation estimation using synchronization matrix and voting method .. GENERATED FROM PYTHON SOURCE LINES 29-31 Initialize Simulation Object and CTF Filters -------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 31-58 .. code-block:: Python # Define a precision for this experiment dtype = np.float32 # Set the sizes of images img_size = 33 # Set the total number of images generated from the 3D map num_imgs = 128 # Specify the CTF parameters not used for this example # but necessary for initializing the simulation object pixel_size = 5 # Pixel size of the images (in angstroms) voltage = 200 # Voltage (in KV) defocus_min = 1.5e4 # Minimum defocus value (in angstroms) defocus_max = 2.5e4 # Maximum defocus value (in angstroms) defocus_ct = 7 # Number of defocus groups. Cs = 2.0 # Spherical aberration alpha = 0.1 # Amplitude contrast print("Initialize simulation object and CTF filters.") # Create CTF filters filters = [ RadialCTFFilter(pixel_size, voltage, defocus=d, Cs=2.0, alpha=0.1) for d in np.linspace(defocus_min, defocus_max, defocus_ct) ] .. rst-class:: sphx-glr-script-out .. code-block:: none Initialize simulation object and CTF filters. .. GENERATED FROM PYTHON SOURCE LINES 59-61 Downsampling ------------ .. GENERATED FROM PYTHON SOURCE LINES 61-71 .. code-block:: Python # Load the map file of a 70S Ribosome and downsample the 3D map to desired resolution. # The downsampling can be done by the internal function of Volume object. print( f"Load 3D map and downsample 3D map to desired grids " f"of {img_size} x {img_size} x {img_size}." ) vols = Volume.load(file_path, dtype=dtype) vols = vols.downsample(img_size) .. rst-class:: sphx-glr-script-out .. code-block:: none Load 3D map and downsample 3D map to desired grids of 33 x 33 x 33. .. GENERATED FROM PYTHON SOURCE LINES 72-74 Create Simulation Object and Obtain True Rotation Angles -------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 74-82 .. code-block:: Python # Create a simulation object with specified filters and the downsampled 3D map print("Use downsampled map to creat simulation object.") sim = Simulation(L=img_size, n=num_imgs, vols=vols, unique_filters=filters, dtype=dtype) print("Get true rotation angles generated randomly by the simulation object.") rots_true = sim.rotations .. rst-class:: sphx-glr-script-out .. code-block:: none Use downsampled map to creat simulation object. Get true rotation angles generated randomly by the simulation object. .. GENERATED FROM PYTHON SOURCE LINES 83-85 Estimate Orientation -------------------- .. GENERATED FROM PYTHON SOURCE LINES 85-102 .. code-block:: Python # Initialize an orientation estimation object and create an # ``OrientedSource`` object to perform viewing angle and image offset # estimation. Here, because of the small image size of the # ``Simulation``, we customize the ``CLSyncVoting`` method to use # fewer theta values when searching for common-lines between pairs of # images. Additionally, since we are processing images with no noise, # we opt not to use a ``fuzzy_mask``, an option that improves # common-line detection in higher noise regimes. print( "Estimate rotation angles and offsets using synchronization matrix and voting method." ) orient_est = CLSyncVoting(sim, n_theta=36, mask=False) oriented_src = OrientedSource(sim, orient_est) rots_est = oriented_src.rotations .. rst-class:: sphx-glr-script-out .. code-block:: none Estimate rotation angles and offsets using synchronization matrix and voting method. Searching over common line pairs: 0%| | 0/8128 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: orient3d_simulation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: orient3d_simulation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_