Apple Picker

We demonstrate ASPIRE’s particle picking methods using the Apple class.

import logging
import os

import matplotlib.pyplot as plt
import mrcfile

from aspire.apple.apple import Apple

logger = logging.getLogger(__name__)

Read and Plot Micrograph

Here we demonstrate reading in and plotting a raw micrograph.

file_path = os.path.join(
    os.path.dirname(os.getcwd()), "data", "falcon_2012_06_12-14_33_35_0.mrc"
)

with mrcfile.open(file_path, mode="r") as mrc:
    micro_img = mrc.data

plt.title("Sample Micrograph")
plt.imshow(micro_img, cmap="gray")
plt.show()
Sample Micrograph

Initialize Apple

Initiate ASPIRE’s Apple class. Apple admits many options relating to particle sizing and mrc processing.

apple_picker = Apple(
    particle_size=78, min_particle_size=19, max_particle_size=156, tau1=710, tau2=7100
)

Pick Particles and Find Centers

Here we use the process_micrograph method from the Apple class to find particles in the micrograph. It will also return an image suitable for display, and optionally save a jpg.

centers, particles_img = apple_picker.process_micrograph(file_path, create_jpg=True)

# Note that if you only desire ``centers`` you may call ``process_micrograph_centers(file_path,...)``.
  0%|          | 0/256 [00:00<?, ?it/s]
  0%|          | 1/256 [00:00<01:39,  2.57it/s]
  1%|          | 3/256 [00:00<00:35,  7.05it/s]
  2%|▏         | 5/256 [00:00<00:42,  5.88it/s]
  3%|▎         | 8/256 [00:01<00:26,  9.48it/s]
  4%|▍         | 10/256 [00:01<00:31,  7.70it/s]
  5%|▍         | 12/256 [00:01<00:30,  7.93it/s]
  5%|▌         | 14/256 [00:01<00:28,  8.48it/s]
  6%|▌         | 15/256 [00:02<00:33,  7.15it/s]
  7%|▋         | 17/256 [00:02<00:26,  9.06it/s]
  7%|▋         | 19/256 [00:02<00:31,  7.54it/s]
  8%|▊         | 21/256 [00:02<00:28,  8.29it/s]
  9%|▉         | 23/256 [00:02<00:28,  8.16it/s]
 10%|▉         | 25/256 [00:03<00:28,  8.09it/s]
 11%|█         | 27/256 [00:03<00:27,  8.37it/s]
 11%|█▏        | 29/256 [00:03<00:30,  7.54it/s]
 12%|█▏        | 31/256 [00:03<00:24,  9.02it/s]
 13%|█▎        | 33/256 [00:04<00:29,  7.44it/s]
 14%|█▍        | 36/256 [00:04<00:27,  8.04it/s]
 15%|█▍        | 38/256 [00:04<00:26,  8.14it/s]
 15%|█▌        | 39/256 [00:04<00:26,  8.17it/s]
 16%|█▌        | 41/256 [00:05<00:23,  9.17it/s]
 16%|█▋        | 42/256 [00:05<00:28,  7.44it/s]
 17%|█▋        | 44/256 [00:05<00:23,  9.20it/s]
 18%|█▊        | 46/256 [00:05<00:26,  7.95it/s]
 19%|█▉        | 48/256 [00:05<00:22,  9.14it/s]
 20%|█▉        | 50/256 [00:06<00:26,  7.66it/s]
 20%|██        | 52/256 [00:06<00:25,  8.07it/s]
 21%|██        | 53/256 [00:06<00:28,  7.13it/s]
 21%|██        | 54/256 [00:06<00:27,  7.27it/s]
 22%|██▏       | 56/256 [00:07<00:24,  8.28it/s]
 23%|██▎       | 58/256 [00:07<00:24,  8.05it/s]
 23%|██▎       | 60/256 [00:07<00:23,  8.51it/s]
 24%|██▍       | 61/256 [00:07<00:22,  8.73it/s]
 24%|██▍       | 62/256 [00:07<00:26,  7.33it/s]
 25%|██▌       | 64/256 [00:07<00:21,  8.86it/s]
 25%|██▌       | 65/256 [00:08<00:26,  7.10it/s]
 26%|██▌       | 67/256 [00:08<00:20,  9.18it/s]
 27%|██▋       | 69/256 [00:08<00:25,  7.35it/s]
 28%|██▊       | 72/256 [00:09<00:23,  7.67it/s]
 29%|██▉       | 74/256 [00:09<00:19,  9.26it/s]
 30%|██▉       | 76/256 [00:09<00:23,  7.57it/s]
 30%|███       | 78/256 [00:09<00:20,  8.81it/s]
 31%|███▏      | 80/256 [00:09<00:21,  8.32it/s]
 32%|███▏      | 82/256 [00:10<00:19,  8.71it/s]
 32%|███▏      | 83/256 [00:10<00:22,  7.70it/s]
 33%|███▎      | 84/256 [00:10<00:22,  7.74it/s]
 34%|███▎      | 86/256 [00:10<00:19,  8.63it/s]
 34%|███▍      | 87/256 [00:10<00:23,  7.17it/s]
 35%|███▍      | 89/256 [00:11<00:20,  8.12it/s]
 36%|███▌      | 91/256 [00:11<00:20,  8.11it/s]
 36%|███▋      | 93/256 [00:11<00:19,  8.33it/s]
 37%|███▋      | 95/256 [00:11<00:19,  8.07it/s]
 38%|███▊      | 97/256 [00:12<00:18,  8.69it/s]
 38%|███▊      | 98/256 [00:12<00:21,  7.36it/s]
 39%|███▉      | 101/256 [00:12<00:20,  7.46it/s]
 40%|████      | 103/256 [00:12<00:17,  8.67it/s]
 41%|████      | 105/256 [00:13<00:19,  7.68it/s]
 42%|████▏     | 108/256 [00:13<00:17,  8.63it/s]
 43%|████▎     | 109/256 [00:13<00:18,  7.75it/s]
 44%|████▍     | 112/256 [00:14<00:18,  7.62it/s]
 45%|████▍     | 114/256 [00:14<00:16,  8.62it/s]
 45%|████▌     | 116/256 [00:14<00:18,  7.69it/s]
 46%|████▌     | 118/256 [00:14<00:14,  9.27it/s]
 47%|████▋     | 120/256 [00:14<00:17,  7.73it/s]
 48%|████▊     | 122/256 [00:15<00:14,  9.29it/s]
 48%|████▊     | 124/256 [00:15<00:16,  8.09it/s]
 49%|████▉     | 126/256 [00:15<00:15,  8.33it/s]
 50%|████▉     | 127/256 [00:15<00:17,  7.31it/s]
 50%|█████     | 129/256 [00:15<00:14,  8.89it/s]
 51%|█████     | 131/256 [00:16<00:17,  7.30it/s]
 52%|█████▏    | 134/256 [00:16<00:16,  7.43it/s]
 53%|█████▎    | 136/256 [00:16<00:13,  9.01it/s]
 54%|█████▍    | 138/256 [00:17<00:15,  7.40it/s]
 55%|█████▌    | 141/256 [00:17<00:14,  7.84it/s]
 56%|█████▌    | 143/256 [00:17<00:12,  9.18it/s]
 57%|█████▋    | 145/256 [00:18<00:14,  7.53it/s]
 57%|█████▋    | 147/256 [00:18<00:12,  8.73it/s]
 58%|█████▊    | 149/256 [00:18<00:12,  8.26it/s]
 59%|█████▉    | 151/256 [00:18<00:14,  7.36it/s]
 60%|██████    | 154/256 [00:19<00:11,  8.66it/s]
 61%|██████    | 155/256 [00:19<00:13,  7.39it/s]
 61%|██████▏   | 157/256 [00:19<00:11,  8.84it/s]
 62%|██████▏   | 159/256 [00:19<00:11,  8.12it/s]
 63%|██████▎   | 161/256 [00:19<00:10,  8.79it/s]
 63%|██████▎   | 162/256 [00:20<00:12,  7.27it/s]
 64%|██████▍   | 164/256 [00:20<00:09,  9.23it/s]
 65%|██████▍   | 166/256 [00:20<00:12,  7.37it/s]
 66%|██████▌   | 168/256 [00:20<00:09,  8.93it/s]
 66%|██████▋   | 170/256 [00:21<00:11,  7.54it/s]
 67%|██████▋   | 172/256 [00:21<00:09,  9.10it/s]
 68%|██████▊   | 174/256 [00:21<00:10,  7.90it/s]
 69%|██████▉   | 176/256 [00:21<00:10,  7.49it/s]
 70%|██████▉   | 178/256 [00:22<00:08,  9.14it/s]
 70%|███████   | 180/256 [00:22<00:09,  7.61it/s]
 71%|███████   | 182/256 [00:22<00:08,  9.14it/s]
 72%|███████▏  | 184/256 [00:22<00:09,  7.55it/s]
 73%|███████▎  | 186/256 [00:22<00:07,  9.00it/s]
 73%|███████▎  | 188/256 [00:23<00:08,  7.94it/s]
 74%|███████▍  | 190/256 [00:23<00:07,  8.68it/s]
 75%|███████▌  | 192/256 [00:23<00:07,  8.54it/s]
 75%|███████▌  | 193/256 [00:23<00:08,  7.59it/s]
 76%|███████▌  | 195/256 [00:24<00:08,  7.29it/s]
 77%|███████▋  | 197/256 [00:24<00:07,  8.18it/s]
 77%|███████▋  | 198/256 [00:24<00:06,  8.45it/s]
 78%|███████▊  | 199/256 [00:24<00:06,  8.41it/s]
 79%|███████▊  | 201/256 [00:24<00:06,  8.29it/s]
 79%|███████▉  | 202/256 [00:25<00:06,  8.20it/s]
 80%|███████▉  | 204/256 [00:25<00:05,  9.22it/s]
 80%|████████  | 205/256 [00:25<00:07,  7.05it/s]
 80%|████████  | 206/256 [00:25<00:06,  7.49it/s]
 82%|████████▏ | 209/256 [00:25<00:06,  7.55it/s]
 83%|████████▎ | 212/256 [00:26<00:05,  7.87it/s]
 84%|████████▎ | 214/256 [00:26<00:04,  8.96it/s]
 84%|████████▍ | 216/256 [00:26<00:05,  7.71it/s]
 85%|████████▌ | 218/256 [00:26<00:04,  9.00it/s]
 86%|████████▌ | 220/256 [00:27<00:04,  7.85it/s]
 87%|████████▋ | 222/256 [00:27<00:03,  9.25it/s]
 88%|████████▊ | 224/256 [00:27<00:04,  7.64it/s]
 89%|████████▊ | 227/256 [00:28<00:03,  8.30it/s]
 89%|████████▉ | 228/256 [00:28<00:03,  8.39it/s]
 89%|████████▉ | 229/256 [00:28<00:03,  8.40it/s]
 90%|█████████ | 231/256 [00:28<00:03,  8.31it/s]
 91%|█████████ | 233/256 [00:28<00:02,  8.32it/s]
 91%|█████████▏| 234/256 [00:28<00:02,  8.57it/s]
 92%|█████████▏| 235/256 [00:28<00:02,  8.74it/s]
 93%|█████████▎| 237/256 [00:29<00:02,  7.49it/s]
 93%|█████████▎| 239/256 [00:29<00:01,  9.33it/s]
 94%|█████████▍| 241/256 [00:29<00:01,  8.00it/s]
 95%|█████████▍| 243/256 [00:29<00:01,  8.62it/s]
 95%|█████████▌| 244/256 [00:30<00:01,  7.28it/s]
 96%|█████████▌| 246/256 [00:30<00:01,  9.01it/s]
 97%|█████████▋| 248/256 [00:30<00:00,  8.20it/s]
 97%|█████████▋| 249/256 [00:30<00:00,  7.47it/s]
 98%|█████████▊| 252/256 [00:31<00:00,  7.75it/s]
 99%|█████████▉| 254/256 [00:31<00:00,  9.38it/s]
100%|██████████| 256/256 [00:31<00:00,  9.40it/s]
100%|██████████| 256/256 [00:31<00:00,  8.13it/s]

Plot the Picked Particles

Observe the number of particles picked and plot the result from Apple.

img_dim = micro_img.shape
particles = centers.shape[0]
logger.info(f"Dimensions of the micrograph are {img_dim}")
logger.info(f"{particles} particles were picked")

plt.imshow(particles_img, cmap="gray")
plt.show()
apple picker

Total running time of the script: (0 minutes 44.821 seconds)

Gallery generated by Sphinx-Gallery