diff --git a/ImageD11/sinograms/geometry.py b/ImageD11/sinograms/geometry.py index 8248f7ed..9fe536ac 100644 --- a/ImageD11/sinograms/geometry.py +++ b/ImageD11/sinograms/geometry.py @@ -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 @@ -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 @@ -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 @@ -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] @@ -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: