Commit 4c89c345 authored by myron's avatar myron
Browse files

added legacy test for detector translation using data from Christian

parent 3dc3d20c
Pipeline #27671 passed with stages
in 4 minutes and 34 seconds
......@@ -518,7 +518,8 @@ class DetectorTranslationAlongBeam(AlignmentBase):
median_filt_shape=None,
padding_mode=None,
peak_fit_radius=1,
equispaced_increments=True
equispaced_increments=True,
found_shifts_list=[]
):
"""Find the deviation of the translation axis of the area detector
along the beam propagation direction.
......@@ -561,6 +562,10 @@ class DetectorTranslationAlongBeam(AlignmentBase):
build up large displacements in the correlation.
However, if this is done for equispaced images, the linear fitting
becomes unstable.
found_shifts_list: list, optional
if a list is given in input, it will be populated
with the found shifts. For each given image of the stack a tuple of shifts will be
appended to the list. This slot is intended for introspection.
Returns
-------
......@@ -613,4 +618,11 @@ class DetectorTranslationAlongBeam(AlignmentBase):
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
if found_shifts_list is not None:
if not isinstance(found_shifts_list, list):
raise ValueError("If optional parameter found_shifts_list is given it must be a list."
"You have given an object of type %s" % type(found_shifts_list))
for vh in shifts_vh:
found_shifts_list.append(vh)
return coeffs_v[1], coeffs_h[1]
......@@ -3,8 +3,9 @@ import numpy as np
import os
import h5py
import scipy.ndimage
from silx.third_party.EdfFile import EdfFile
from nabu.preproc.alignment import CenterOfRotation
from nabu.preproc.alignment import CenterOfRotation, DetectorTranslationAlongBeam
from nabu.testutils import utilstest
......@@ -14,6 +15,12 @@ def bootstrap(request):
cls.data, cls.px = get_data_h5("tworadios.h5")
cls.cor_tol = 0.2
# loading alignxc edf files from Christian. The last one is the dark. The first 6 are images for translation 0,1...6
transcor_legacydatas = np.array([EdfFile(utilstest.getfile("alignxc%04d.edf" % i)).GetData(0,
DataType="FloatValue") for i in range(7)])
# removing dark
cls.transcor_legacydatas = (transcor_legacydatas[:-1] - transcor_legacydatas[-1])
def get_data_h5(*dataset_path):
"""
......@@ -151,3 +158,29 @@ class TestCor:
+ "other error raised instead:\n%s" % str(ex.value)
)
assert "Images need to be of the same shape" in str(ex.value), message
def test_alignxc(self):
T_calc = DetectorTranslationAlongBeam()
found_shifts_list = []
ab_v, ab_h = T_calc.find_shift(
self.transcor_legacydatas,
img_pos=(1+np.arange(6))*0.01,
roi_yxhw=None,
median_filt_shape=None,
padding_mode=None,
peak_fit_radius=1,
equispaced_increments=True,
found_shifts_list=found_shifts_list
)
reference_coeffs = (2551.2529860886843, 308.9007837781174)
reference_shifts_list = [[-121.39034751, 11.29080154], [-117.01864405, 3.81080018], [-115.66542712, 9.73375546],
[-116.72357645, 16.71435394], [6.024768, 20.28406386]]
message = ("Computed shifts coefficients %s and found ones %s do not coincide" % ((ab_v, ab_h), reference_coeffs))
assert (np.abs(np.array(reference_coeffs) - np.array([ab_v, ab_h]))).max() < 0.01, message
message = ("Computed shifts %s and found ones %s do not coincide" % (found_shifts_list, reference_shifts_list))
assert (np.abs(np.array(found_shifts_list) - np.array(reference_shifts_list))).max() < 0.0001, message
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