.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_tutorials/tutorials/cov3d_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_cov3d_simulation.py: Covariance 3D Estimation ======================== This script illustrates the example of Covariance 3D estimation using simulation images generated from Gaussian blob volumes. .. GENERATED FROM PYTHON SOURCE LINES 8-23 .. code-block:: Python import numpy as np from scipy.cluster.vq import kmeans2 from aspire.basis import FBBasis3D from aspire.covariance import CovarianceEstimator from aspire.denoising import src_wiener_coords from aspire.noise import WhiteNoiseEstimator from aspire.operators import RadialCTFFilter from aspire.reconstruction import MeanEstimator from aspire.source.simulation import Simulation from aspire.utils import eigs from aspire.utils.random import Random from aspire.volume import LegacyVolume, Volume .. GENERATED FROM PYTHON SOURCE LINES 24-26 Create Simulation Object ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 26-63 .. code-block:: Python # Specify parameters img_size = 8 # image size in square num_imgs = 1024 # number of images num_eigs = 16 # number of eigen-vectors to keep dtype = np.float32 # Generate a ``Volume`` object for use in the simulation. Here we use a ``LegacyVolume`` and # set C = 3 to generate 3 unique random volumes. vols = LegacyVolume( L=img_size, C=3, dtype=dtype, ).generate() # Create a simulation object with specified filters sim = Simulation( L=img_size, n=num_imgs, vols=vols, unique_filters=[ RadialCTFFilter(pixel_size=10, defocus=d) for d in np.linspace(1.5e4, 2.5e4, 7) ], dtype=dtype, ) # The Simulation object was created using 3 volumes. num_vols = sim.C # Specify the normal FB basis method for expending the 2D images basis = FBBasis3D(img_size) # Estimate the noise variance. This is needed for the covariance estimation step below. noise_estimator = WhiteNoiseEstimator(sim, batch_size=500) noise_variance = noise_estimator.estimate() print(f"Noise Variance = {noise_variance}") .. rst-class:: sphx-glr-script-out .. code-block:: none 0%| | 0/3 [00:00= 0.97 assert clustering_accuracy >= 0.99 .. rst-class:: sphx-glr-script-out .. code-block:: none Population Covariance Spectrum = [11.67564 6.42179 1.759699 1.370867 1.0250142 0.90507495 0.76535636 0.6299399 0.558662 0.52021676 0.4597896 0.417423 0.35928726 0.3185292 0.2915414 0.26145974] Mean (rel. error) = 0.171009823679924 Mean (correlation) = 0.9861127138137817 Covariance (rel. error) = 0.7859532237052917 Covariance (correlation) = 0.6227817535400391 Eigendecomposition (rel. error) = 0.7407597303390503 Clustering (accuracy) = 1.0 Coordinates (mean rel. error) = [[0.15486291 0.15486291 0.2977213 ... 0.15122503 0.2977213 0.15122503] [0.15508513 0.15508513 0.28991634 ... 0.15925645 0.28991634 0.15925645]] Coordinates (mean correlation) = 0.9783612607948894 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 37.341 seconds) .. _sphx_glr_download_auto_tutorials_tutorials_cov3d_simulation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: cov3d_simulation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: cov3d_simulation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: cov3d_simulation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_