Commit f8e57892 authored by Nicola Vigano's avatar Nicola Vigano
Browse files

Alignment: finished implementation of DetectorTranslationAlongBeam.find_shift



This is also based on some code prepared by Christian Nemoz

Signed-off-by: Nicola Vigano's avatarNicola VIGANÒ <nicola.vigano@esrf.fr>
parent a99e3a84
......@@ -339,7 +339,7 @@ class CenterOfRotation(AlignmentBase):
All options are:
None | 'constant' | 'edge' | 'linear_ramp' | 'maximum' | 'mean'
| 'median' | 'minimum' | 'reflect' | 'symmetric' |'wrap'
peak_fit_radius: int
peak_fit_radius: int, optional
Radius size around the max correlation pixel, for sub-pixel fitting.
Minimum and default value is 1.
......@@ -449,11 +449,14 @@ class DetectorTranslationAlongBeam(AlignmentBase):
median_filt_shape=None,
padding_mode=None,
peak_fit_radius=2,
equispaced_increments=False
):
"""Find the deviation of the translation axis of the area detector
along the beam propagation direction.
TODO: Add more information here! Including interpretation of the result
This means giving also an example on how to convert the returned values
into meaningful quantities. See "Returns" for more details.
Parameters
----------
......@@ -477,14 +480,24 @@ class DetectorTranslationAlongBeam(AlignmentBase):
All options are:
None | 'constant' | 'edge' | 'linear_ramp' | 'maximum' | 'mean'
| 'median' | 'minimum' | 'reflect' | 'symmetric' |'wrap'
peak_fit_radius: int
peak_fit_radius: int, optional
Radius size around the max correlation pixel, for sub-pixel fitting.
Minimum and default value is 1.
equispaced_increments: boolean, optional
Tells whether the position increments are equispaced or not. If
equispaced increments are used, we have to compute the correlation
images with respect to the first image, otherwise we can do it
against adjacent images.
The advantage of doing it between adjacent images is that we do not
build up large displacements in the correlation.
However, if this is done for equispaced images, the linear fitting
becomes unstable.
Returns
-------
tuple(float, float)
Estimated (vertical, horizontal) increment per unit-distance of the shift.
Estimated (vertical, horizontal) increment per unit-distance of the
ratio between pixel-size and detector translation.
Examples
--------
......@@ -507,7 +520,9 @@ class DetectorTranslationAlongBeam(AlignmentBase):
# do correlations
ccs = [
self._compute_correlation_fft(img_stack[ii - 1, ...], img_stack[ii, ...], padding_mode)
self._compute_correlation_fft(
img_stack[0 if equispaced_increments else ii - 1, ...], img_stack[ii, ...], padding_mode
)
for ii in range(1, num_imgs)
]
......@@ -531,22 +546,14 @@ class DetectorTranslationAlongBeam(AlignmentBase):
shifts_vh[ii, :] = self.refine_max_position_2d(f_vals, fv, fh)
"""
TODO: finish implementing the following logic!
pos -= repmat(pos(:,1),1,ni);
ph = polyfit(motpos,pos(1,:),1);
thz = ph(1)*pixsize/1000*180/pi;
printf('Correction in horizontal angle: %5.2f urad -> mvr thz %5.4f\n',thz*pi/180*1e6,thz)
figure(1);
plot(motpos,pos(1,:))
title('Horizontal displacement')
pv = polyfit(motpos,pos(2,:),1);
thy = pv(1)*pixsize/1000*180/pi;
printf('Correction in vertical angle: %5.2f urad -> mvr thy %5.4f\n',thy*pi/180*1e6,thy)
figure(2);
plot(motpos,pos(2,:))
title('Vertical displacement')
"""
if equispaced_increments:
img_pos_increments = img_pos[1:] - img_pos[0]
else:
img_pos_increments = - np.diff(img_pos)
# Polynomial.fit is supposed to be more numerically stable than polyfit
# (according to numpy)
coeffs_v = Polynomial.fit(img_pos_increments, shifts_vh[:, 0], deg=1).convert().coef
coeffs_h = Polynomial.fit(img_pos_increments, shifts_vh[:, 1], deg=1).convert().coef
return coeffs_v[1], coeffs_h[1]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment