comp_phase module

This module consists of functions for simulating the phase shift of a given object.

It contained two functions:

  1. linsupPhi - using the linear superposition principle for application in model based iterative reconstruction (MBIR) type 3D reconstruction of magnetization (both magnetic and electrostatic). This also includes a helper function that makes use of numba and just-in-time (jit) compilation.
  2. mansPhi - using the Mansuripur Algorithm to compute the phase shift (only magnetic)

Authors: CD Phatak, Arthur McCray June 2020

comp_phase.exp_sum(mphi_k, ephi_k, inds, KY, KX, j_n, i_n, my_n, mx_n, Sy, Sx)[source]

Called by linsupPhi when running with multiprocessing and numba.

Numba incorporates just-in-time (jit) compiling and multiprocessing to numpy array calculations, greatly speeding up the phase-shift computation beyond that of pure vectorization and without the memory cost. Running this for the first time each session will take an additional 5-10 seconds as it is compiled.

This function could be further improved by sending it to the GPU, or likely by other methods we haven’t considered. If you have suggestions (or better yet, written and tested code) please email amccray@anl.gov.

comp_phase.linsupPhi(mx=1.0, my=1.0, mz=1.0, Dshp=None, theta_x=0.0, theta_y=0.0, pre_B=1.0, pre_E=1, v=1, multiproc=True)[source]

Applies linear superposition principle for 3D reconstruction of magnetic and electrostatic phase shifts.

This function will take 3D arrays with Mx, My and Mz components of the magnetization, the Dshp array consisting of the shape function for the object (1 inside, 0 outside), and the tilt angles about x and y axes to compute the magnetic and the electrostatic phase shift. Initial computation is done in Fourier space and then real space values are returned.

Parameters:
  • mx (3D array) – x component of magnetization at each voxel (z,y,x)
  • my (3D array) – y component of magnetization at each voxel (z,y,x)
  • mz (3D array) – z component of magnetization at each voxel (z,y,x)
  • Dshp (3D array) – Binary shape function of the object. Where value is 0, phase is not computed.
  • theta_x (float) – Rotation around x-axis (degrees). Rotates around x axis then y axis if both are nonzero.
  • theta_y (float) – Rotation around y-axis (degrees)
  • pre_B (float) – Numerical prefactor for unit conversion in calculating the magnetic phase shift. Units 1/pixels^2. Generally (2*pi*b0*(nm/pix)^2)/phi0 , where b0 is the Saturation induction and phi0 the magnetic flux quantum.
  • pre_E (float) – Numerical prefactor for unit conversion in calculating the electrostatic phase shift. Equal to sigma*V0, where sigma is the interaction constant of the given TEM accelerating voltage (an attribute of the microscope class), and V0 the mean inner potential.
  • v (int) – Verbosity. v >= 1 will print status and progress when running without numba. v=0 will suppress all prints.
  • mp (bool) – Whether or not to implement multiprocessing.
Returns:

Tuple of length 2: (ephi, mphi). Where ephi and mphi are 2D numpy arrays of the electrostatic and magnetic phase shifts respectively.

Return type:

tuple

comp_phase.mansPhi(mx=1.0, my=1.0, mz=None, beam=[0.0, 0.0, 1.0], thick=1.0, embed=0.0)[source]

Calculate magnetic phase shift using Mansuripur algorithm [1].

Unlike the linear superposition method, this algorithm only accepts 2D samples. The input given is expected to be 2D arrays for mx, my, mz. It can compute beam angles close to (0,0,1), but for tilts greater than a few degrees (depending on sample conditions) it loses accuracy.

The embed argument places the magnetization into a larger array to increase Fourier resolution, but this also seems to introduce a background phase shift into some images. Use at your own risk.

Parameters:
  • mx (2D array) – x component of magnetization at each pixel.
  • my (2D array) – y component of magnetization at each pixel.
  • mz (2D array) – z component of magnetization at each pixel.
  • beam (list) – Vector direction of beam [x,y,z]. Default [001].
  • thick (float) – Thickness of the sample in pixels. i.e. thickness in nm divided by del_px which is nm/pixel.
  • embed (int) –

    Whether or not to embed the mx, my, mz into a larger array for Fourier-space computation. In theory this improves edge effects at the cost of reduced speed, however it also seems to add a background phase gradient in some simulations.

    embed value effect
    0 Do not embed (default)
    1 Embed in (1024, 1024) array
    x (int) Embed in (x, x) array.
Returns:

2D array of magnetic phase shift

Return type:

ndarray

References

  1. Mansuripur, M. Computation of electron diffraction patterns in Lorentz electron microscopy of thin magnetic films. J. Appl. Phys. 69, 5890 (1991).