Electron probes#

Electron probes, Ronchigrams, contrast transfer functions and HREM images of a lens with aberrations, from emaps’ probe module.

A Probe holds the microscope settings: the high voltage, the aperture, the defocus, the spherical, fifth-order and chromatic aberrations, the residual aberrations a corrector measures (a1 to a5, b2, b4, d4, s3), and the map the results are computed on. Its methods return the results as NumPy arrays, in four modes:

  • ronchigram(): the Ronchigram, the shadow image of the probe through a thin sample: a random amorphous potential (random_potential()), a crystal along a zone axis (crystal_potential()) or one you give;

  • probe(): the probe’s intensity, and diameter() its size;

  • ctf(): the contrast transfer function, with its coherence envelopes;

  • hrem(): the high-resolution TEM image of a thin sample’s exit wave (exit_wave()), with the lens as the objective lens.

For crystals thicker than the projection suits, the multislice method (a licensed feature):

And around them:

  • phase_map(): the aberration function χ(k) itself;

  • stem_image() and mtf(): the incoherent STEM image of a sample, and the probe’s transfer function;

  • apply_psf(): a camera’s point spread function, for HREM images;

  • focal_series(): any of these over a range of defocus;

  • scherzer() and haider(): the optimum defocus and aperture for an uncorrected or a corrected lens, and optimize(): the defocus and residual aberrations that make the probe smallest;

  • show(): the results with their axes.

pyemaps.probe.ABERRATIONS = {'a1': 'nm', 'a2': 'nm', 'a3': 'um', 'a4': 'um', 'a5': 'mm', 'b2': 'nm', 'b4': 'um', 'd4': 'um', 's3': 'um'}#

The residual aberrations, in the order the backend takes them, with their units: two-fold astigmatism a1, three-fold astigmatism a2, four-fold a3, five-fold a4, six-fold a5, axial coma b2, axial star aberration s3, fourth-order coma b4 and three-lobe aberration d4.

class pyemaps.probe.Probe(kv=200.0, aperture=10.0, defocus=0.0, cs=1.0, c5=0.0, cc=0.0, energy_spread=0.7, semi_angle=0.1, tilt=(0.0, 0.0), rotation=0.0, aberrations=None, size=20.0, sampling=256)#

A lens with aberrations, and the map its probe, Ronchigram, CTF and HREM images are computed on. For the probe and the Ronchigram it’s the probe-forming lens; for the CTF and HREM images, the objective lens.

Parameters:
  • kv (float, optional) – high voltage, in kV.

  • aperture (float, optional) – aperture semi-angle, in mrad: the probe’s convergence angle, or for HREM images the objective aperture. The CTF isn’t cut off at it; show() draws it.

  • defocus (float, optional) – defocus, in nm. Negative values are underfocus.

  • cs (float, optional) – spherical aberration C3, in mm.

  • c5 (float, optional) – fifth-order spherical aberration C5, in mm.

  • cc (float, optional) – chromatic aberration, in mm. With 0.01 mm or more, probe() adds up the probes over the energy spread, and ctf() includes the temporal coherence envelope, as do HREM images. The Ronchigram doesn’t include it.

  • energy_spread (float, optional) – energy spread of the beam, full width at half maximum, in eV.

  • semi_angle (float, optional) – illumination semi-angle, in mrad, for the spatial coherence envelope of ctf() and hrem().

  • tilt (tuple of float, optional) – beam tilt: amplitude, in mrad, and direction, in degrees.

  • rotation (float, optional) – rotation of the residual aberrations, in degrees.

  • aberrations (dict, optional) – residual aberrations, {name: (amplitude, angle)}, with the angle in degrees and the amplitude in the units of ABERRATIONS, for example {'a1': (1.35, 146.2), 'b2': (22.9, 141.4)}. Those not given are 0.

  • size (float, optional) – width and height of the map, in Å. The probe and the sample are in a square of this size; the Ronchigram and the CTF extend to sampling / (2 * size) 1/Å from their center.

  • sampling (int, optional) – pixels along each side of the map, an even number.

The defaults are those of the probe program: 200 kV, Cs 1 mm, a 20 Å map of 256 x 256 pixels, with a 10 mrad aperture.

property wavelength#

The electron wavelength, in Å, relativistically corrected.

property kmax#

The aperture’s radius in reciprocal space, in 1/Å.

property aberrations#

The residual aberrations, {name: (amplitude, angle)}. A copy: change them with set_aberration().

set_aberration(name, amplitude, angle=0.0)#

Set a residual aberration.

Parameters:
  • name (str) – its name: 'a1', 'a2', 'a3', 'a4', 'a5', 'b2', 'b4', 'd4' or 's3'.

  • amplitude (float) – its amplitude, in the units of ABERRATIONS.

  • angle (float, optional) – its angle, in degrees.

Raises:

ValueError – if name isn’t one of them.

zero_aberrations()#

Set all residual aberrations to 0.

random_potential(density=0.05, z=13.0, thickness=100.0, seed=1211)#

A random potential of an amorphous sample: atoms of one element at random positions, each a point-like potential, projected through the sample’s thickness.

Parameters:
  • density (float, optional) – number of atoms per ų.

  • z (float, optional) – their atomic number.

  • thickness (float, optional) – the sample’s thickness, in Å.

  • seed (int, optional) – the random number seed, from 1 to 2147483646 (MAX_SEED). The same seed gives the same potential.

Returns:

the projected potential, (sampling, sampling), rows then columns.

Return type:

numpy.ndarray

Raises:
  • ValueError – if a setting is invalid, or the sample would have more than 10⁸ atoms (size² × thickness × density).

  • MemoryError – if it needs more memory than is free.

The defaults are those of the probe program: 100 Å of amorphous aluminium.

crystal_potential(crystal, zone=(0, 0, 1), thickness=50.0, x_axis=None, shift=(0.0, 0.0), fit=False)#

The projected potential of a crystal along a zone axis: the atoms of the crystal in a slab of the given thickness, each with its projected atomic potential, added up.

Parameters:
  • crystal (Crystal) – the crystal, such as Crystal.from_builtin('Silicon').

  • zone (tuple of int, optional) – the zone axis [uvw], a direction in the crystal’s direct lattice, along the beam.

  • thickness (float, optional) – the slab’s thickness along the zone axis, in Å.

  • x_axis (tuple of int, optional) – the direction [uvw] along the map’s x axis (its columns). It must not be parallel to the zone axis; its part along the zone axis is ignored. By default, the shortest direction with indices up to 6 perpendicular to the zone axis.

  • shift (tuple of float, optional) – where the crystal’s origin is on the map, (x, y) in Å from the map’s top left corner.

  • fit (bool, optional) – strain the crystal slightly in the plane of the map so that it repeats at the map’s edges, without a seam; see crystal_repeats(). A strain above 1% gives a warning.

Returns:

the projected potential in V·Å, (sampling, sampling), rows then columns, as random_potential() gives it.

Return type:

numpy.ndarray

Raises:
  • ValueError – if a setting is invalid, an element has no scattering factor, or the slab would have more than 10⁸ atoms (MAX_ATOMS).

  • ImportError – if emaps is older than 2.6.0.

  • MemoryError – if it needs more memory than is free.

Each atom’s potential comes from its electron scattering factor, by the Mott–Bethe formula from emaps’ X-ray scattering factors, as emaps’ structure factors have it. It includes the atom’s Debye–Waller factor, an anisotropic one averaged to the equivalent isotropic factor, and its occupancy. The unit cell is filled with the space group by generateMxtal(), and emaps computes the potential.

The potential is that of the whole slab projected onto one plane, as the probe program’s random potential is, so it suits thin crystals: there’s no propagation through the thickness. For thicker crystals, see crystal_exit_wave().

The map repeats itself at its edges. Unless size is a whole number of the crystal’s repeats along x and y, or fit is set, the crystal has a seam there; it’s away from the map’s center, where the probe is.

crystal_repeats(crystal, zone=(0, 0, 1), x_axis=None, max_size=200.0, max_strain=0.002)#

How a crystal along a zone axis repeats on the map, and the map sizes that fit it without a seam.

Parameters:
  • crystal (Crystal) – the crystal.

  • zone (tuple of int, optional) – the zone axis [uvw], along the beam.

  • x_axis (tuple of int, optional) – the direction [uvw] along the map’s x axis, as crystal_potential() takes it.

  • max_size (float, optional) – the largest map size to list, in Å.

  • max_strain (float, optional) – the largest strain fit would need for a listed size.

Returns:

a dictionary:

  • 'x_axis': the direction [uvw] along x;

  • 'repeats': two lattice vectors that span the crystal’s repeats in the plane of the map, (x, y) in Å, shortest first;

  • 'period': the crystal’s repeat along the zone axis, in Å; the multislice cuts it into slices;

  • 'sizes': (size, strain) pairs, the map sizes up to max_size at which the crystal repeats at the map’s edges with at most max_strain, smallest first. At these sizes fit=True changes almost nothing, and without it the seam is hardly there.

Return type:

dict

Raises:

ValueError – if a setting is invalid.

The current map’s size doesn’t matter here.

crystal_exit_wave(crystal, zone=(0, 0, 1), thickness=100.0, slice_thickness=2.0, x_axis=None, shift=(0.0, 0.0), fit=False, bandlimit=True)#

The exit wave of a crystal under plane-wave illumination, by the multislice method: the wave through the crystal slice by slice, for crystals too thick for exit_wave() of crystal_potential(). This is a licensed feature.

Parameters:
  • crystal (Crystal) – the crystal.

  • zone (tuple of int, optional) – the zone axis [uvw], three integers, along the beam.

  • thickness (float or list of float, optional) – the crystal’s thickness in Å, or a list of thicknesses: the waves at each come from one pass through the crystal. Each is rounded to a whole number of slices.

  • slice_thickness (float, optional) – about how thick each slice is, in Å. The crystal’s repeat along the zone axis (crystal_repeats()['period']) is cut into a whole number of slices of about this thickness, and each slice’s potential is that of its atoms. Thinner slices are more accurate and slower.

  • x_axis (tuple of int, optional) – the direction [uvw] along the map’s x axis, as crystal_potential() takes it.

  • shift (tuple of float, optional) – where the crystal’s origin is on the map, (x, y) in Å.

  • fit (bool, optional) – strain the crystal slightly so that it repeats at the map’s edges, as crystal_potential() does.

  • bandlimit (bool, optional) – limit the slices’ transmission functions and the propagator to 2/3 of the map’s largest spatial frequency, so their products don’t alias. Leave it on, except to compare with exit_wave().

Returns:

the exit wave, complex, (sampling, sampling), or with a list of thicknesses, (len(thickness), sampling, sampling). Pass it to hrem().

Return type:

numpy.ndarray

Raises:
  • LicenseError – without an active pyEMAPS license.

  • ValueError – if a setting is invalid, an element has no scattering factor, or the map doesn’t fit in memory.

  • ImportError – if emaps is older than 2.6.0.

  • MemoryError – if it needs more memory than is free.

The crystal repeats along the zone axis, so the slices of one repeat serve for every repeat. Each slice’s transmission function is exp(iσV) for its projected potential V, and the wave travels to the next slice by the Fresnel propagator. With the band limit, the wave’s total intensity drops slightly as the crystal scatters beyond it; finer pixels (a larger sampling for the same size) keep more of it.

There is no absorption and no thermal diffuse scattering, and the beam is along the zone axis.

crystal_ronchigram(crystal, zone=(0, 0, 1), thickness=100.0, slice_thickness=2.0, x_axis=None, shift=(0.0, 0.0), fit=False, bandlimit=True)#

The Ronchigram of this probe through a crystal, by the multislice method: the probe’s wave through the crystal slice by slice, then its intensity in the far field. With a small aperture and the probe focused on the crystal, it’s a convergent-beam diffraction (CBED) pattern, with the crystal’s dynamical diffraction inside its disks. This is a licensed feature.

The parameters are those of crystal_exit_wave().

Returns:

the Ronchigram, (sampling, sampling), with the beam at the center, as ronchigram() gives it, or with a list of thicknesses, (len(thickness), sampling, sampling).

Return type:

numpy.ndarray

Raises:
  • LicenseError – without an active pyEMAPS license.

  • ValueError – if a setting is invalid, an element has no scattering factor, or the map doesn’t fit in memory.

  • ImportError – if emaps is older than 2.6.0.

  • MemoryError – if it needs more memory than is free.

The probe sits at the map’s center. As for ronchigram(), the chromatic aberration isn’t included.

ronchigram(potential=None)#

The Ronchigram: the intensity of the probe after a thin sample, in the far field.

Parameters:

potential (numpy.ndarray, optional) – the sample’s projected potential, (sampling, sampling), covering the map. By default, random_potential() with its defaults.

Returns:

the Ronchigram, (sampling, sampling), with the beam at the center. Each pixel is 1 / size 1/Å, or 1000 * wavelength / size mrad.

Return type:

numpy.ndarray

Raises:
  • ValueError – if a setting is invalid or potential has the wrong shape.

  • MemoryError – if it needs more memory than is free.

probe()#

The probe’s intensity in the sample plane, normalized to a sum of 1.

Returns:

the intensity, (sampling, sampling), with the probe at the center. Each pixel is size / sampling Å.

Return type:

numpy.ndarray

Raises:
  • ValueError – if a setting is invalid.

  • MemoryError – if it needs more memory than is free.

diameter(percent=50.0, probe=None, interpolate=False)#

The probe’s diameter: that of the circle around the map’s center that holds percent percent of its intensity.

Parameters:
  • percent (float, optional) – the share of the intensity, in percent.

  • probe (numpy.ndarray, optional) – the probe intensity from probe(). By default, computed.

  • interpolate (bool, optional) – False: count whole pixels, as the probe program does. True: interpolate the intensity within the circle between the pixels’ distances from the center, so the diameter changes smoothly with the probe; optimize() uses it.

Returns:

the diameter, in Å.

Return type:

float

Raises:

ValueError – if percent isn’t between 0 and 100, the probe has no intensity near the center of the map, the map is too small to hold percent percent of it, or its pixels are too large to measure it (it fits within one pixel of the center).

Counting whole pixels, the diameter changes in steps of about a pixel, and probes of slightly different sizes can give the same value. Use a map whose pixels (size / sampling) are much smaller than the probe, such as 0.1 Å, or interpolate.

ctf()#

The contrast transfer function, sin(χ), damped by the temporal coherence envelope (from cc and energy_spread) and the spatial one (from semi_angle). It’s computed within 80% of the map’s radius and is 0 outside.

Returns:

the CTF, (sampling, sampling), with zero frequency at the center. Each pixel is 1 / size 1/Å.

Return type:

numpy.ndarray

Raises:
  • ValueError – if a setting is invalid.

  • MemoryError – if it needs more memory than is free.

exit_wave(potential=None)#

The exit wave of a thin sample under plane-wave illumination: its transmission function, exp(iσV), for the projected potential V at this high voltage.

Parameters:

potential (numpy.ndarray, optional) – the projected potential, (sampling, sampling). By default, random_potential() with its defaults.

Returns:

the exit wave, complex, (sampling, sampling).

Return type:

numpy.ndarray

Raises:
  • ValueError – if a setting is invalid or potential has the wrong shape.

  • MemoryError – if it needs more memory than is free.

hrem(wave=None, integrate=False)#

The high-resolution TEM (HREM) image of an exit wave, with this lens as the objective lens: the image intensity of the wave through the aperture, with the aberrations and the coherence envelopes. The direct beam passes unchanged.

Parameters:
  • wave (numpy.ndarray, optional) – the sample’s exit wave, complex, (sampling, sampling), such as exit_wave() gives or a multislice program computes. By default, exit_wave() of the default random potential: 100 Å of amorphous aluminium.

  • integrate (bool, optional) – how to include the chromatic aberration. False: the coherent image, damped by the temporal coherence envelope (cc, energy_spread) and the spatial one (semi_angle). True: the images at each energy across the energy spread, added up with the spatial envelope only; this needs energy_spread.

Returns:

the image intensity, (sampling, sampling), with pixels of size / sampling Å. A plane wave’s image is 1 everywhere.

Return type:

numpy.ndarray

Raises:
  • ValueError – if a setting is invalid or wave has the wrong shape.

  • MemoryError – if it needs more memory than is free.

phase_map()#

The aberration function χ(k): the phase, in radians, that the lens adds to the wave at each spatial frequency, from the defocus, Cs, C5 and the residual aberrations, with the beam tilt and rotation. The CTF without its envelopes is sin(χ). It’s computed within 80% of the map’s radius, as the CTF, and is 0 outside.

Returns:

χ, (sampling, sampling), with zero frequency at the center. Each pixel is 1 / size 1/Å.

Return type:

numpy.ndarray

Raises:
  • ValueError – if a setting is invalid.

  • MemoryError – if it needs more memory than is free.

Where χ is nearly flat, within about π/4 of its value at the center, the lens is free of aberrations: that region sets how large an aperture can be used.

stem_image(potential=None)#

The incoherent (annular dark field) STEM image of a thin sample: the probe’s intensity, as probe() computes it, convolved with the sample’s projected potential.

Parameters:

potential (numpy.ndarray, optional) – the projected potential, (sampling, sampling). By default, random_potential() with its defaults.

Returns:

the image, (sampling, sampling), with pixels of size / sampling Å.

Return type:

numpy.ndarray

Raises:
  • ValueError – if a setting is invalid or potential has the wrong shape.

  • MemoryError – if it needs more memory than is free.

mtf()#

The probe’s modulation transfer function: the amplitude of the Fourier transform of its intensity, which tells how strongly each spatial frequency of the sample shows in an incoherent STEM image. It’s 1 at zero frequency.

Returns:

the MTF, (sampling, sampling), with zero frequency at the center. Each pixel is 1 / size 1/Å.

Return type:

numpy.ndarray

Raises:
  • ValueError – if a setting is invalid.

  • MemoryError – if it needs more memory than is free.

apply_psf(image, a=0.6, b=400.0)#

Blur an image with a detector’s point spread function, as recorded by a camera: its transfer function is a / (1 + b w²) + 1 - a at the spatial frequency w, in cycles per pixel (0 to 0.5). The defaults are typical of a camera: the transfer is about 0.4 at the Nyquist frequency.

Parameters:
  • image (numpy.ndarray) – the image, square, with an even number of pixels along each side, such as hrem() gives.

  • a (float, optional) – the share of the transfer that falls off with frequency, 0 to 1.

  • b (float, optional) – how fast it falls off; 0 leaves the image as it is.

Returns:

the blurred image, the same shape.

Return type:

numpy.ndarray

Raises:
  • ValueError – if image isn’t square with an even size of at least 8 pixels, or b is negative.

  • MemoryError – if it needs more memory than is free.

focal_series(defocus, kind='probe', sample=None, integrate=False)#

A result at each of a series of defocus values, the probe program’s focus command.

Parameters:
  • defocus (sequence of float) – the defocus values, in nm.

  • kind (str, optional) – 'probe', 'ronchigram', 'ctf', 'hrem', 'stem' or 'phase'.

  • sample (numpy.ndarray, optional) – the projected potential for 'ronchigram' and 'stem', or the exit wave for 'hrem'. By default, as those methods take it, computed once.

  • integrate (bool, optional) – for 'hrem', as hrem() takes it.

Returns:

the results, (len(defocus), sampling, sampling).

Return type:

numpy.ndarray

Raises:

ValueError – if kind or a setting is invalid.

The probe’s defocus is left as it was.

optimize(percent=50.0, vary=('defocus', 'a1'), steps=None, max_evaluations=400)#

Find the settings that make the probe smallest: the diameter holding percent percent of its intensity, as diameter() measures it with interpolate=True, the probe program’s optimize command. It searches with the Nelder-Mead simplex method and sets the probe to the best settings it found.

Parameters:
  • percent (float, optional) – the share of the intensity whose diameter is minimized, in percent.

  • vary (sequence of str, optional) – what to adjust: 'defocus', and the residual aberrations, such as 'a1', 'a2' and 'b2', each by its two components (amplitude times the cosine and sine of its angle). The probe program’s options were (‘defocus’, ‘a1’), (‘defocus’, ‘a1’, ‘a2’, ‘b2’), (‘a1’, ‘a2’, ‘b2’) and (‘defocus’,).

  • steps (dict, optional) – the size of the first steps, {name: step}, in the setting’s units. By default, as the probe program: 10 nm for the defocus, and 25 in each aberration’s units.

  • max_evaluations (int, optional) – the most probes to compute.

Returns:

the result: diameter (Å), the settings found (defocus in nm, and each aberration as (amplitude, angle)), and evaluations.

Return type:

dict

Raises:

ValueError – if vary names an unknown setting, or the probe can’t be measured at the starting settings (see diameter()).

The probe’s map must hold the probe with room to spare, with pixels much smaller than it. The search finds a local minimum, near the starting settings.

scherzer(mode=1)#

Set the Scherzer defocus and aperture of an uncorrected lens, from Cs.

Parameters:

mode (int, optional) – 1 for the optimum probe (defocus -sqrt(Cs λ), kmax (4 / (Cs λ³))^¼), 2 for the optimum phase contrast (defocus -sqrt(1.5 Cs λ), kmax (6 / (Cs λ³))^¼).

Returns:

the settings: defocus (nm), aperture (mrad), kmax (1/Å), and with mode 1 the probe’s fwhm (Å).

Return type:

dict

Raises:

ValueError – if Cs isn’t positive or mode isn’t 1 or 2.

haider(optimum_aperture=True)#

Set the defocus and Cs that balance C5 in a corrected lens (Haider et al., Ultramicroscopy, 2000).

Parameters:

optimum_aperture (bool, optional) – also set the aperture to its optimum for C5, and Cs and the defocus for it. With False, keep the aperture and set Cs and the defocus for it.

Returns:

the settings: defocus (nm), cs (mm) and aperture (mrad), and with optimum_aperture the expected resolution (Å).

Return type:

dict

Raises:

ValueError – if C5 isn’t positive.

extent(kind)#

The axis extent of a result for matplotlib.pyplot.imshow().

Parameters:

kind (str) – 'probe', 'potential', 'hrem' or 'stem' (Å), 'ronchigram' (mrad), or 'ctf', 'phase' or 'mtf' (1/Å).

Returns:

(left, right, bottom, top).

Return type:

tuple

show(image, kind, ax=None, title=None, aperture=True)#

Display a result with its axes.

Parameters:
  • image (numpy.ndarray) – the result, from ronchigram(), probe(), ctf(), hrem(), stem_image(), phase_map(), mtf(), random_potential() or crystal_potential().

  • kind (str) – 'ronchigram', 'probe', 'ctf', 'hrem', 'stem', 'phase', 'mtf' or 'potential'.

  • ax (matplotlib.axes.Axes, optional) – the axes to draw in. By default, a new figure, shown.

  • title (str, optional) – the title. By default, the kind and the main settings.

  • aperture (bool, optional) – on a Ronchigram, CTF, phase map or MTF, draw the aperture’s edge. A phase map is shown modulo 2π, with a cyclic colour map.

Returns:

the axes.

Return type:

matplotlib.axes.Axes

classmethod from_file(path, **kwargs)#

Create a probe from a probe program parameter file: lines of a name and values, such as kv 200, aperture 25, df -5.14, cs -0.00355 (or c3_mm), c5 3.829 and a1 1.349 146.2, as the program’s write -m and its microscope files have them. The program’s other settings are read too: kmax (1/Å, instead of the aperture), semi, cc, de, fhi, tilt (amplitude and angle), dim (the map’s size) and sam (its sampling). Lines starting with #, and end, are skipped.

Parameters:
  • path (str or os.PathLike) – the file.

  • kwargs – other Probe settings, such as size and sampling. Those in the file take precedence.

Returns:

the probe.

Return type:

Probe

Raises:

ValueError – for a line it doesn’t understand, with its number.