Apple Picker

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

import os

import matplotlib.pyplot as plt
import mrcfile

from aspire.apple.apple import Apple

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:46,  2.40it/s]
  2%|▏         | 4/256 [00:00<00:31,  7.90it/s]
  2%|▏         | 6/256 [00:00<00:36,  6.84it/s]
  3%|▎         | 8/256 [00:01<00:35,  6.91it/s]
  4%|▍         | 10/256 [00:01<00:32,  7.56it/s]
  5%|▍         | 12/256 [00:01<00:30,  7.93it/s]
  5%|▌         | 13/256 [00:01<00:31,  7.68it/s]
  5%|▌         | 14/256 [00:01<00:30,  8.03it/s]
  6%|▋         | 16/256 [00:02<00:29,  8.15it/s]
  7%|▋         | 17/256 [00:02<00:36,  6.58it/s]
  8%|▊         | 20/256 [00:02<00:30,  7.62it/s]
  8%|▊         | 21/256 [00:02<00:31,  7.50it/s]
  9%|▉         | 24/256 [00:03<00:33,  6.99it/s]
 11%|█         | 27/256 [00:03<00:24,  9.38it/s]
 11%|█▏        | 29/256 [00:03<00:29,  7.82it/s]
 12%|█▏        | 31/256 [00:03<00:24,  9.08it/s]
 13%|█▎        | 33/256 [00:04<00:31,  7.08it/s]
 14%|█▎        | 35/256 [00:04<00:25,  8.63it/s]
 14%|█▍        | 37/256 [00:04<00:29,  7.52it/s]
 15%|█▌        | 39/256 [00:05<00:27,  8.01it/s]
 16%|█▌        | 40/256 [00:05<00:31,  6.92it/s]
 16%|█▋        | 42/256 [00:05<00:24,  8.71it/s]
 17%|█▋        | 44/256 [00:05<00:25,  8.25it/s]
 18%|█▊        | 46/256 [00:05<00:25,  8.15it/s]
 18%|█▊        | 47/256 [00:06<00:28,  7.34it/s]
 19%|█▉        | 49/256 [00:06<00:26,  7.68it/s]
 20%|█▉        | 51/256 [00:06<00:26,  7.78it/s]
 20%|██        | 52/256 [00:06<00:25,  8.03it/s]
 21%|██        | 53/256 [00:06<00:25,  8.08it/s]
 21%|██▏       | 55/256 [00:07<00:23,  8.38it/s]
 22%|██▏       | 56/256 [00:07<00:23,  8.58it/s]
 22%|██▏       | 57/256 [00:07<00:28,  6.87it/s]
 23%|██▎       | 59/256 [00:07<00:22,  8.90it/s]
 23%|██▎       | 60/256 [00:07<00:26,  7.32it/s]
 24%|██▍       | 61/256 [00:07<00:24,  7.82it/s]
 24%|██▍       | 62/256 [00:08<00:25,  7.67it/s]
 25%|██▌       | 64/256 [00:08<00:23,  8.31it/s]
 26%|██▌       | 66/256 [00:08<00:24,  7.74it/s]
 26%|██▌       | 67/256 [00:08<00:24,  7.78it/s]
 27%|██▋       | 69/256 [00:08<00:22,  8.42it/s]
 27%|██▋       | 70/256 [00:09<00:26,  6.97it/s]
 28%|██▊       | 72/256 [00:09<00:19,  9.21it/s]
 29%|██▉       | 74/256 [00:09<00:25,  7.09it/s]
 30%|███       | 77/256 [00:09<00:23,  7.76it/s]
 31%|███       | 79/256 [00:10<00:23,  7.50it/s]
 32%|███▏      | 81/256 [00:10<00:22,  7.92it/s]
 32%|███▏      | 83/256 [00:10<00:21,  8.04it/s]
 33%|███▎      | 85/256 [00:10<00:20,  8.22it/s]
 34%|███▍      | 87/256 [00:11<00:22,  7.37it/s]
 35%|███▍      | 89/256 [00:11<00:19,  8.54it/s]
 36%|███▌      | 91/256 [00:11<00:22,  7.41it/s]
 36%|███▋      | 93/256 [00:11<00:18,  8.81it/s]
 37%|███▋      | 95/256 [00:12<00:18,  8.49it/s]
 38%|███▊      | 96/256 [00:12<00:21,  7.28it/s]
 38%|███▊      | 98/256 [00:12<00:21,  7.52it/s]
 39%|███▉      | 100/256 [00:12<00:19,  7.84it/s]
 40%|███▉      | 102/256 [00:13<00:19,  7.74it/s]
 41%|████      | 104/256 [00:13<00:19,  7.81it/s]
 41%|████▏     | 106/256 [00:13<00:19,  7.76it/s]
 42%|████▏     | 108/256 [00:13<00:19,  7.67it/s]
 43%|████▎     | 109/256 [00:14<00:18,  7.86it/s]
 43%|████▎     | 110/256 [00:14<00:19,  7.65it/s]
 44%|████▍     | 112/256 [00:14<00:17,  8.30it/s]
 45%|████▍     | 114/256 [00:14<00:19,  7.17it/s]
 45%|████▌     | 116/256 [00:14<00:16,  8.67it/s]
 46%|████▌     | 117/256 [00:15<00:19,  7.16it/s]
 46%|████▋     | 119/256 [00:15<00:18,  7.60it/s]
 47%|████▋     | 121/256 [00:15<00:17,  7.74it/s]
 48%|████▊     | 122/256 [00:15<00:16,  7.98it/s]
 48%|████▊     | 123/256 [00:15<00:16,  8.20it/s]
 49%|████▉     | 125/256 [00:16<00:18,  7.05it/s]
 50%|████▉     | 127/256 [00:16<00:14,  9.07it/s]
 50%|█████     | 129/256 [00:16<00:17,  7.16it/s]
 52%|█████▏    | 132/256 [00:17<00:18,  6.77it/s]
 52%|█████▏    | 134/256 [00:17<00:14,  8.32it/s]
 53%|█████▎    | 136/256 [00:17<00:16,  7.34it/s]
 54%|█████▍    | 139/256 [00:17<00:13,  8.48it/s]
 55%|█████▌    | 141/256 [00:18<00:14,  8.18it/s]
 56%|█████▌    | 143/256 [00:18<00:15,  7.35it/s]
 57%|█████▋    | 145/256 [00:18<00:12,  8.75it/s]
 57%|█████▋    | 147/256 [00:18<00:14,  7.32it/s]
 59%|█████▊    | 150/256 [00:19<00:12,  8.33it/s]
 59%|█████▉    | 151/256 [00:19<00:14,  7.27it/s]
 60%|█████▉    | 153/256 [00:19<00:11,  8.99it/s]
 61%|██████    | 155/256 [00:19<00:12,  8.15it/s]
 61%|██████▏   | 157/256 [00:20<00:12,  8.17it/s]
 62%|██████▏   | 158/256 [00:20<00:12,  7.56it/s]
 62%|██████▎   | 160/256 [00:20<00:12,  7.49it/s]
 63%|██████▎   | 161/256 [00:20<00:12,  7.60it/s]
 63%|██████▎   | 162/256 [00:20<00:11,  7.93it/s]
 64%|██████▍   | 164/256 [00:21<00:11,  7.81it/s]
 64%|██████▍   | 165/256 [00:21<00:11,  8.05it/s]
 65%|██████▌   | 167/256 [00:21<00:11,  7.60it/s]
 66%|██████▌   | 169/256 [00:21<00:11,  7.57it/s]
 67%|██████▋   | 171/256 [00:21<00:10,  7.79it/s]
 68%|██████▊   | 173/256 [00:22<00:10,  8.16it/s]
 68%|██████▊   | 174/256 [00:22<00:10,  7.97it/s]
 68%|██████▊   | 175/256 [00:22<00:10,  8.04it/s]
 69%|██████▉   | 177/256 [00:22<00:10,  7.84it/s]
 70%|██████▉   | 179/256 [00:23<00:10,  7.05it/s]
 70%|███████   | 180/256 [00:23<00:10,  7.48it/s]
 71%|███████   | 182/256 [00:23<00:07,  9.48it/s]
 72%|███████▏  | 184/256 [00:23<00:09,  7.75it/s]
 73%|███████▎  | 186/256 [00:23<00:08,  8.30it/s]
 73%|███████▎  | 187/256 [00:24<00:09,  7.06it/s]
 74%|███████▍  | 189/256 [00:24<00:07,  8.92it/s]
 75%|███████▍  | 191/256 [00:24<00:08,  7.68it/s]
 75%|███████▌  | 193/256 [00:24<00:08,  7.36it/s]
 76%|███████▌  | 195/256 [00:24<00:06,  8.80it/s]
 77%|███████▋  | 197/256 [00:25<00:07,  7.48it/s]
 78%|███████▊  | 199/256 [00:25<00:07,  7.65it/s]
 78%|███████▊  | 200/256 [00:25<00:07,  7.23it/s]
 79%|███████▉  | 203/256 [00:26<00:06,  8.03it/s]
 80%|████████  | 205/256 [00:26<00:06,  7.63it/s]
 81%|████████  | 207/256 [00:26<00:06,  7.67it/s]
 82%|████████▏ | 209/256 [00:26<00:05,  8.09it/s]
 82%|████████▏ | 211/256 [00:27<00:05,  7.97it/s]
 83%|████████▎ | 213/256 [00:27<00:05,  7.43it/s]
 84%|████████▍ | 215/256 [00:27<00:05,  7.91it/s]
 85%|████████▍ | 217/256 [00:27<00:05,  7.62it/s]
 86%|████████▌ | 219/256 [00:28<00:04,  7.71it/s]
 86%|████████▌ | 220/256 [00:28<00:04,  7.81it/s]
 87%|████████▋ | 222/256 [00:28<00:03,  8.59it/s]
 87%|████████▋ | 223/256 [00:28<00:04,  7.62it/s]
 88%|████████▊ | 225/256 [00:28<00:04,  7.27it/s]
 89%|████████▊ | 227/256 [00:29<00:03,  9.18it/s]
 89%|████████▉ | 229/256 [00:29<00:03,  7.22it/s]
 90%|█████████ | 231/256 [00:29<00:02,  8.82it/s]
 91%|█████████ | 233/256 [00:29<00:03,  7.65it/s]
 92%|█████████▏| 235/256 [00:30<00:02,  7.52it/s]
 92%|█████████▏| 236/256 [00:30<00:02,  7.23it/s]
 93%|█████████▎| 238/256 [00:30<00:02,  8.95it/s]
 94%|█████████▍| 240/256 [00:30<00:01,  8.89it/s]
 95%|█████████▍| 242/256 [00:31<00:01,  7.04it/s]
 95%|█████████▌| 244/256 [00:31<00:01,  8.48it/s]
 96%|█████████▌| 246/256 [00:31<00:01,  7.76it/s]
 97%|█████████▋| 248/256 [00:31<00:01,  7.90it/s]
 97%|█████████▋| 249/256 [00:31<00:01,  6.90it/s]
 98%|█████████▊| 252/256 [00:32<00:00,  8.31it/s]
 99%|█████████▉| 253/256 [00:32<00:00,  7.12it/s]
100%|██████████| 256/256 [00:32<00:00,  9.33it/s]
100%|██████████| 256/256 [00:32<00:00,  7.84it/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]
print(f"Dimensions of the micrograph are {img_dim}")
print(f"{particles} particles were picked")

plt.imshow(particles_img, cmap="gray")
plt.show()
apple picker
Dimensions of the micrograph are (4096, 4096)
461 particles were picked

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

Gallery generated by Sphinx-Gallery