|
| 1 | +""" |
| 2 | +Commonlines Method using LUD |
| 3 | +============================ |
| 4 | +
|
| 5 | +This tutorial demonstrates using the Least Unsquared Deviations (LUD) |
| 6 | +commonlines method for estimating particle orientations. This tutorial |
| 7 | +reproduces the "Experiments on simulated images" found in the publication: |
| 8 | +
|
| 9 | +Orientation Determination of Cryo-EM Images Using Least Unsquared Deviations, |
| 10 | +L. Wang, A. Singer, and Z. Wen, SIAM J. Imaging Sciences, 6, 2450-2483 (2013). |
| 11 | +""" |
| 12 | + |
| 13 | +# %% |
| 14 | +# Imports |
| 15 | +# ------- |
| 16 | + |
| 17 | +import logging |
| 18 | +from fractions import Fraction |
| 19 | +from itertools import product |
| 20 | + |
| 21 | +import numpy as np |
| 22 | + |
| 23 | +from aspire.abinitio import CommonlineIRLS, CommonlineLUD |
| 24 | +from aspire.noise import WhiteNoiseAdder |
| 25 | +from aspire.source import Simulation |
| 26 | +from aspire.utils import mean_aligned_angular_distance |
| 27 | +from aspire.volume import Volume |
| 28 | + |
| 29 | +logger = logging.getLogger(__name__) |
| 30 | + |
| 31 | + |
| 32 | +# %% |
| 33 | +# Parameters |
| 34 | +# ---------- |
| 35 | +# Set up some initializing parameters. We will run the LUD algorithm using ADMM |
| 36 | +# and IRLS methods under various spectral norm constraints and levels of noise. |
| 37 | + |
| 38 | +SNR = ["1/8", "1/16", "1/32"] # Signal-to-noise ratio |
| 39 | +METHOD = ["ADMM", "IRLS"] |
| 40 | +ALPHA = [0.90, 0.75, 0.67] # Spectral norm constraint |
| 41 | +n_imgs = 500 # Number of images in our source |
| 42 | +dtype = np.float64 |
| 43 | +pad_size = 129 |
| 44 | + |
| 45 | +# %% |
| 46 | +# Load Volume Map |
| 47 | +# --------------- |
| 48 | +# We will generate simulated noisy images from a low res volume |
| 49 | +# map available in our data folder. This volume map is a 65 x 65 x 65 |
| 50 | +# voxel volume which we intend to upsample to 129 x 129 x 129. |
| 51 | +# To do this we use our ``downsample`` method which, when provided a voxel |
| 52 | +# size larger than the input volume, internally zero-pads in Fourier |
| 53 | +# space to increase the overall shape of the volume. |
| 54 | +vol = ( |
| 55 | + Volume.load("../tutorials/data/clean70SRibosome_vol_65p.mrc") |
| 56 | + .astype(dtype) |
| 57 | + .downsample(pad_size) |
| 58 | +) |
| 59 | +logger.info("Volume map data" f" shape: {vol.shape} dtype:{vol.dtype}") |
| 60 | + |
| 61 | +# %% |
| 62 | +# Generate Noisy Images and Estimate Rotations |
| 63 | +# -------------------------------------------- |
| 64 | +# A ``Simulation`` object is used to generate simulated data at various |
| 65 | +# noise levels. Then rotations are estimated using the ``CommonlineLUD`` and |
| 66 | +# ``CommonlineIRLS`` algorithms. Results are measured by computing the mean |
| 67 | +# aligned angular distance between the ground truth rotations and the globally |
| 68 | +# aligned estimated rotations. |
| 69 | + |
| 70 | +# Build table to dislay results. |
| 71 | +col_width = 21 |
| 72 | +table = [] |
| 73 | +table.append( |
| 74 | + f"{'METHOD':<{col_width}} {'SNR':<{col_width}} {'ALPHA':<{col_width}} {'Mean Angular Distance':<{col_width}}" |
| 75 | +) |
| 76 | +table.append("-" * (col_width * 4)) |
| 77 | + |
| 78 | +for method, snr, alpha in product(METHOD, SNR, ALPHA): |
| 79 | + # Generate a white noise adder with specified SNR. |
| 80 | + noise_adder = WhiteNoiseAdder.from_snr(snr=Fraction(snr)) |
| 81 | + |
| 82 | + # Initialize a Simulation source to generate noisy, centered images. |
| 83 | + src = Simulation( |
| 84 | + n=n_imgs, |
| 85 | + vols=vol, |
| 86 | + offsets=0, |
| 87 | + amplitudes=1, |
| 88 | + noise_adder=noise_adder, |
| 89 | + dtype=dtype, |
| 90 | + ).cache() |
| 91 | + |
| 92 | + # Estimate rotations using the LUD algorithm. |
| 93 | + if method == "ADMM": |
| 94 | + orient_est = CommonlineLUD(src, alpha=alpha) |
| 95 | + else: |
| 96 | + orient_est = CommonlineIRLS(src, alpha=alpha) |
| 97 | + est_rotations = orient_est.estimate_rotations() |
| 98 | + |
| 99 | + # Find the mean aligned angular distance between estimates and ground truth rotations. |
| 100 | + mean_ang_dist = mean_aligned_angular_distance(est_rotations, src.rotations) |
| 101 | + |
| 102 | + # Append results to table. |
| 103 | + table.append( |
| 104 | + f"{method:<{col_width}} {snr:<{col_width}} {str(alpha):<{col_width}} {mean_ang_dist:<{col_width}}" |
| 105 | + ) |
| 106 | + |
| 107 | +# %% |
| 108 | +# Display Results |
| 109 | +# --------------- |
| 110 | +# Display table of results for both methods using various spectral norm |
| 111 | +# constraints and noise levels. |
| 112 | + |
| 113 | +logger.info("\n" + "\n".join(table)) |
0 commit comments