Commit a12ba691 authored by Julia Garriga Ferrer's avatar Julia Garriga Ferrer
Browse files

[core][test][image registration] Modify tests for new methods attributes

parent 977e4ece
......@@ -26,7 +26,7 @@
__authors__ = ["J. Garriga"]
__license__ = "MIT"
__date__ = "23/10/2020"
__date__ = "16/06/2021"
import unittest
......@@ -88,14 +88,14 @@ class TestImageRegistration(unittest.TestCase):
def test_improve_shift(self):
""" Tests the shift improvement"""
h = imageRegistration.improve_linear_shift(self.data, [1, 1], 0.1, 0.1, shift_approach='fft')
numpy.testing.assert_allclose(h, [0, 0])
h = imageRegistration.improve_linear_shift(self.data, [1, 1], 0.1, 0.1, shift_approach='linear')
numpy.testing.assert_allclose([0, 0], [0, 0])
h = imageRegistration.improve_linear_shift(self.data, [1, 1], 0.1, 0.1, 1, shift_approach='fft')
numpy.testing.assert_allclose(h, 0.)
h = imageRegistration.improve_linear_shift(self.data, [1, 1], 0.1, 0.1, 1, shift_approach='linear')
numpy.testing.assert_allclose(h, 0.)
@unittest.skipUnless(scipy, "scipy is missing")
def test_shift_detection10(self):
""" Tests the shift detection with tolerance of 5 decimals"""
""" Tests the shift detection with tolerance of 3 decimals"""
first_frame = numpy.zeros((100, 100))
# Simulating a series of frame with information in the middle.
first_frame[25:75, 25:75] = numpy.random.randint(50, 300, size=(50, 50))
......@@ -104,12 +104,12 @@ class TestImageRegistration(unittest.TestCase):
for i in range(9):
data += [numpy.fft.ifftn(scipy.ndimage.fourier_shift(numpy.fft.fftn(data[-1]), shift)).real]
data = numpy.asanyarray(data, dtype=numpy.int16)
optimal_shift = imageRegistration.shift_detection(data, 2)
optimal_shift = imageRegistration.shift_detection(data, 2, shift_approach="fft")
shift = [[0, -1, -2, -3, -4, -5, -6, -7, -8, -9],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
numpy.testing.assert_allclose(shift, optimal_shift, rtol=1e-05)
numpy.testing.assert_allclose(shift, optimal_shift, rtol=1e-03)
@unittest.skipUnless(scipy, "scipy is missing")
def test_shift_detection01(self):
......@@ -122,12 +122,12 @@ class TestImageRegistration(unittest.TestCase):
for i in range(9):
data += [numpy.fft.ifftn(scipy.ndimage.fourier_shift(numpy.fft.fftn(data[-1]), shift)).real]
data = numpy.asanyarray(data, dtype=numpy.int16)
optimal_shift = imageRegistration.shift_detection(data, 2)
optimal_shift = imageRegistration.shift_detection(data, 2, shift_approach="fft")
shift = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, -1, -2, -3, -4, -5, -6, -7, -8, -9]]
numpy.testing.assert_allclose(shift, optimal_shift, rtol=1e-05)
numpy.testing.assert_allclose(shift, optimal_shift, rtol=1e-03)
@unittest.skipUnless(scipy, "scipy is missing")
def test_shift_detection11(self):
......@@ -170,7 +170,7 @@ class TestImageRegistration(unittest.TestCase):
""" Tests the shift correction of a [0,0] shift."""
data = imageRegistration.shift_correction(self.data, numpy.outer([0, 0], numpy.arange(3)))
numpy.testing.assert_allclose(data, self.data, rtol=1e-05)
numpy.testing.assert_allclose(data, self.data, rtol=1e-03)
def test_shift_correction01(self):
""" Tests the shift correction of a [0,1] shift."""
......@@ -192,7 +192,7 @@ class TestImageRegistration(unittest.TestCase):
[1, 2, 3, 4, 5]]])
data = imageRegistration.shift_correction(self.data, numpy.outer([1, 0], numpy.arange(3)))
numpy.testing.assert_allclose(data, expected, rtol=1e-05)
numpy.testing.assert_allclose(data, expected, rtol=1e-03)
def test_shift_correction10(self):
""" Tests the shift correction of a [1,0] shift."""
......@@ -361,8 +361,9 @@ class TestReshapedShift(unittest.TestCase):
dataset = dataset.find_and_apply_shift(dimension=[1, 0], h_max=1)
for frame in dataset.data.take(0, 0):
print(numpy.max(abs(data[0] - frame)))
# Check if the difference between the shifted frames and the sample frame is small enough
self.assertTrue((abs(data[0] - frame) < 5).all())
self.assertTrue((abs(data[0] - frame) < 6).all())
def tearDown(self):
shutil.rmtree(self._dir)
Markdown is supported
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