.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_focus_ctf.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_focus_ctf.py: Defocus, astigmatism and the CTF ================================ TEM imaging is wave-optical: amorphous carbon shows Thon rings whose spacing follows the defocus and which turn elliptical with objective astigmatism, so autofocus and CTF tools can be tested against known values. .. GENERATED FROM PYTHON SOURCE LINES 9-38 .. image-sg:: /auto_examples/images/sphx_glr_plot_focus_ctf_001.png :alt: defocus -0.5 um, defocus -1.5 um, defocus -1.5 um, astigmatic :srcset: /auto_examples/images/sphx_glr_plot_focus_ctf_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from de_twin import DigitalTwin, ManualClock twin = DigitalTwin("Dense Au on holey C", camera="DESim", clock=ManualClock(), seed=3) twin.column.set("Magnification", 300000) def power_spectrum(image): a = (image - image.mean()) * np.outer(np.hanning(image.shape[0]), np.hanning(image.shape[1])) return np.log1p(np.fft.fftshift(np.abs(np.fft.fft2(a)) ** 2)) settings = [(-0.5, (0.0, 0.0)), (-1.5, (0.0, 0.0)), (-1.5, (0.4, 0.0))] fig, axes = plt.subplots(2, 3, figsize=(10, 6.6)) for col, (df, stig) in enumerate(settings): twin.column.set_defocus_um(df) twin.column.set_objective_stig(*stig) img = twin.flux(twin.request()) ps = power_spectrum(img) axes[0, col].imshow(img, cmap="gray") axes[1, col].imshow(ps, cmap="magma", vmin=np.percentile(ps, 40), vmax=np.percentile(ps, 99.95)) axes[0, col].set_title(f"defocus {df} um" + (", astigmatic" if stig[0] else ""), fontsize=9) for ax in axes[:, col]: ax.axis("off") fig.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.118 seconds) .. _sphx_glr_download_auto_examples_plot_focus_ctf.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_focus_ctf.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_focus_ctf.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_focus_ctf.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_