Note
Go to the end to download the full example code.
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()
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.55it/s]
1%| | 3/256 [00:00<00:35, 7.21it/s]
2%|▏ | 5/256 [00:00<00:37, 6.62it/s]
3%|▎ | 8/256 [00:01<00:30, 8.18it/s]
4%|▎ | 9/256 [00:01<00:33, 7.41it/s]
4%|▍ | 11/256 [00:01<00:25, 9.60it/s]
5%|▌ | 13/256 [00:01<00:30, 8.03it/s]
6%|▌ | 15/256 [00:01<00:29, 8.21it/s]
6%|▋ | 16/256 [00:02<00:31, 7.62it/s]
7%|▋ | 18/256 [00:02<00:24, 9.53it/s]
8%|▊ | 20/256 [00:02<00:27, 8.48it/s]
9%|▊ | 22/256 [00:02<00:28, 8.27it/s]
9%|▉ | 24/256 [00:02<00:26, 8.85it/s]
10%|█ | 26/256 [00:03<00:30, 7.66it/s]
11%|█ | 28/256 [00:03<00:24, 9.39it/s]
12%|█▏ | 30/256 [00:03<00:29, 7.78it/s]
12%|█▎ | 32/256 [00:03<00:23, 9.41it/s]
13%|█▎ | 34/256 [00:04<00:27, 8.06it/s]
14%|█▍ | 36/256 [00:04<00:25, 8.70it/s]
15%|█▍ | 38/256 [00:04<00:25, 8.46it/s]
16%|█▌ | 40/256 [00:04<00:27, 7.77it/s]
16%|█▋ | 42/256 [00:05<00:22, 9.35it/s]
17%|█▋ | 44/256 [00:05<00:27, 7.81it/s]
18%|█▊ | 46/256 [00:05<00:22, 9.46it/s]
19%|█▉ | 48/256 [00:05<00:24, 8.49it/s]
20%|█▉ | 50/256 [00:06<00:23, 8.64it/s]
20%|██ | 52/256 [00:06<00:24, 8.34it/s]
21%|██ | 54/256 [00:06<00:22, 8.85it/s]
21%|██▏ | 55/256 [00:06<00:27, 7.42it/s]
22%|██▏ | 57/256 [00:06<00:22, 8.83it/s]
23%|██▎ | 58/256 [00:07<00:26, 7.47it/s]
23%|██▎ | 60/256 [00:07<00:22, 8.74it/s]
24%|██▍ | 62/256 [00:07<00:25, 7.58it/s]
25%|██▌ | 64/256 [00:07<00:20, 9.40it/s]
26%|██▌ | 66/256 [00:08<00:24, 7.81it/s]
27%|██▋ | 69/256 [00:08<00:23, 7.96it/s]
28%|██▊ | 71/256 [00:08<00:20, 9.22it/s]
29%|██▊ | 73/256 [00:08<00:22, 8.13it/s]
29%|██▉ | 75/256 [00:08<00:19, 9.41it/s]
30%|███ | 77/256 [00:09<00:22, 7.85it/s]
31%|███ | 79/256 [00:09<00:18, 9.48it/s]
32%|███▏ | 81/256 [00:09<00:20, 8.37it/s]
32%|███▏ | 83/256 [00:10<00:21, 8.13it/s]
33%|███▎ | 84/256 [00:10<00:22, 7.67it/s]
34%|███▎ | 86/256 [00:10<00:18, 9.25it/s]
34%|███▍ | 88/256 [00:10<00:18, 8.84it/s]
35%|███▍ | 89/256 [00:10<00:20, 8.12it/s]
36%|███▌ | 91/256 [00:11<00:21, 7.56it/s]
36%|███▌ | 92/256 [00:11<00:20, 7.89it/s]
37%|███▋ | 95/256 [00:11<00:19, 8.08it/s]
38%|███▊ | 97/256 [00:11<00:16, 9.86it/s]
39%|███▊ | 99/256 [00:11<00:19, 7.97it/s]
40%|███▉ | 102/256 [00:12<00:19, 7.75it/s]
41%|████ | 104/256 [00:12<00:16, 8.99it/s]
41%|████▏ | 106/256 [00:12<00:18, 7.92it/s]
42%|████▏ | 108/256 [00:12<00:15, 9.48it/s]
43%|████▎ | 110/256 [00:13<00:18, 7.86it/s]
44%|████▍ | 112/256 [00:13<00:15, 9.42it/s]
45%|████▍ | 114/256 [00:13<00:16, 8.37it/s]
45%|████▌ | 116/256 [00:13<00:15, 8.95it/s]
46%|████▌ | 118/256 [00:14<00:16, 8.29it/s]
47%|████▋ | 120/256 [00:14<00:15, 8.80it/s]
47%|████▋ | 121/256 [00:14<00:17, 7.83it/s]
48%|████▊ | 123/256 [00:14<00:16, 8.02it/s]
49%|████▉ | 125/256 [00:15<00:16, 8.16it/s]
50%|████▉ | 127/256 [00:15<00:15, 8.23it/s]
50%|█████ | 129/256 [00:15<00:15, 8.26it/s]
51%|█████ | 131/256 [00:15<00:14, 8.50it/s]
52%|█████▏ | 133/256 [00:15<00:14, 8.52it/s]
53%|█████▎ | 135/256 [00:16<00:14, 8.20it/s]
53%|█████▎ | 136/256 [00:16<00:14, 8.01it/s]
54%|█████▍ | 138/256 [00:16<00:12, 9.52it/s]
55%|█████▍ | 140/256 [00:16<00:14, 8.11it/s]
55%|█████▌ | 142/256 [00:17<00:14, 7.80it/s]
56%|█████▋ | 144/256 [00:17<00:11, 9.40it/s]
57%|█████▋ | 146/256 [00:17<00:13, 8.42it/s]
57%|█████▋ | 147/256 [00:17<00:13, 8.07it/s]
58%|█████▊ | 149/256 [00:17<00:12, 8.87it/s]
59%|█████▉ | 151/256 [00:18<00:13, 7.60it/s]
60%|█████▉ | 153/256 [00:18<00:11, 8.74it/s]
61%|██████ | 155/256 [00:18<00:13, 7.68it/s]
61%|██████▏ | 157/256 [00:18<00:10, 9.44it/s]
62%|██████▏ | 159/256 [00:19<00:12, 7.95it/s]
63%|██████▎ | 161/256 [00:19<00:10, 9.31it/s]
64%|██████▎ | 163/256 [00:19<00:10, 8.80it/s]
64%|██████▍ | 165/256 [00:19<00:10, 8.87it/s]
65%|██████▌ | 167/256 [00:19<00:10, 8.63it/s]
66%|██████▌ | 168/256 [00:20<00:10, 8.21it/s]
66%|██████▋ | 170/256 [00:20<00:10, 7.84it/s]
67%|██████▋ | 172/256 [00:20<00:11, 7.39it/s]
68%|██████▊ | 174/256 [00:20<00:10, 8.11it/s]
69%|██████▉ | 176/256 [00:21<00:09, 8.76it/s]
70%|██████▉ | 178/256 [00:21<00:09, 8.15it/s]
70%|███████ | 180/256 [00:21<00:09, 8.12it/s]
71%|███████ | 182/256 [00:21<00:08, 8.37it/s]
72%|███████▏ | 184/256 [00:22<00:08, 8.32it/s]
72%|███████▏ | 185/256 [00:22<00:08, 8.39it/s]
73%|███████▎ | 187/256 [00:22<00:07, 8.83it/s]
73%|███████▎ | 188/256 [00:22<00:08, 7.66it/s]
74%|███████▍ | 190/256 [00:22<00:06, 9.82it/s]
75%|███████▌ | 192/256 [00:23<00:08, 7.92it/s]
76%|███████▌ | 194/256 [00:23<00:06, 8.87it/s]
77%|███████▋ | 196/256 [00:23<00:07, 7.98it/s]
77%|███████▋ | 198/256 [00:23<00:07, 7.99it/s]
78%|███████▊ | 199/256 [00:23<00:07, 7.80it/s]
79%|███████▊ | 201/256 [00:24<00:05, 9.73it/s]
79%|███████▉ | 203/256 [00:24<00:06, 8.44it/s]
80%|████████ | 205/256 [00:24<00:06, 8.07it/s]
80%|████████ | 206/256 [00:24<00:06, 8.10it/s]
81%|████████▏ | 208/256 [00:24<00:06, 7.86it/s]
82%|████████▏ | 210/256 [00:25<00:05, 7.98it/s]
83%|████████▎ | 212/256 [00:25<00:05, 8.13it/s]
84%|████████▎ | 214/256 [00:25<00:04, 8.61it/s]
84%|████████▍ | 216/256 [00:25<00:04, 8.14it/s]
85%|████████▌ | 218/256 [00:26<00:04, 8.16it/s]
86%|████████▌ | 220/256 [00:26<00:04, 7.87it/s]
87%|████████▋ | 222/256 [00:26<00:04, 7.65it/s]
88%|████████▊ | 224/256 [00:26<00:03, 8.49it/s]
88%|████████▊ | 226/256 [00:27<00:03, 7.68it/s]
89%|████████▉ | 229/256 [00:27<00:03, 8.99it/s]
90%|████████▉ | 230/256 [00:27<00:03, 7.79it/s]
91%|█████████ | 232/256 [00:27<00:02, 9.34it/s]
91%|█████████▏| 234/256 [00:28<00:02, 7.71it/s]
93%|█████████▎| 237/256 [00:28<00:02, 7.83it/s]
94%|█████████▍| 240/256 [00:28<00:01, 8.87it/s]
94%|█████████▍| 241/256 [00:29<00:01, 7.81it/s]
95%|█████████▍| 243/256 [00:29<00:01, 9.19it/s]
96%|█████████▌| 245/256 [00:29<00:01, 9.10it/s]
96%|█████████▌| 246/256 [00:29<00:01, 8.26it/s]
97%|█████████▋| 248/256 [00:29<00:00, 8.49it/s]
98%|█████████▊| 250/256 [00:30<00:00, 8.15it/s]
98%|█████████▊| 252/256 [00:30<00:00, 8.82it/s]
99%|█████████▉| 253/256 [00:30<00:00, 7.26it/s]
100%|██████████| 256/256 [00:30<00:00, 9.88it/s]
100%|██████████| 256/256 [00:30<00:00, 8.36it/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()
Total running time of the script: (0 minutes 43.044 seconds)