stemtool.gpa package¶
Submodules¶
stemtool.gpa.gpa module¶
-
class
stemtool.gpa.gpa.GPA(image, calib, calib_units, ref_iter=20, use_blur=True, max_strain=0.4)[source]¶ Bases:
objectUse Geometric Phase Analysis (GPA) to measure strain in an electron micrograph by locating the diffraction spots and identifying a reference region
Parameters: - image (ndarray) – The image from which the strain will be measured from
- calib (float) – Size of an individual pixel
- calib_units (str) – Unit of calibration
- ref_iter (int, optional) – Number of iterations to run for refining the G vectors and the phase matrixes. Default is 20.
- use_blur (bool, optional) – Use a Gaussian blur to generate the phase matrix from a g vector. Default is True
References
[1] Hÿtch, M. J., E. Snoeck, and R. Kilaas. “Quantitative measurement of displacement and strain fields from HREM micrographs.” Ultramicroscopy 74.3 (1998): 131-146. Examples
Run as:
>>> im_gpa = gpa(image=imageDC, calib=calib1, calib_units= calib1_units)
Then to check the image you just loaded
>>> im_gpa.show_image()
Then, select the diffraction spots in inverse units that you want to be used for GPA. They must not be collinear.
>>> im_gpa.find_spots((5, 0), (0, -5))
where (5, 0) and (0, -5) are two diffraction spot locations. You can run the find_spots method manually multiple times till you locate the spots closely. After you have located the spots, you need to define a reference region for the image - with respect to which the strain will be calculated.
>>> im_gpa.define_reference((6.8, 6.9), (10.1, 6.8), (10.2, 9.5), (7.0, 9.6))
where (6.8, 6.9), (10.1, 6.8), (10.2, 9.5) and (7.0, 9.6) are the corners of the reference region you are defining.
>>> im_gpa.refine_phase() >>> e_xx, e_yy, e_theta, e_diag = im_gpa.get_strain()
To plot the obtained strain maps:
>>> im_gpa.plot_gpa_strain()
-
define_reference(A_pt, B_pt, C_pt, D_pt, imsize=(10, 10), 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
Notes
Locates a reference region bounded by the four points given in length units. Choose the points in a clockwise fashion.
-
find_spots(circ1, circ2, circ_size=15, imsize=(10, 10))[source]¶ Locate the diffraction spots visually.
Parameters: - circ1 (ndarray) – Position of the first beam in the Fourier pattern
- circ2 (ndarray) – Position of the second beam in the Fourier pattern
- circ_size (float) – Size of the circle in pixels
- imsize (tuple, optional) – Size in inches of the image with the diffraction spots marked. Default is (10, 10)
Notes
Put circles in red(central), y(blue) and x(green) on the diffraction pattern to approximately know the positions. We also convert the circle locations to G vectors by calling the static method circ_to_G. We use the G vector locations to also generate the initial phase matrices.
See also
-
get_strain()[source]¶ Use the refined phase matrix and g vectors to calculate the strain matrices.
Returns: - e_xx (ndarray) – Strain along X direction
- e_yy (ndarray) – Strain along Y direction
- e_th (ndarray) – Rotational strain
- e_dg (ndarray) – Diagonal Strain
Notes
Use the refined G vectors to generate a matrix of the lattice parameters, which is stored as the class attribute a_matrix. This is multiplied by the refined phase matrix, and the multiplicand is subsequently differentiated to get the strain parameters.
See also
-
plot_gpa_strain(mval=0, imwidth=15)[source]¶ Use the calculated strain matrices to plot the strain maps
Parameters: - mval (float, optional) – The maximum strain value that will be plotted. Default is 0, upon which the maximum strain percentage will be calculated, which will be used for plotting.
- imwidth (int, optional) – Size in inches of the image with the diffraction spots marked. Default is 15
Notes
Uses matplotlib.gridspec to plot the strain maps of the four types of strain calculated through geometric phase analysis.
-
stemtool.gpa.gpa.G_to_circ(g_vec, image)[source]¶ Convert g vectors in Fourier space to pixel positions in real space.
Parameters: - g_vec (ndarray) – Shape is (2, 1) which is the G vector in Fourier space in inverse pixels
- image (ndarray) – The image matrix
Returns: circ_pos – Shape is (2, 1) which is the corresponding pixel position in real space.
Return type: ndarray
See also
-
stemtool.gpa.gpa.circ_to_G(circ_pos, image)[source]¶ Convert a pixel position to g vectors in Fourier space.
Parameters: - circ_pos (tuple) – First phase image
- image (ndarray) – The image matrix
Returns: g_vec – Shape is (2, 1) which is the corresponding g-vector in inverse pixels
Return type: ndarray
See also
-
stemtool.gpa.gpa.g_matrix(g_vector, image)[source]¶ Multiply g vector with Fourier coordinates to generate a corresponding phase matrix
Parameters: - g_vec (ndarray) – Shape is (2, 1) which is the G vector in Fourier space in inverse pixels
- image (ndarray) – The image matrix
Returns: G_r – Same size as the image originally and gives the phase map for a given g vector
Return type: ndarray
-
stemtool.gpa.gpa.phase_diff(angle_image)[source]¶ Differentiate a complex phase image while ensuring that phase wrapping doesn’t distort the differentiation.
Parameters: angle_image (ndarray) – Wrapped phase image Returns: - diff_x (ndarray) – X differential of the phase image
- diff_y (ndarray) – Y differential of the phase image
Notes
The basic idea of this is that we differentiate the complex exponential of the phase image, and then obtain the differentiation result by multiplying the differential with the conjugate of the complex phase image.
[1] Hÿtch, M. J., E. Snoeck, and R. Kilaas. “Quantitative measurement of displacement and strain fields from HREM micrographs.” Ultramicroscopy 74.3 (1998): 131-146.
-
stemtool.gpa.gpa.phase_matrix(gvec, image, circ_size=0, g_blur=True)[source]¶ Use the g vector in Fourier coordinates to select only the subset of phases associated with that diffraction spot, a.k.a. the lattice parameter.
Parameters: - g_vec (ndarray) – Shape is (2, 1) which is the G vector in Fourier space in inverse pixels
- image (ndarray) – The image matrix
- circ_size (float, optional) – Size of the circle in pixels
- g_blur (bool, optional) –
Returns: P_matrix – Same size as the image originally and gives a real space phase matrix for a given real image and a g vector
Return type: ndarray
Notes
We put an aperture around a single diffraction spot, given by the g vector that generates the phase matrix associated with that diffraction spot. If the g vector is already refined, then in the reference region, the difference between this phase matrix and that given by g_matrix should be zero.
See also
-
stemtool.gpa.gpa.phase_subtract(matrix_1, matrix_2)[source]¶ Subtract one complex phase image from another without causing phase wrapping.
Parameters: - matrix_1 (ndarray) – First phase image
- matrix_2 (ndarray) – Second phase image
Returns: Difference of the phase images
Return type: ndarray
Notes
The basic idea of this is that we subtract the phase images from each other, then transform that to a complex phase, and take the angle of the complex image.