Off-axis electron holography

New in version 0.3.0.

The off-axis holography applications (see Off-axis electron holography for the application examples) are realized in two modules: UDF for off axis electron holography reconstruction and utility function for hologram simulations.

Hologram reconstruction

The reconstruction module contains class for reconstruction of off-axis holograms using Fourier-space method which implies following processing steps:

  • Fast Fourier transform

  • Filtering of the sideband in Fourier space and cropping (if applicable)

  • Centering of the sideband

  • Inverse Fourier transform.

class libertem.udf.holography.HoloReconstructUDF(out_shape, sb_position, sb_size, sb_smoothness=0.05, precision=True)[source]

Reconstruct off-axis electron holograms using a Fourier-based method.

Running run_udf() on an instance of this class will reconstruct a complex electron wave. Use the wave key to access the raw data in the result.

See Off-axis electron holography for detailed application example

New in version 0.3.0.

Parameters
  • out_shape ((int, int)) – Shape of the returned complex wave image. Note that the result should fit into the main memory. See Off-axis electron holography for more details

  • sb_position (tuple, or vector) – Coordinates of sideband position with respect to non-shifted FFT of a hologram

  • sb_size (float) – Radius of side band filter in pixels

  • sb_smoothness (float, optional (Default: 0.05)) – Fraction of sb_size over which the edge of the filter aperture to be smoothed

  • precision (bool, optional, (Default: True)) – Defines precision of the reconstruction, True for complex128 for the resulting complex wave, otherwise results will be complex64

Examples

>>> shape = tuple(dataset.shape.sig)
>>> sb_position = [2, 3]
>>> sb_size = 4.4
>>> holo_udf = HoloReconstructUDF(out_shape=shape,
...                               sb_position=sb_position,
...                               sb_size=sb_size)
>>> wave = ctx.run_udf(dataset=dataset, udf=holo_udf)['wave'].data
get_backends()[source]

Signal which computation back-ends the UDF can use.

numpy is the default CPU-based computation.

cuda is CUDA-based computation without CuPy.

cupy is CUDA-based computation through CuPy.

New in version 0.6.0.

Returns

backend – An iterable containing possible values numpy (default), 'cuda' and cupy

Return type

Iterable[str]

get_result_buffers()[source]

Initializes BufferWrapper objects for reconstructed wave function

Returns

  • A dictionary that maps ‘wave’ to the corresponding

  • BufferWrapper objects

get_task_data()[source]

Updates task_data

Returns

  • kwargs (dict)

  • A dictionary with the following keys – kwargs[‘aperture’] : array-like Side band filter aperture (mask) kwargs[‘slice’] : slice Slice for slicing FFT of the hologram

process_frame(frame)[source]

Reconstructs holograms outputting results into ‘wave’

Parameters

frame – single frame (hologram) of the data

libertem.udf.holography.aperture_function(r, apradius, rsmooth)[source]

A smooth aperture function that decays from apradius-rsmooth to apradius+rsmooth. :param r: Array of input data (e.g. frequencies) :type r: ndarray :param apradius: Radius (center) of the smooth aperture. Decay starts at apradius - rsmooth. :type apradius: float :param rsmooth: Smoothness in halfwidth. rsmooth = 1 will cause a decay from 1 to 0 over 2 pixel. :type rsmooth: float

Returns

Return type

2d array containing aperture

libertem.udf.holography.freq_array(shape, sampling=(1.0, 1.0))[source]

Makes up a frequency array.

Parameters
  • shape ((int, int)) – The shape of the array.

  • sampling ((float, float), optional, (Default: (1., 1.))) – The sampling rates of the array.

Returns

Return type

Array of the frequencies.

Hologram simulation

libertem.utils.generate.hologram_frame(amp, phi, counts=1000.0, sampling=5.0, visibility=1.0, f_angle=30.0, gaussian_noise=None, poisson_noise=None)[source]

Generates holograms using phase and amplitude as an input

See Off-axis electron holography for detailed application example

New in version 0.3.0.

Notes

Theoretical basis for hologram simulations see in: Lichte, H., and M. Lehmann. Rep. Prog. Phys. 71 (2008): 016102. doi:10.1088/0034-4885/71/1/016102 [LL08]

Parameters
  • amp (np.ndarray, 2d) – normalized amplitude and phase images of the same shape

  • phi (np.ndarray, 2d) – normalized amplitude and phase images of the same shape

  • counts (float, default: 1000.) – Number of electron counts in vacuum

  • sampling (float, default: 5.) – Hologram fringe sampling (number of pixels per fringe)

  • visibility (float, default: 1.) – Hologram fringe visibility (aka fringe contrast)

  • f_angle (float, default: 30.) – Angle in degrees of hologram fringes with respect to X-axis

  • gaussian_noise (float or int or None, default: None.) – Amount of Gaussian smoothing determined by sigma parameter applied to the hologram simulating effect of focus spread or PSF of the detector.

  • poisson_noise (float or int or None, default: None.) – Amount of Poisson applied to the hologram.

Returns

holo – hologram image

Return type

np.ndarray, 2d