pycroscopy / stemtool

A single package for analyzing atomic resolution STEM, 4D-STEM and STEM-EELS datasets, along with basic STEM simulation functionality
MIT License
16 stars 3 forks source link

The defination of some parameters in STEMTOOL? #5

Open PhysXu opened 2 months ago

PhysXu commented 2 months ago

Hi, dear Dr. Mukherjee,

I am interested in the _relative_strain and strain_map_ functions in atom_position .py of stemtool.

But, I did not find the annotations of parameters of _nlist, coords, centers, mask in the github.

Could you kindly tell me the defination/details of these above four parameters?

Thanks in advance.

def relative_strain(n_list, coords):
    warnings.filterwarnings("ignore")
    identity = np.asarray(((1, 0), (0, 1)))
    axis_pos = np.asarray(((0, 0), (1, 0), (0, 1), (1, 1)))
    no_atoms = (np.shape(n_list))[0]
    coords_inv = np.linalg.inv(coords)
    cell_center = np.zeros((no_atoms, 2))
    e_xx = np.zeros(no_atoms)
    e_xy = np.zeros(no_atoms)
    e_yy = np.zeros(no_atoms)
    e_th = np.zeros(no_atoms)
    for ii in range(no_atoms):
        cc = np.zeros((4, 2))
        cc[0, :] = n_list[ii, 0:2] - n_list[ii, 0:2]
        cc[1, :] = n_list[ii, 2:4] - n_list[ii, 0:2]
        cc[2, :] = n_list[ii, 4:6] - n_list[ii, 0:2]
        cc[3, :] = n_list[ii, 6:8] - n_list[ii, 0:2]
        l_cc, _, _, _ = np.linalg.lstsq(axis_pos, cc, rcond=None)
        t_cc = np.matmul(l_cc, coords_inv) - identity
        e_yy[ii] = t_cc[0, 0]
        e_xx[ii] = t_cc[1, 1]
        e_xy[ii] = 0.5 * (t_cc[0, 1] + t_cc[1, 0])
        e_th[ii] = 0.5 * (t_cc[0, 1] - t_cc[1, 0])
        cell_center[ii, 0] = 0.25 * (
            n_list[ii, 0] + n_list[ii, 2] + n_list[ii, 4] + n_list[ii, 6]
        )
        cell_center[ii, 1] = 0.25 * (
            n_list[ii, 1] + n_list[ii, 3] + n_list[ii, 5] + n_list[ii, 7]
        )
    return cell_center, e_yy, e_xx, e_xy, e_th

def strain_map(centers, e_yy, e_xx, e_xy, e_th, mask):
    yr, xr = np.mgrid[0 : mask.shape[0], 0 : mask.shape[1]]
    cartcoord = list(zip(centers[:, 1], centers[:, 0]))

    e_yy[np.abs(e_yy) > 3 * np.median(np.abs(e_yy))] = 0
    e_xx[np.abs(e_xx) > 3 * np.median(np.abs(e_xx))] = 0
    e_xy[np.abs(e_xy) > 3 * np.median(np.abs(e_xy))] = 0
    e_th[np.abs(e_th) > 3 * np.median(np.abs(e_th))] = 0

    f_yy = scinterp.LinearNDInterpolator(cartcoord, e_yy)
    f_xx = scinterp.LinearNDInterpolator(cartcoord, e_xx)
    f_xy = scinterp.LinearNDInterpolator(cartcoord, e_xy)
    f_th = scinterp.LinearNDInterpolator(cartcoord, e_th)

    map_yy = f_yy(xr, yr)
    map_yy[np.isnan(map_yy)] = 0
    map_yy = np.multiply(map_yy, mask)

    map_xx = f_xx(xr, yr)
    map_xx[np.isnan(map_xx)] = 0
    map_xx = np.multiply(map_xx, mask)

    map_xy = f_xy(xr, yr)
    map_xy[np.isnan(map_xy)] = 0
    map_xy = np.multiply(map_xy, mask)

    map_th = f_th(xr, yr)
    map_th[np.isnan(map_th)] = 0
    map_th = np.multiply(map_th, mask)

    return map_yy, map_xx, map_xy, map_th