{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "46fa1f5a-f9a8-4117-937c-c8a4ebd6c38c", "metadata": { "tags": [ "hide-input" ] }, "outputs": [], "source": [ "%config InlineBackend.rc = {\"figure.dpi\": 72, 'figure.figsize': (6.0, 4.0)}\n", "%matplotlib inline\n", "\n", "import ase\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "from IPython.display import HTML\n", "\n", "import abtem\n", "\n", "abtem.config.set({\"local_diagnostics.progress_bar\": True});" ] }, { "cell_type": "markdown", "id": "3048121d-f027-4cd2-887e-c99016d5da4d", "metadata": {}, "source": [ "(examples:animations)=\n", "# Animations\n", "\n", "*ab*TEM visualizations can be animated over ensemble axes. In this example, we animate a probe over different values of astigmatism. We ramp the astigmatism from $-70 \\ \\mathrm{Å}$ to $70 \\ \\mathrm{Å}$ and back again at an angle of $\\pi / 4$, with a static value for the defocus of $70 \\ \\mathrm{Å}$." ] }, { "cell_type": "code", "execution_count": 2, "id": "3502551c-b81d-4243-b998-4b68ccfe930d", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[########################################] | 100% Completed | 520.85 ms\n" ] } ], "source": [ "astigmatism = np.linspace(-70, 70, 50)\n", "\n", "astigmatism = np.concatenate([astigmatism, astigmatism[:-1][::-1]])\n", "\n", "probe = abtem.Probe(\n", " semiangle_cutoff=30,\n", " defocus=70,\n", " astigmatism=astigmatism,\n", " astigmatism_angle=np.pi / 4,\n", " gpts=256,\n", " extent=10,\n", " energy=200e3,\n", ")\n", "probes = probe.build().complex_images().compute()" ] }, { "cell_type": "markdown", "id": "40e41e57-8e45-4cf7-8b86-1cb1298788cc", "metadata": {}, "source": [ "VAnimations are created via the `.animate` method, which can be rendered in HTML using Javascript via the `to_jshtml` method." ] }, { "cell_type": "code", "execution_count": 3, "id": "346eec1b-7e12-4c1e-a19f-15ae961f3ce8", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "
\n", " \n", "
\n", " \n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", "
\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "visualization = probes.show(cmap=\"hsluv\", display=False, cbar=True, vmin=0, vmax=8e-5)\n", "\n", "visualization.adjust_figure_aspect()\n", "\n", "visualization.set_panel_labels(\n", " labels=\"metadata\", frameon=False, prop={\"color\": \"w\", \"fontsize\": 12}\n", ")\n", "\n", "animation = visualization.animate(adjust_scale=False, interval=100)\n", "\n", "HTML(animation.to_jshtml())" ] }, { "cell_type": "markdown", "id": "f0c8c061-17c7-48a6-8a26-e6a75a2a0886", "metadata": {}, "source": [ "We can switch off the axes and the label, and easily save the animation to disk, for example as a GIF file." ] }, { "cell_type": "code", "execution_count": 6, "id": "1f5c6e3a-fe94-4342-805c-30e0572c28a2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "
\n", " \n", "
\n", " \n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", "
\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "visualization = probes.show(\n", " cmap=\"hsluv\", display=False, cbar=False, vmin=0, vmax=8e-5, figsize=(3, 3))\n", "\n", "visualization.axis_off(spines=False)\n", "visualization.adjust_tight_bbox()\n", "animation = visualization.animate(adjust_scale=False, interval=100)\n", "\n", "HTML(animation.to_jshtml())" ] }, { "cell_type": "code", "execution_count": 4, "id": "b1b8786d-e010-4f67-9566-670da02a58a6", "metadata": {}, "outputs": [], "source": [ "animation.save(\"../thumbnails/animations.gif\", writer=\"pillow\")" ] } ], "metadata": { "kernelspec": { "display_name": "abtem", "language": "python", "name": "abtem" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.4" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 5 }