Animations

Hide code cell source
%config InlineBackend.rc = {"figure.dpi": 72, 'figure.figsize': (6.0, 4.0)}
%matplotlib inline

import ase
import matplotlib.pyplot as plt
import numpy as np
from IPython.display import HTML

import abtem

abtem.config.set({"local_diagnostics.progress_bar": True});

Animations#

abTEM 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{Å}\).

astigmatism = np.linspace(-70, 70, 50)

astigmatism = np.concatenate([astigmatism, astigmatism[:-1][::-1]])

probe = abtem.Probe(
    semiangle_cutoff=30,
    defocus=70,
    astigmatism=astigmatism,
    astigmatism_angle=np.pi / 4,
    gpts=256,
    extent=10,
    energy=200e3,
)
probes = probe.build().complex_images().compute()
[########################################] | 100% Completed | 520.85 ms

VAnimations are created via the .animate method, which can be rendered in HTML using Javascript via the to_jshtml method.

visualization = probes.show(cmap="hsluv", display=False, cbar=True, vmin=0, vmax=8e-5)

visualization.adjust_figure_aspect()

visualization.set_panel_labels(
    labels="metadata", frameon=False, prop={"color": "w", "fontsize": 12}
)

animation = visualization.animate(adjust_scale=False, interval=100)

HTML(animation.to_jshtml())

We can switch off the axes and the label, and easily save the animation to disk, for example as a GIF file.

visualization = probes.show(
    cmap="hsluv", display=False, cbar=False, vmin=0, vmax=8e-5, figsize=(3, 3))

visualization.axis_off(spines=False)
visualization.adjust_tight_bbox()
animation = visualization.animate(adjust_scale=False, interval=100)

HTML(animation.to_jshtml())
animation.save("../thumbnails/animations.gif", writer="pillow")