Skip to content

Commit

Permalink
black formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
jonwright committed Mar 28, 2024
1 parent 3b62437 commit 2533b6b
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions ImageD11/sinograms/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def dtymask(i, j, cosomega, sinomega, dtyi, step, y0):

def recon_space_to_real_space(i, j, recon_shape, ystep, y0):
"""Convert pixel position in reconstruction space (i, j) to real space
i, j are indices to the reconstruction image
recon_shape is a tuple of the shape of the reconstruction array
ystep is the dty step (microns or mm per pixel, dty motor unit)"""
i, j are indices to the reconstruction image
recon_shape is a tuple of the shape of the reconstruction array
ystep is the dty step (microns or mm per pixel, dty motor unit)"""
x = (i - recon_shape[0] // 2) * ystep + y0
y = -(j - recon_shape[1] // 2) * ystep + y0

Expand All @@ -32,8 +32,8 @@ def real_space_to_recon_space(x, y, recon_shape, ystep, y0):
"""Convert real space (x, y) position to reconstruction space.
Should be the exact opposite of recon_space_to_real_space()
Accounts for the shape of the reconstruction because the origin in reconstruction space is in the corner of the image."""
i = recon_shape[0]//2 + (x - y0)/ystep
j = -(recon_shape[1] // 2 + (y - y0)/ystep)
i = recon_shape[0] // 2 + (x - y0) / ystep
j = -(recon_shape[1] // 2 + (y - y0) / ystep)

return i, j

Expand All @@ -45,9 +45,17 @@ def sine_function(omega, offset, a, b):

def fit_sine_wave(omega, dty, initial_guess):
"""Fits a sine wave to omega and dty data
Returns sine wave coefficients and offset
To convert coefficients into lab positions, use sine_coeffs_to_lab_position()"""
popt, _ = curve_fit(sine_function, omega, dty, p0=initial_guess, method='trf', loss='soft_l1', max_nfev=10000)
Returns sine wave coefficients and offset
To convert coefficients into lab positions, use sine_coeffs_to_lab_position()"""
popt, _ = curve_fit(
sine_function,
omega,
dty,
p0=initial_guess,
method="trf",
loss="soft_l1",
max_nfev=10000,
)

offset, a, b = popt

Expand Down Expand Up @@ -85,10 +93,10 @@ def fit_lab_position_from_peaks(omega, dty):

def fit_lab_position_from_recon(recon, ystep, y0):
"""Fits grain position by doing a LoG search with skimage on the reconstruction image
Useful if grain is very small (close to pointlike)
Returns position in lab frame (unit matches ystep)
Returns None if we couldn't find any blobs"""
blobs = blob_log(recon, min_sigma=1, max_sigma=10, num_sigma=10, threshold=.01)
Useful if grain is very small (close to pointlike)
Returns position in lab frame (unit matches ystep)
Returns None if we couldn't find any blobs"""
blobs = blob_log(recon, min_sigma=1, max_sigma=10, num_sigma=10, threshold=0.01)
blobs_sorted = sorted(blobs, key=lambda x: x[2], reverse=True)
try:
largest_blob = blobs_sorted[0]
Expand All @@ -106,7 +114,9 @@ def fit_lab_position_from_recon(recon, ystep, y0):

# the below should be independent, tested, inside sinograms/geometry

x, y = recon_space_to_real_space(x_recon_space, y_recon_space, recon.shape, ystep, y0)
x, y = recon_space_to_real_space(
x_recon_space, y_recon_space, recon.shape, ystep, y0
)

return x, y
except IndexError:
Expand Down

0 comments on commit 2533b6b

Please sign in to comment.