Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 23eec419 authored by Olga Stamati's avatar Olga Stamati
Browse files

tests for getImagettes() in grid

parent 0c358ba3
Pipeline #64705 passed with stages
in 12 minutes and 45 seconds
......@@ -16,17 +16,10 @@ You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>.
"""
from __future__ import print_function
import numpy
import spam.DIC.correlate
import sys
import progressbar
if sys.version[0] == '2':
import Queue as queue
else:
import queue as queue
def makeGrid(imageSize, nodeSpacing):
"""
......@@ -218,8 +211,10 @@ def getImagettes(im1, nodePosition, halfWindowSize, Phi, im2, searchRange, im1ma
# 2020-10-06 OS and EA: Add a pad to each dimension of 25% of max(halfWindowSize) to allow space to apply F (no displacement) to imagette1
applyPhiPad = int(0.5*numpy.ceil(max(halfWindowSize)))
if twoD: applyPhiPad = ( 0 , applyPhiPad, applyPhiPad)
else: applyPhiPad = (applyPhiPad, applyPhiPad, applyPhiPad)
if twoD:
applyPhiPad = ( 0 , applyPhiPad, applyPhiPad)
else:
applyPhiPad = (applyPhiPad, applyPhiPad, applyPhiPad)
# 2020-09-25 OS and EA: Prepare startStop array for imagette 1 to be extracted with new slicePadded
startStopIm1 = [int(nodePosition[0] - halfWindowSize[0] - applyPhiPad[0] ),
......@@ -241,6 +236,7 @@ def getImagettes(im1, nodePosition, halfWindowSize, Phi, im2, searchRange, im1ma
imagette1def = imagette1paddedDef[ : ,
applyPhiPad[1]:-applyPhiPad[1],
applyPhiPad[2]:-applyPhiPad[2]]
else:
imagette1def = imagette1paddedDef[applyPhiPad[0]:-applyPhiPad[0],
applyPhiPad[1]:-applyPhiPad[1],
......@@ -270,7 +266,6 @@ def getImagettes(im1, nodePosition, halfWindowSize, Phi, im2, searchRange, im1ma
maskVolumeCondition = (imagette1mask != 0).mean() >= minMaskCoverage
# Make sure imagette is not 0-dimensional in any dimension
# Check minMaskVolume
if numpy.all(numpy.array(imagette1def.shape) > 0) or (twoD and numpy.all(numpy.array(imagette1def.shape[1:3]) > 0)):
......
......@@ -403,7 +403,7 @@ class TestFunctionDVC(unittest.TestCase):
for i in range(3):
self.assertAlmostEqual(tVector[i], ps2[0][i]+topDisp[0], places=4)
# CASE XX: Catch asertion error when im1 is bigger than im2
# CASE XX: Catch assertion error when im1 is bigger than im2
self.assertRaises(AssertionError, spam.DIC.pixelSearch, imDef, im[subVolSliceRef].copy())
......@@ -432,11 +432,67 @@ class TestFunctionDVC(unittest.TestCase):
self.assertTrue(grid3 is None)
def test_kinematics(self):
# local quadratic coherency
def test_getImagettes(self):
# 3D image
imagetteReturns1 = spam.DIC.getImagettes(im, imCentre, [5, 5, 5], numpy.eye(4), im, numpy.zeros((6)),
applyF='no')
self.assertTrue(numpy.allclose(imagetteReturns1["imagette1"].shape, [11, 11, 11]))
self.assertTrue(numpy.allclose(imagetteReturns1["imagette1"], imagetteReturns1["imagette2"]))
# check masks + rigid Phi
imagetteReturns2 = spam.DIC.getImagettes(im, imCentre, [5, 5, 5], numpy.eye(4), im, numpy.zeros((6)),
im1mask=numpy.ones_like(im), im2mask=numpy.ones_like(im),
applyF='rigid')
self.assertTrue(numpy.allclose(imagetteReturns2["imagette1"].shape, [11, 11, 11]))
self.assertTrue(numpy.allclose(imagetteReturns2["imagette1"], imagetteReturns2["imagette2"]))
self.assertTrue(numpy.allclose(imagetteReturns2["imagette1mask"], numpy.ones_like(imagetteReturns2["imagette1"])))
self.assertTrue(numpy.allclose(imagetteReturns2["imagette1mask"], imagetteReturns2["imagette2mask"]))
# check apply F
Phi = numpy.eye(4)
Phi[0, 0] = 0.8
imagetteReturns3 = spam.DIC.getImagettes(im, imCentre, [5, 5, 5], Phi, im, numpy.zeros((6)),
applyF="all")
self.assertTrue(numpy.allclose(imagetteReturns3["imagette1"].shape, [11, 11, 11]))
# check apply F with im1mask
Phi = numpy.eye(4)
Phi[0, 0] = 0.8
imagetteReturns4 = spam.DIC.getImagettes(im, imCentre, [5, 5, 5], Phi, im, numpy.zeros((6)),
im1mask=numpy.ones_like(im),
applyF="all")
self.assertTrue(numpy.allclose(imagetteReturns4["imagette1"].shape, [11, 11, 11]))
self.assertTrue(numpy.allclose(imagetteReturns4["imagette1mask"].shape, [11, 11, 11]))
# check apply F with im1mask in 2D
Phi = numpy.eye(4)
Phi[0, 0] = 0.8
im2D = im[10]
im2D = im2D[numpy.newaxis, ...]
imagetteReturns5 = spam.DIC.getImagettes(im2D, [0, 25, 25], [0, 5, 5], Phi, im2D, numpy.zeros((6)),
im1mask=numpy.ones_like(im2D),
applyF="all", twoD=True)
self.assertTrue(numpy.allclose(imagetteReturns5["imagette1"].shape, [1, 11, 11]))
self.assertTrue(numpy.allclose(imagetteReturns5["imagette1mask"].shape, [1, 11, 11]))
# fails glt
imagetteReturns6 = spam.DIC.getImagettes(im, imCentre, [5, 5, 5], numpy.eye(4), im, numpy.zeros((6)),
applyF='no', greyThreshold=[numpy.inf, numpy.inf])
self.assertEqual(imagetteReturns6["returnStatus"], -5)
self.assertTrue(imagetteReturns6["imagette1"] is None)
# fails masks vol
imagetteReturns7 = spam.DIC.getImagettes(im, imCentre, [5, 5, 5], numpy.eye(4), im, numpy.zeros((6)),
im1mask=numpy.zeros_like(im), im2mask=numpy.ones_like(im),
minMaskCoverage=0.5)
self.assertEqual(imagetteReturns7["returnStatus"], -5)
self.assertTrue(imagetteReturns7["imagette1"] is None)
def test_LQC(self):
points, _ = spam.DIC.grid.makeGrid((10, 10, 10), 2)
disp = numpy.ones_like(points, dtype='<f4')*5
# all points should be coherent
LQC0 = spam.DIC.estimateLocalQuadraticCoherency(points, disp, neighbourRadius=1)
LQC1 = spam.DIC.estimateLocalQuadraticCoherency(points, disp, neighbourRadius=20)
self.assertEqual(len(numpy.where(LQC1 > 0.1)[0]), 0)
......@@ -445,6 +501,7 @@ class TestFunctionDVC(unittest.TestCase):
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)
......@@ -452,9 +509,12 @@ class TestFunctionDVC(unittest.TestCase):
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))
# correct disp with radius
dispModFit2 = spam.DIC.estimateDisplacementFromQuadraticFit(points, dispMod, LQC2, neighbourRadius=20)
self.assertTrue(numpy.allclose(dispModFit2, disp))
# correct disp with neighbours
dispModFit3 = spam.DIC.estimateDisplacementFromQuadraticFit(points, dispMod, LQC3, nNeighbours=35)
self.assertTrue(numpy.allclose(dispModFit3, disp))
if __name__ == '__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