Skip to content

Commit

Permalink
Fixed formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sivborg committed Nov 14, 2023
1 parent 030f9c8 commit f73fb42
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions pyxem/utils/pixelated_stem_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,17 @@ def _f_min(X, p):
def _residuals(params, X):
return _f_min(X, params)


def _distance_residuals(params, X):
plane_x_xy = params[0:2]
plane_y_xy = params[3:5]
distance_x = (plane_x_xy * X[:,:2]).sum(axis=1) + params[2]
distance_y = (plane_y_xy * X[:,:2]).sum(axis=1) + params[5]
distance = np.sqrt(((distance_x-X[:,2])**2 + (distance_y-X[:,3])**2))
distance_x = (plane_x_xy * X[:, :2]).sum(axis=1) + params[2]
distance_y = (plane_y_xy * X[:, :2]).sum(axis=1) + params[5]
distance = np.sqrt(((distance_x - X[:, 2]) ** 2 + (distance_y - X[:, 3]) ** 2))

return distance


def _plane_parameters_to_image(p, xaxis, yaxis):
"""Get a plane 2D array from plane parameters.
Expand Down Expand Up @@ -195,13 +197,14 @@ def _get_linear_plane_from_signal2d(signal, mask=None, initial_values=None):
plane = _plane_parameters_to_image(p, xaxis, yaxis)
return plane


def _get_linear_xy_planes_from_signal2d(signal, mask=None, initial_values=None):
if len(signal.axes_manager.navigation_axes) != 2:
raise ValueError("signal need to have 2 navigation dimensions")
if len(signal.axes_manager.signal_axes) != 1:
raise ValueError("signal need to have 1 signal dimension")
if initial_values is None:
initial_values = [0.1]*6
initial_values = [0.1, 0.1, 0.1, 0.1, 0.1, 0.1]

signal = signal.T
sam = signal.axes_manager.signal_axes
Expand All @@ -218,10 +221,9 @@ def _get_linear_xy_planes_from_signal2d(signal, mask=None, initial_values=None):

p = opt.leastsq(_distance_residuals, initial_values, args=points)[0]


x, y = np.meshgrid(xaxis, yaxis)
z_x = p[0]*x + p[1]*y + p[2]
z_y = p[3]*x + p[4]*y + p[5]
z_x = p[0] * x + p[1] * y + p[2]
z_y = p[3] * x + p[4] * y + p[5]

return np.stack((z_x, z_y), axis=-1)

Expand Down

0 comments on commit f73fb42

Please sign in to comment.