Skip to content

Commit

Permalink
updated warp function to work on centered diff
Browse files Browse the repository at this point in the history
  • Loading branch information
ahoust17 committed Sep 13, 2023
1 parent d015f18 commit 7b3313f
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions pyTEMlib/image_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,24 +910,30 @@ def cartesian2polar(x, y, grid, r, t, order=3):
return ndimage.map_coordinates(grid, np.array([new_ix, new_iy]), order=order).reshape(new_x.shape)


def warp(diff, center):
"""Convert diffraction pattern to polar coordinates"""
def warp(diff):
"""Takes a centered diffraction pattern (as a sidpy dataset)and warps it to a polar grid"""
"""Centered diff can be produced with it.diffractogram_spots(return_center = True)"""

# Define original polar grid
nx = diff.shape[0]
ny = diff.shape[1]
nx = np.shape(diff)[0]
ny = np.shape(diff)[1]

x = np.linspace(1, nx, nx, endpoint=True)-center[1]
y = np.linspace(1, ny, ny, endpoint=True)-center[0]
z = np.abs(diff)
# Define center pixel
pix2nm = np.gradient(diff.u.values)[0]
center_pixel = [abs(min(diff.u.values)), abs(min(diff.v.values))]//pix2nm

x = np.linspace(1, nx, nx, endpoint = True)-center_pixel[0]
y = np.linspace(1, ny, ny, endpoint = True)-center_pixel[1]
z = diff

# Define new polar grid
nr = min([center[0], center[1], diff.shape[0]-center[0], diff.shape[1]-center[1]])-1
nr = int(min([center_pixel[0], center_pixel[1], diff.shape[0]-center_pixel[0], diff.shape[1]-center_pixel[1]])-1)
nt = 360*3

r = np.linspace(1, nr, nr)
t = np.linspace(0., np.pi, nt, endpoint=False)
return cartesian2polar(x, y, z, r, t, order=3).T
t = np.linspace(0., np.pi, nt, endpoint = False)

return cartesian2polar(x,y, z, r, t, order=3)


def calculate_ctf(wavelength, cs, defocus, k):
Expand Down

0 comments on commit 7b3313f

Please sign in to comment.