.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_tutorials/pipeline_demo.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_pipeline_demo.py: Ab-initio Pipeline Demonstration ================================ This tutorial demonstrates some key components of an ab-initio reconstruction pipeline using synthetic data generated with ASPIRE's ``Simulation`` class of objects. .. GENERATED FROM PYTHON SOURCE LINES 11-20 Download an Example Volume -------------------------- We begin by downloading a high resolution volume map of the 80S Ribosome, sourced from EMDB: https://www.ebi.ac.uk/emdb/EMD-2660. This is one of several volume maps that can be downloaded with ASPIRE's data downloading utility by using the following import. sphinx_gallery_start_ignore flake8: noqa sphinx_gallery_end_ignore .. GENERATED FROM PYTHON SOURCE LINES 20-29 .. code-block:: Python from aspire.downloader import emdb_2660 # Load 80s Ribosome as a ``Volume`` object. original_vol = emdb_2660() # Downsample the volume res = 41 vol = original_vol.downsample(res) .. GENERATED FROM PYTHON SOURCE LINES 30-35 .. note:: A ``Volume`` can be saved using the ``Volume.save()`` method as follows:: fn = f"downsampled_80s_ribosome_size{res}.mrc" vol.save(fn, overwrite=True) .. GENERATED FROM PYTHON SOURCE LINES 38-45 Create a Simulation Source -------------------------- ASPIRE's ``Simulation`` class can be used to generate a synthetic dataset of projection images. A ``Simulation`` object produces random projections of a supplied Volume and applies noise and CTF filters. The resulting stack of 2D images is stored in an ``Image`` object. .. GENERATED FROM PYTHON SOURCE LINES 48-54 CTF Filters ^^^^^^^^^^^^^^^^^^^^^ Let's start by creating CTF filters. The ``operators`` package contains a collection of filter classes that can be supplied to a ``Simulation``. We use ``RadialCTFFilter`` to generate a set of CTF filters with various defocus values. .. GENERATED FROM PYTHON SOURCE LINES 54-70 .. code-block:: Python # Create CTF filters import numpy as np from aspire.operators import RadialCTFFilter # Radial CTF Filter defocus_min = 15000 # unit is angstroms defocus_max = 25000 defocus_ct = 7 ctf_filters = [ RadialCTFFilter(pixel_size=vol.pixel_size, defocus=d) for d in np.linspace(defocus_min, defocus_max, defocus_ct) ] .. GENERATED FROM PYTHON SOURCE LINES 71-83 Initialize Simulation Object ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ We feed our ``Volume`` and filters into ``Simulation`` to generate the dataset of images. When controlled white Gaussian noise is desired, ``WhiteNoiseAdder.from_snr()`` can be used to generate a simulation data set around a specific SNR. Alternatively, users can bring their own images using an ``ArrayImageSource``, or define their own custom noise functions via ``Simulation(..., noise_adder=CustomNoiseAdder(...))``. Examples can be found in ``tutorials/class_averaging.py`` and ``experiments/simulated_abinitio_pipeline.py``. .. GENERATED FROM PYTHON SOURCE LINES 83-93 .. code-block:: Python from aspire.noise import WhiteNoiseAdder from aspire.source import Simulation # set parameters n_imgs = 2500 # SNR target for white gaussian noise. snr = 0.5 .. GENERATED FROM PYTHON SOURCE LINES 94-98 .. note:: Note, the SNR value was chosen based on other parameters for this quick tutorial, and can be changed to adjust the power of the additive noise. .. GENERATED FROM PYTHON SOURCE LINES 98-110 .. code-block:: Python # For this ``Simulation`` we set all 2D offset vectors to zero, # but by default offset vectors will be randomly distributed. src = Simulation( n=n_imgs, # number of projections vols=vol, # volume source offsets=0, # Default: images are randomly shifted unique_filters=ctf_filters, noise_adder=WhiteNoiseAdder.from_snr(snr=snr), # desired SNR ) .. rst-class:: sphx-glr-script-out .. code-block:: none 0%| | 0/5 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: pipeline_demo.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: pipeline_demo.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_