Commit 0c358ba3 authored by Olga Stamati's avatar Olga Stamati
Browse files

tests for LQC

parent 70bf6e0e
Pipeline #64625 passed with stages
in 12 minutes and 46 seconds
...@@ -143,6 +143,7 @@ class TestFunctionDVC(unittest.TestCase): ...@@ -143,6 +143,7 @@ class TestFunctionDVC(unittest.TestCase):
os.remove("spam-corrected-N12.tsv") os.remove("spam-corrected-N12.tsv")
os.remove("spamPhiFieldCF.tsv") os.remove("spamPhiFieldCF.tsv")
def test_applyPhiField(self): def test_applyPhiField(self):
a = numpy.random.rand(10, 10, 10) a = numpy.random.rand(10, 10, 10)
Phi = spam.deformation.computePhi({'t': [0.0, 3.0, 3.0]}) Phi = spam.deformation.computePhi({'t': [0.0, 3.0, 3.0]})
...@@ -415,8 +416,6 @@ class TestFunctionDVC(unittest.TestCase): ...@@ -415,8 +416,6 @@ class TestFunctionDVC(unittest.TestCase):
nodePositions, nodesDim2D = spam.DIC.grid.makeGrid((1, 50, 50), 10) nodePositions, nodesDim2D = spam.DIC.grid.makeGrid((1, 50, 50), 10)
self.assertEqual((1, 4, 4), nodesDim2D) self.assertEqual((1, 4, 4), nodesDim2D)
def test_grid(self):
im = spam.datasets.loadSnow() im = spam.datasets.loadSnow()
imageSize = im.shape imageSize = im.shape
...@@ -432,5 +431,30 @@ class TestFunctionDVC(unittest.TestCase): ...@@ -432,5 +431,30 @@ class TestFunctionDVC(unittest.TestCase):
grid3 = spam.DIC.makeGrid(imageSize, [10, 10, 10, 10]) grid3 = spam.DIC.makeGrid(imageSize, [10, 10, 10, 10])
self.assertTrue(grid3 is None) self.assertTrue(grid3 is None)
def test_kinematics(self):
# local quadratic coherency
points, _ = spam.DIC.grid.makeGrid((10, 10, 10), 2)
disp = numpy.ones_like(points, dtype='<f4')*5
# all points should be coherent
LQC1 = spam.DIC.estimateLocalQuadraticCoherency(points, disp, neighbourRadius=20)
self.assertEqual(len(numpy.where(LQC1 > 0.1)[0]), 0)
# set some bad points
dispMod = disp.copy()
dispMod[:4] = numpy.random.randint(-20, high=-2, size=[4, 3])
dispMod[20:25] = numpy.random.randint(-20, high=-2, size=[5, 3])
dispMod[-4:] = numpy.random.randint(-20, high=-2, size=[4, 3])
# try with radius
LQC2 = spam.DIC.estimateLocalQuadraticCoherency(points, dispMod, neighbourRadius=20)
self.assertTrue(len(numpy.where(LQC2 > 0.1)[0]), 13)
# try with number of neighbours
LQC3 = spam.DIC.estimateLocalQuadraticCoherency(points, dispMod, nNeighbours=35)
self.assertTrue(len(numpy.where(LQC3 > 0.1)[0]), 13)
# correct disp
dispModFit = spam.DIC.estimateDisplacementFromQuadraticFit(points, dispMod, LQC2, neighbourRadius=20)
self.assertTrue(numpy.allclose(dispModFit, disp))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
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