Skip to content

Commit 35eabbf

Browse files
committed
cleanup pixel_sizes in CTF tutorial
1 parent 72e06c8 commit 35eabbf

File tree

1 file changed

+11
-19
lines changed
  • gallery/tutorials/tutorials

1 file changed

+11
-19
lines changed

gallery/tutorials/tutorials/ctf.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@
2424
# Image size to use throughout the demo.
2525
IMG_SIZE = 512
2626

27-
# Pixel size in Angstrom
28-
pixel_size = 0.5
29-
30-
# %%
31-
# .. note::
32-
# Pixel size was chosen to demonstrate effects similar to lecture notes,
33-
# but at a higher resolution.
34-
3527

3628
# %%
3729
# Visualizing the CTF
@@ -59,7 +51,7 @@
5951
# The CTF filter can be visualized as an image once it is evaluated at a specific resolution.
6052
# More specifically the following code will return a transfer function as an array,
6153
# which is then plotted.
62-
rctf_fn = radial_ctf_filter.evaluate_grid(IMG_SIZE, pixel_size=pixel_size)
54+
rctf_fn = radial_ctf_filter.evaluate_grid(IMG_SIZE, pixel_size=1)
6355
plt.imshow(rctf_fn)
6456
plt.colorbar()
6557
plt.show()
@@ -84,7 +76,7 @@
8476
)
8577

8678
# Again, we plot it, and note the difference from the RadialCTFFilter.
87-
plt.imshow(ctf_filter.evaluate_grid(IMG_SIZE, pixel_size=pixel_size))
79+
plt.imshow(ctf_filter.evaluate_grid(IMG_SIZE, pixel_size=1))
8880
plt.colorbar()
8981
plt.show()
9082

@@ -97,7 +89,7 @@
9789
# array returned by ASPIRE's ``CTFFilter.evaluate_grid``.
9890

9991

100-
ctf_sign = np.sign(radial_ctf_filter.evaluate_grid(IMG_SIZE, pixel_size=pixel_size))
92+
ctf_sign = np.sign(radial_ctf_filter.evaluate_grid(IMG_SIZE, pixel_size=1))
10193
plt.imshow(ctf_sign)
10294
plt.colorbar()
10395
plt.show()
@@ -147,7 +139,7 @@ def generate_example_image(L, noise_variance=0.1):
147139
return img
148140

149141

150-
img = Image(generate_example_image(IMG_SIZE), pixel_size=pixel_size)
142+
img = Image(generate_example_image(IMG_SIZE), pixel_size=1)
151143
img.show()
152144

153145

@@ -172,7 +164,7 @@ def generate_example_image(L, noise_variance=0.1):
172164
# Generate images corrupted by progressively increasing defocus.
173165

174166
# For each defocus, apply filter to the base image.
175-
imgs = Image(np.empty((len(defoci), IMG_SIZE, IMG_SIZE)), pixel_size=pixel_size)
167+
imgs = Image(np.empty((len(defoci), IMG_SIZE, IMG_SIZE)), pixel_size=1)
176168
for i, ctf in enumerate(ctf_filters):
177169
imgs[i] = img.filter(ctf)[0]
178170
imgs.show()
@@ -190,13 +182,13 @@ def generate_example_image(L, noise_variance=0.1):
190182
# Compute the signs of this CTF
191183
# In practice, this would be an estimated CTF,
192184
# but in the demo we have the luxury of using the model CTF that was applied.
193-
signs = np.sign(ctf.evaluate_grid(IMG_SIZE, pixel_size=pixel_size))
185+
signs = np.sign(ctf.evaluate_grid(IMG_SIZE, pixel_size=1))
194186
# Apply to the image in Fourier space.
195187
phase_flipped_imgs_f[i] = signs * imgs_f[i]
196188

197189
# Construct the centered 2D FFT of the images.
198190
phase_flipped_imgs = aspire.numeric.fft.centered_ifft2(phase_flipped_imgs_f).real
199-
Image(phase_flipped_imgs, pixel_size=pixel_size).show()
191+
Image(phase_flipped_imgs, pixel_size=1).show()
200192

201193
# %%
202194
# .. warning::
@@ -224,7 +216,7 @@ def generate_example_image(L, noise_variance=0.1):
224216
B=0,
225217
)
226218
# Evaluate Filter, returning a Numpy array.
227-
bad_ctf_fn = bad_est_ctf_filter.evaluate_grid(IMG_SIZE, pixel_size=pixel_size)
219+
bad_ctf_fn = bad_est_ctf_filter.evaluate_grid(IMG_SIZE, pixel_size=1)
228220

229221
c = IMG_SIZE // 2 + 1
230222
plt.plot(rctf_fn[c, c:], label="Model CTF") # radial_ctf_filter
@@ -264,7 +256,7 @@ def generate_example_image(L, noise_variance=0.1):
264256

265257
radial_ctf_est = estimate_ctf(
266258
data_folder=d,
267-
pixel_size=pixel_size,
259+
pixel_size=1,
268260
cs=radial_ctf_filter.Cs,
269261
amplitude_contrast=radial_ctf_filter.alpha,
270262
voltage=radial_ctf_filter.voltage,
@@ -298,7 +290,7 @@ def generate_example_image(L, noise_variance=0.1):
298290
alpha=est["amplitude_contrast"],
299291
B=0,
300292
)
301-
est_ctf_fn = est_ctf.evaluate_grid(IMG_SIZE, pixel_size=pixel_size)
293+
est_ctf_fn = est_ctf.evaluate_grid(IMG_SIZE, pixel_size=1)
302294

303295
# Compare the model CTF with the estimated CTF.
304296
c = IMG_SIZE // 2 + 1
@@ -342,7 +334,7 @@ def generate_example_image(L, noise_variance=0.1):
342334
from aspire.source import Simulation
343335

344336
# Create the Source. ``ctf_filters`` are re-used from earlier section.
345-
src = Simulation(L=64, n=4, unique_filters=ctf_filters, pixel_size=pixel_size)
337+
src = Simulation(L=64, n=4, unique_filters=ctf_filters, pixel_size=1)
346338
src.images[:4].show()
347339

348340
# %%

0 commit comments

Comments
 (0)