Skip to content

Commit

Permalink
Added kwargs to base.tilt_align
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewHerzing committed Jun 18, 2024
1 parent bff118f commit 5ad293b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
1 change: 0 additions & 1 deletion tomotools/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,6 @@ def tilt_maximage(stack, limit=10, delta=0.1, plot_results=False, also_shift=Fal
shifted.data[:, :, i] = np.roll(ali.isig[idx, :].data, int(shifts[i]))
shifted_rec = shifted.reconstruct('SIRT', 100, constrain=True)
tilt_shift = shifts[shifted_rec.sum((1, 2)).data.argmin()]
print("Calculated tilt shift: %s pixels" % tilt_shift)
ali = ali.trans_stack(yshift=-tilt_shift)
ali.metadata.Tomography.yshift = -tilt_shift
return ali
Expand Down
37 changes: 19 additions & 18 deletions tomotools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ def stack_register(self, method="PC", start=None, show_progressbar=False, crop=F
out = align.shift_crop(out)
return out

def tilt_align(self, method, limit=10, delta=0.3, locs=None, nslices=20, show_progressbar=False):
def tilt_align(self, method, **kwargs):
"""
Align the tilt axis of a TomoStack.
Expand All @@ -613,27 +613,22 @@ def tilt_align(self, method, limit=10, delta=0.3, locs=None, nslices=20, show_pr
MaxImage: Perform automated determination of the tilt axis of a
TomoStack by analyzing features in the projected maximum image. A combination
of edge detection and Hough transform analysis is used to determine the global
rotation of the stack.
rotation of the stack. Optionally, the global shift of the tilt axis can also
be calculated by minimization of the sum of the reconstruction.
Args
----------
method : string
Algorithm to use for registration alignment. Must be either 'CoM' or
'MaxImage'.
delta : integer
Position i
limit : integer or float
Maximum rotation angle to use for MaxImage calculation
delta : float
Angular increment for MaxImage calculation
locs : list
Image coordinates indicating the locations at which to calculate
the alignment
axis : integer
Axis along which to extract sinograms. Value of 0 means tilt axis
is horizontally oriented. 1 means vertically oriented.
show_progressbar : boolean
Enable/disable progress bar
**kwargs: Additional keyword arguments. Possible keys include:
- nslices (int): Number of slices to use for the center of mass tilt alignment.
- locs (list): Location along tilt axis to use for center of mass tilt alignment.
- limit (integer or float): Maximum rotation angle to use for MaxImage calculation
- delta (float): Angular increment in degrees for MaxImage calculation
- plot_results (bool): if True, plot results of Hough line analysis
- also_shift (bool): if True, also calculate global shift of tilt axis
Returns
----------
Expand All @@ -654,15 +649,21 @@ def tilt_align(self, method, limit=10, delta=0.3, locs=None, nslices=20, show_pr
>>> stack = ds.get_needle_data()
>>> reg = stack.stack_register('PC',show_progressbar=False)
>>> method = 'MaxImage'
>>> ali = reg.tilt_align(method, show_progressbar=False)
>>> ali = reg.tilt_align(method)
"""
method = method.lower()

if method == "com":
nslices = kwargs.get('nslices', 20)
locs = kwargs.get('locs', None)
out = align.tilt_com(self, locs, nslices)
elif method == "maximage":
out = align.tilt_maximage(self, limit, delta, show_progressbar)
limit = kwargs.get('limit', 10)
delta = kwargs.get('delta', 0.3)
plot_results = kwargs.get('plot_results', False)
also_shift = kwargs.get('also_shift', False)
out = align.tilt_maximage(self, limit, delta, plot_results, also_shift)
else:
raise ValueError(
"Invalid alignment method: %s."
Expand Down

0 comments on commit 5ad293b

Please sign in to comment.