stemtool.afit package

Submodules

stemtool.afit.atom_positions module

class stemtool.afit.atom_positions.atom_fit(image, calib, calib_units)[source]

Bases: object

Locate atom columns in atomic resolution STEM images and then subsequently use gaussian peak fitting to refine the column location with sub-pixel precision.

Parameters:
  • image (ndarray) – The image from which the peak positions will be ascertained.
  • calib (float) – Size of an individual pixel
  • calib_units (str) – Unit of calibration

References

1]_, Mukherjee, D., Miao, L., Stone, G. and Alem, N.,
mpfit: a robust method for fitting atomic resolution images with multiple Gaussian peaks. Adv Struct Chem Imag 6, 1 (2020).

Examples

Run as:

>>> atoms = st.afit.atom_fit(stem_image, calibration, 'nm')

Then to check the image you just loaded, with the optional parameter 12 determining how many pixels of gaussian blur need to applied to calculate and separate a background. If in doubt, don’t use it.

>>> atoms.show_image(12)

It is then optional to define a refernce region for the image. If such a region is defined, atom positions will only be ascertained grom the reference region. If you don’t run this step, the entire image will be analyzed

>>> atoms.define_reference((17, 7), (26, 7), (26, 24), (17, 24))

Then, visualize the peaks:

>>> atoms.peaks_vis(dist=0.1, thresh=0.1)

dist indicates the distance between the peaks in calibration units. Play around with the numbers till you get a satisfactory result. Then run the gaussian peak refinement as:

>>> atoms.refine_peaks()

You can visualize your fitted peaks as:

>>> atoms.show_peaks(style= 'separate')
define_reference(A_pt, B_pt, C_pt, D_pt, imsize=(15, 15), tColor='k')[source]

Locate the reference image.

Parameters:
  • A_pt (tuple) – Top left position of reference region in (x, y)
  • B_pt (tuple) – Top right position of reference region in (x, y)
  • C_pt (tuple) – Bottom right position of reference region in (x, y)
  • D_pt (tuple) – Bottom left position of reference region in (x, y)
  • imsize (tuple, optional) – Size in inches of the image with the diffraction spots marked. Default is (10, 10)
  • tColor (str, optional) – Color of the text on the image. Default is black

Notes

Locates a reference region bounded by the four points given in length units. Choose the points in a clockwise fashion.

peaks_vis(dist, thresh, gfilt=2, imsize=(15, 15), spot_color='c')[source]
refine_peaks()[source]

Calls the numba functions med_dist_numba and refine_atoms_numba to refine the peaks originally calculated.

show_image(gaussval=0, imsize=(15, 15), colormap='inferno')[source]
Parameters:
  • gaussval (int, optional) – Extent of Gaussian blurring in pixels to generate a background image for subtraction. Default is 0
  • imsize (tuple, optional) – Size in inches of the image with the diffraction spots marked. Default is (15, 15)
  • colormap (str, optional) – Colormap of the image. Default is inferno
show_peaks(imsize=(15, 15), style='together')[source]
stemtool.afit.atom_positions.coords_of_atoms(peaks, coords, origin)[source]

Convert atom positions to coordinates

Parameters:
  • peaks (ndarray) – List of Gaussian fitted peaks
  • coords (ndarray) – Co-ordinates of the axes
Returns:

atom_coords – Peak positions as the atom coordinates

Return type:

ndarray

Notes

One atom is chosen as the origin and the co-ordinates of all the atoms are calculated with respect to the origin

Authors:

Debangshu Mukherjee <mukherjeed@ornl.gov>

stemtool.afit.atom_positions.create_circmask(image, center, radius, g_val=3, flip=True)[source]

Use a Gaussian blurred image to fit peaks.

Parameters:
  • image (ndarray) – 2D array representing the image
  • center (tuple) – Approximate location as (x,y) of the peak we are trying to fit
  • radius (float) – Masking radius
  • g_val (float) – Value in pixels of the Gaussian blur applied. Default is 3
  • flip (bool) – Switch to flip refined center position from (x,y) to (y,x). Default is True which returns the center as (y,x)
Returns:

  • masked_image (ndarray) – Masked Image centered at refined peak position
  • new_center (ndarray) – Refined atom center as (y,x) if flip switch is on, else the center is returned as (x,y)

Notes

For some noisy datasets, a peak may be visible with the human eye, but getting a sub-pixel estimation of the peak position is often challenging, especially for FFT for diffraction patterns. This code Gaussian blurs the image, and returns the refined peak position

See also

st.util.fit_gaussian2D_mask

Authors:

Debangshu Mukherjee <mukherjeed@ornl.gov>

stemtool.afit.atom_positions.find_coords(image, fourier_center, fourier_y, fourier_x, y_axis, x_axis)[source]

Convert the fourier positions to image axes. Do not use numba to accelerate as LLVM IR throws an error from the the if statements

Parameters:
  • image (ndarray) – Original image
  • four_c (ndarray) – Position of the central beam in the Fourier pattern
  • four_y (ndarray) – Position of the y beam in the Fourier pattern
  • four_x (ndarray) – Position of the x beam in the Fourier pattern
Returns:

coords – Axes co-ordinates in the real image, as [y1 x1

y2 x2]

Return type:

ndarray

Notes

Use the fourier coordinates to define the axes co-ordinates in real space, which will be used to assign each atom position to a axes position

Authors:

Debangshu Mukherjee <mukherjeed@ornl.gov>

stemtool.afit.atom_positions.find_diffraction_spots(image, circ_c, circ_y, circ_x)[source]

Find the diffraction spots visually.

Parameters:
  • image (ndarray) – Original image
  • circ_c (ndarray) – Position of the central beam in the Fourier pattern
  • circ_y (ndarray) – Position of the y beam in the Fourier pattern
  • circ_x (ndarray) – Position of the x beam in the Fourier pattern

Notes

Put circles in red(central), y(blue) and x(green) on the diffraction pattern to approximately know the positions.

Authors:

Debangshu Mukherjee <mukherjeed@ornl.gov>

stemtool.afit.atom_positions.fourier_mask(original_image, center, radius, threshold=0.2)[source]
stemtool.afit.atom_positions.get_coords(image, peak_pos, origin, current_coords)[source]
stemtool.afit.atom_positions.get_origin(image, peak_pos, coords)[source]
stemtool.afit.atom_positions.peaks_vis(data_image, dist=10, thresh=0.1, imsize=(20, 20))[source]

Find atom maxima pixels in images

Parameters:
  • data_image (ndarray) – Original atomic resolution image
  • dist (int) – Average distance between neighboring peaks Default is 10
  • thresh (float) – The cutoff intensity value below which a peak will not be detected Default is 0.1
  • imsize (ndarray) – Size of the display image Default is (20,20)
Returns:

peaks – List of peak positions as y, x

Return type:

ndarray

Notes

This is a wrapper around the skimage peak finding module which finds the peaks with a given threshold value and an inter-peak separation. The function additionally plots the peak positions on the original image thus users can modify the input values of threshold and distance to ensure the right peaks are selected.

Authors:

Debangshu Mukherjee <mukherjeed@ornl.gov>

stemtool.afit.atom_positions.remove_close_vals(input_arr, limit)[source]
stemtool.afit.atom_positions.strain_map(centers, e_yy, e_xx, e_xy, e_th, mask)[source]

stemtool.afit.drift_corr module

class stemtool.afit.atom_positions.atom_fit(image, calib, calib_units)[source]

Bases: object

Locate atom columns in atomic resolution STEM images and then subsequently use gaussian peak fitting to refine the column location with sub-pixel precision.

Parameters:
  • image (ndarray) – The image from which the peak positions will be ascertained.
  • calib (float) – Size of an individual pixel
  • calib_units (str) – Unit of calibration

References

1]_, Mukherjee, D., Miao, L., Stone, G. and Alem, N.,
mpfit: a robust method for fitting atomic resolution images with multiple Gaussian peaks. Adv Struct Chem Imag 6, 1 (2020).

Examples

Run as:

>>> atoms = st.afit.atom_fit(stem_image, calibration, 'nm')

Then to check the image you just loaded, with the optional parameter 12 determining how many pixels of gaussian blur need to applied to calculate and separate a background. If in doubt, don’t use it.

>>> atoms.show_image(12)

It is then optional to define a refernce region for the image. If such a region is defined, atom positions will only be ascertained grom the reference region. If you don’t run this step, the entire image will be analyzed

>>> atoms.define_reference((17, 7), (26, 7), (26, 24), (17, 24))

Then, visualize the peaks:

>>> atoms.peaks_vis(dist=0.1, thresh=0.1)

dist indicates the distance between the peaks in calibration units. Play around with the numbers till you get a satisfactory result. Then run the gaussian peak refinement as:

>>> atoms.refine_peaks()

You can visualize your fitted peaks as:

>>> atoms.show_peaks(style= 'separate')
define_reference(A_pt, B_pt, C_pt, D_pt, imsize=(15, 15), tColor='k')[source]

Locate the reference image.

Parameters:
  • A_pt (tuple) – Top left position of reference region in (x, y)
  • B_pt (tuple) – Top right position of reference region in (x, y)
  • C_pt (tuple) – Bottom right position of reference region in (x, y)
  • D_pt (tuple) – Bottom left position of reference region in (x, y)
  • imsize (tuple, optional) – Size in inches of the image with the diffraction spots marked. Default is (10, 10)
  • tColor (str, optional) – Color of the text on the image. Default is black

Notes

Locates a reference region bounded by the four points given in length units. Choose the points in a clockwise fashion.

peaks_vis(dist, thresh, gfilt=2, imsize=(15, 15), spot_color='c')[source]
refine_peaks()[source]

Calls the numba functions med_dist_numba and refine_atoms_numba to refine the peaks originally calculated.

show_image(gaussval=0, imsize=(15, 15), colormap='inferno')[source]
Parameters:
  • gaussval (int, optional) – Extent of Gaussian blurring in pixels to generate a background image for subtraction. Default is 0
  • imsize (tuple, optional) – Size in inches of the image with the diffraction spots marked. Default is (15, 15)
  • colormap (str, optional) – Colormap of the image. Default is inferno
show_peaks(imsize=(15, 15), style='together')[source]
stemtool.afit.atom_positions.coords_of_atoms(peaks, coords, origin)[source]

Convert atom positions to coordinates

Parameters:
  • peaks (ndarray) – List of Gaussian fitted peaks
  • coords (ndarray) – Co-ordinates of the axes
Returns:

atom_coords – Peak positions as the atom coordinates

Return type:

ndarray

Notes

One atom is chosen as the origin and the co-ordinates of all the atoms are calculated with respect to the origin

Authors:

Debangshu Mukherjee <mukherjeed@ornl.gov>

stemtool.afit.atom_positions.create_circmask(image, center, radius, g_val=3, flip=True)[source]

Use a Gaussian blurred image to fit peaks.

Parameters:
  • image (ndarray) – 2D array representing the image
  • center (tuple) – Approximate location as (x,y) of the peak we are trying to fit
  • radius (float) – Masking radius
  • g_val (float) – Value in pixels of the Gaussian blur applied. Default is 3
  • flip (bool) – Switch to flip refined center position from (x,y) to (y,x). Default is True which returns the center as (y,x)
Returns:

  • masked_image (ndarray) – Masked Image centered at refined peak position
  • new_center (ndarray) – Refined atom center as (y,x) if flip switch is on, else the center is returned as (x,y)

Notes

For some noisy datasets, a peak may be visible with the human eye, but getting a sub-pixel estimation of the peak position is often challenging, especially for FFT for diffraction patterns. This code Gaussian blurs the image, and returns the refined peak position

See also

st.util.fit_gaussian2D_mask

Authors:

Debangshu Mukherjee <mukherjeed@ornl.gov>

stemtool.afit.atom_positions.find_coords(image, fourier_center, fourier_y, fourier_x, y_axis, x_axis)[source]

Convert the fourier positions to image axes. Do not use numba to accelerate as LLVM IR throws an error from the the if statements

Parameters:
  • image (ndarray) – Original image
  • four_c (ndarray) – Position of the central beam in the Fourier pattern
  • four_y (ndarray) – Position of the y beam in the Fourier pattern
  • four_x (ndarray) – Position of the x beam in the Fourier pattern
Returns:

coords – Axes co-ordinates in the real image, as [y1 x1

y2 x2]

Return type:

ndarray

Notes

Use the fourier coordinates to define the axes co-ordinates in real space, which will be used to assign each atom position to a axes position

Authors:

Debangshu Mukherjee <mukherjeed@ornl.gov>

stemtool.afit.atom_positions.find_diffraction_spots(image, circ_c, circ_y, circ_x)[source]

Find the diffraction spots visually.

Parameters:
  • image (ndarray) – Original image
  • circ_c (ndarray) – Position of the central beam in the Fourier pattern
  • circ_y (ndarray) – Position of the y beam in the Fourier pattern
  • circ_x (ndarray) – Position of the x beam in the Fourier pattern

Notes

Put circles in red(central), y(blue) and x(green) on the diffraction pattern to approximately know the positions.

Authors:

Debangshu Mukherjee <mukherjeed@ornl.gov>

stemtool.afit.atom_positions.fourier_mask(original_image, center, radius, threshold=0.2)[source]
stemtool.afit.atom_positions.get_coords(image, peak_pos, origin, current_coords)[source]
stemtool.afit.atom_positions.get_origin(image, peak_pos, coords)[source]
stemtool.afit.atom_positions.peaks_vis(data_image, dist=10, thresh=0.1, imsize=(20, 20))[source]

Find atom maxima pixels in images

Parameters:
  • data_image (ndarray) – Original atomic resolution image
  • dist (int) – Average distance between neighboring peaks Default is 10
  • thresh (float) – The cutoff intensity value below which a peak will not be detected Default is 0.1
  • imsize (ndarray) – Size of the display image Default is (20,20)
Returns:

peaks – List of peak positions as y, x

Return type:

ndarray

Notes

This is a wrapper around the skimage peak finding module which finds the peaks with a given threshold value and an inter-peak separation. The function additionally plots the peak positions on the original image thus users can modify the input values of threshold and distance to ensure the right peaks are selected.

Authors:

Debangshu Mukherjee <mukherjeed@ornl.gov>

stemtool.afit.atom_positions.remove_close_vals(input_arr, limit)[source]
stemtool.afit.atom_positions.strain_map(centers, e_yy, e_xx, e_xy, e_th, mask)[source]