Skip to content

Commit

Permalink
Better log test_correl
Browse files Browse the repository at this point in the history
  • Loading branch information
paugier committed May 24, 2024
1 parent 83d8fd3 commit b1c07b3
Showing 1 changed file with 20 additions and 29 deletions.
49 changes: 20 additions & 29 deletions src/fluidimage/calcul/test_correl.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def setUpClass(cls):
)


for k, cls in classes.items():
for method, cls in classes.items():

def _test(self, cls=cls, k=k):
def _test(self, cls=cls, name=method):
if issubclass(cls, CorrelFFTBase):
displacement_max = "50%"
else:
Expand All @@ -86,7 +86,7 @@ def _test(self, cls=cls, k=k):
) = correl.compute_displacements_from_correl(c, norm=norm)
displacement_computed = np.array([dx, dy])

print(f"{k}, displacement = [0, 0]\t error= {abs(displacement_computed)}")
print(f"{name}, displacement = [0, 0]\t{abs(displacement_computed) = }")

assert np.allclose([0, 0], displacement_computed, atol=1e-03)
assert np.allclose(correl_max, 1.0), correl_max
Expand All @@ -99,19 +99,16 @@ def _test(self, cls=cls, k=k):

displacement_computed = np.array([dx, dy])

logger.debug(
k
+ ", displacement = {}\t error= {}\n".format(
self.displacements,
abs(displacement_computed - self.displacements),
)
print(
f"{name}, displacement = {self.displacements}\t"
f"error = {abs(displacement_computed - self.displacements)}"
)

self.assertTrue(
np.allclose(self.displacements, displacement_computed, atol=0.8)
)

exec("TestCorrel.test_correl_square_image_" + k + " = _test")
exec("TestCorrel.test_correl_square_image_" + method + " = _test")


class TestCorrel1(unittest.TestCase):
Expand All @@ -136,9 +133,9 @@ def setUpClass(cls):
)


for k, cls in classes.items():
for method, cls in classes.items():

def _test1(self, cls=cls, k=k):
def _test1(self, cls=cls, name=method):
correl = cls(self.im0.shape, self.im1.shape)

# first, no displacement
Expand All @@ -149,7 +146,7 @@ def _test1(self, cls=cls, k=k):
displacement_computed = np.array([dx, dy])

logger.debug(
k
name
+ ", displacement = [0, 0]\t error= {}\n".format(
abs(displacement_computed)
)
Expand All @@ -166,19 +163,16 @@ def _test1(self, cls=cls, k=k):

displacement_computed = np.array([dx, dy])

logger.debug(
k
+ ", displacement = {}\t error= {}\n".format(
self.displacements,
abs(displacement_computed - self.displacements),
)
print(
f"{name}, displacement = {self.displacements}\t"
f"error = {abs(displacement_computed - self.displacements)}"
)

self.assertTrue(
np.allclose(self.displacements, displacement_computed, atol=0.8)
)

exec("TestCorrel1.test_correl_rectangular_image_" + k + " = _test1")
exec("TestCorrel1.test_correl_rectangular_image_" + method + " = _test1")


class TestCorrel2(unittest.TestCase):
Expand Down Expand Up @@ -211,9 +205,9 @@ def setUpClass(cls):
cls.im1 = cls.im1.astype("float32")


for k, cls in classes_real_space.items():
for method, cls in classes_real_space.items():

def _test2(self, cls=cls, k=k):
def _test2(self, cls=cls, name=method):
correl = cls(self.im0.shape, self.im1.shape, mode="valid")

# with the 2 figures with displacements
Expand All @@ -224,19 +218,16 @@ def _test2(self, cls=cls, k=k):

displacement_computed = np.array([dx, dy])

logger.debug(
k
+ ", displacement = {}\t error= {}\n".format(
self.displacements,
abs(displacement_computed - self.displacements),
)
print(
f"{name}, displacement = {self.displacements}\t"
f"error = {abs(displacement_computed - self.displacements)}"
)

self.assertTrue(
np.allclose(self.displacements, displacement_computed, atol=0.8)
)

exec("TestCorrel2.test_correl_images_diff_sizes_" + k + " = _test2")
exec("TestCorrel2.test_correl_images_diff_sizes_" + method + " = _test2")


def _test_like_fftshift(n0, n1):
Expand Down

0 comments on commit b1c07b3

Please sign in to comment.