Commit abcb43a9 authored by myron's avatar myron Committed by Pierre Paleo
Browse files

black applied

parent 5c365cba
......@@ -488,7 +488,7 @@ class CenterOfRotation(AlignmentBase):
peak_fit_radius=1,
high_pass=None,
low_pass=None,
half_tomo_cor_guess=None
half_tomo_cor_guess=None,
):
"""Find the Center of Rotation (CoR), given two images.
......@@ -578,13 +578,12 @@ class CenterOfRotation(AlignmentBase):
img_2 = self._prepare_image(img_2, roi_yxhw=roi_yxhw, median_filt_shape=median_filt_shape)
if half_tomo_cor_guess is not None:
cor_in_img = img_1.shape[1]//2 + half_tomo_cor_guess
tmpsigma = (img_1.shape[1] - cor_in_img)/4.0
tmpx = (np.arange(img_1.shape[1]) -cor_in_img)/tmpsigma
apodis = np.exp( -tmpx*tmpx/2.0 )
img_1[:] = img_1 *apodis
cor_in_img = img_1.shape[1] // 2 + half_tomo_cor_guess
tmpsigma = (img_1.shape[1] - cor_in_img) / 4.0
tmpx = (np.arange(img_1.shape[1]) - cor_in_img) / tmpsigma
apodis = np.exp(-tmpx * tmpx / 2.0)
img_1[:] = img_1 * apodis
cc = self._compute_correlation_fft(img_1, img_2, padding_mode, high_pass=high_pass, low_pass=low_pass)
img_shape = img_2.shape
cc_vs = np.fft.fftfreq(img_shape[-2], 1 / img_shape[-2])
......@@ -598,15 +597,15 @@ class CenterOfRotation(AlignmentBase):
# we correct for that here
tmp = fitted_shifts_vh[-1]
p1 = tmp
if( tmp<0):
if tmp < 0:
p2 = cc.shape[1] + tmp
else:
p2 = -cc.shape[1] + tmp
if( abs(half_tomo_cor_guess-p1/2) <abs(half_tomo_cor_guess-p2/2)) :
return p1/2
p2 = -cc.shape[1] + tmp
if abs(half_tomo_cor_guess - p1 / 2) < abs(half_tomo_cor_guess - p2 / 2):
return p1 / 2
else:
return p2/2
return p2 / 2
return fitted_shifts_vh[-1] / 2.0
__call__ = find_shift
......
......@@ -7,6 +7,7 @@ from silx.resources import ExternalResources
try:
import scipy.ndimage
__has_scipy__ = True
except ImportError:
__has_scipy__ = False
......@@ -14,6 +15,7 @@ except ImportError:
from nabu.preproc import alignment
from nabu.testutils import utilstest, __do_long_tests__
@pytest.fixture(scope="class")
def bootstrap_base(request):
cls = request.cls
......@@ -162,7 +164,7 @@ def _get_challenging_ImsCouple_for_halftomo_cor():
"""
np.random.seed(0)
NY = 400
NX = 500
......@@ -173,7 +175,7 @@ def _get_challenging_ImsCouple_for_halftomo_cor():
widths = 3 * np.random.random(npoints)
im1 = _peaks2im(possY, possX, widths, NY, NX)
CHT = 201.67
CenterX = 400.123
......@@ -205,7 +207,7 @@ def _get_challenging_ImsCouple_for_halftomo_cor():
im1[:] += noise_ima1
im2[:] += noise_ima2
return im1, im2, (CenterX - (NX - 1) / 2.0) / 2.0
return im1, im2, (CenterX - (NX - 1) / 2.0)
@pytest.mark.usefixtures("bootstrap_base")
......@@ -288,7 +290,7 @@ class TestCor(object):
message = "Computed CoR %f " % cor_position + " and real CoR %f do not coincide" % self.cor_gl_pix
assert np.isclose(self.cor_gl_pix, cor_position, atol=self.abs_tol), message
@pytest.mark.skipif(not(__has_scipy__), reason="need scipy for this test")
@pytest.mark.skipif(not (__has_scipy__), reason="need scipy for this test")
def test_noisyHF_cor_posx(self):
""" test with noise at high frequencies
"""
......@@ -330,7 +332,6 @@ class TestCor(object):
)
assert not np.isclose(cor_pos, cor_position, atol=self.abs_tol), message
def test_half_tomo_cor(self):
""" test that the half tomo algorithm is precise enough
"""
......@@ -339,14 +340,13 @@ class TestCor(object):
cor_pos = self.ht_cor
CoR_calc = alignment.CenterOfRotation()
cor_position = CoR_calc.find_shift(radio1, radio2, low_pass=1, high_pass=20, half_tomo_cor_guess= cor_pos-10.0)
cor_position = CoR_calc.find_shift(radio1, radio2, low_pass=1, high_pass=20, half_tomo_cor_guess=cor_pos - 10.0)
message = (
"Computed CoR %f " % cor_position
+ " and real CoR %f should coincide when using the halftomo algorithm with hald tomo data" % cor_pos
)
assert np.isclose(cor_pos, cor_position, atol=self.abs_tol), message
assert np.isclose(cor_pos, cor_position, atol=self.abs_tol), message
def test_cor_posx_linear(self):
radio1 = self.data[0, :, :]
......@@ -426,7 +426,7 @@ class TestDetectorTranslation(object):
message = "Computed shifts %s and expected %s do not coincide" % (found_shifts_list, self.all_shifts_vh)
assert np.all(np.isclose(found_shifts_list, self.all_shifts_vh, atol=self.abs_tol)), message
@pytest.mark.skipif(not(__has_scipy__), reason="need scipy for this test")
@pytest.mark.skipif(not (__has_scipy__), reason="need scipy for this test")
def test_alignxc_synth(self):
T_calc = alignment.DetectorTranslationAlongBeam()
......@@ -447,7 +447,7 @@ class TestDetectorTranslation(object):
assert np.all(np.isclose((shifts_v, shifts_h), (-1.234 * 2, -1.234), atol=self.abs_tol)), message
@pytest.mark.skipif(not(__do_long_tests__), reason="need environment variable NABU_LONG_TESTS=1")
@pytest.mark.skipif(not (__do_long_tests__), reason="need environment variable NABU_LONG_TESTS=1")
@pytest.mark.usefixtures("bootstrap_fcs")
class TestFocus(object):
def test_find_distance(self):
......@@ -471,7 +471,7 @@ class TestFocus(object):
assert np.isclose(self.angle_best_ind, focus_ind, atol=self.abs_tol_dist), message
expected_tilts_vh = np.squeeze(np.array([self.angle_tilt_v, self.angle_tilt_h]))
computed_tilts_vh = - tilts_vh / (self.pixel_size / 1000)
computed_tilts_vh = -tilts_vh / (self.pixel_size / 1000)
message = "Computed tilts %s and expected %s do not coincide" % (computed_tilts_vh, expected_tilts_vh)
assert np.all(np.isclose(computed_tilts_vh, expected_tilts_vh, atol=self.abs_tol_tilt)), 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