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 13c8f74e authored by Gustavo Pinzon's avatar Gustavo Pinzon
Browse files

spam-ddic with -skp working, test included

parent 1803e6e5
Pipeline #65567 passed with stages
in 13 minutes and 47 seconds
......@@ -101,7 +101,12 @@ for label in range(numberOfLabels):
# Option 2 - load previous DVC
#################################
if args.PHIFILE is not None:
PhiFromFile = spam.helpers.readCorrelationTSV(args.PHIFILE.name, fieldBinRatio=args.PHIFILE_BIN_RATIO)
PhiFromFile = spam.helpers.readCorrelationTSV(args.PHIFILE.name,
fieldBinRatio=args.PHIFILE_BIN_RATIO,
readConvergence=True,
readError=True,
readLabelDilate=True,
readPixelSearchCC=True)
# If the read Phi-file has only one line -- it's a single point registration!
if PhiFromFile['fieldCoords'].shape[0] == 1:
......@@ -143,7 +148,15 @@ if args.PHIFILE is not None:
print(f"spam-ddic: Input PhiField positions from {args.PHIFILE.name} are not within 1px of the centre of mass of the labels from {args.lab1.name}, this seems dangerous.")
print(f"\tplease consider using spam-passPhiField to apply your PhiField to a new labelled image")
exit()
else:
if args.SKIP_PARTICLES:
#Read the previous result for all grains -- new grains will be overwritten
returnStatus = PhiFromFile["returnStatus"]
iterations = PhiFromFile["iterations"]
deltaPhiNorm = PhiFromFile["deltaPhiNorm"]
labelDilateList = PhiFromFile["LabelDilate"]
error = PhiFromFile["error"]
PSCC = PhiFromFile["pixelSearchCC"]
def correlateOneLabel(label):
#label, labelDilateCurrent = q.get()
......@@ -203,12 +216,13 @@ def correlateOneLabel(label):
# Add labels to a queue -- mostly useful for MPI
#q = queue.Queue()
labelsToCorrelate = numpy.arange(0, numberOfLabels)
if args.SKIP_PARTICLES:
labelsToCorrelate = numpy.delete(labelsToCorrelate, numpy.where(returnStatus != 2))
labelsToCorrelate = numpy.delete(labelsToCorrelate, numpy.where(returnStatus == 2))
labelsToCorrelate = numpy.delete(labelsToCorrelate, 0)
else:
labelsToCorrelate = numpy.delete(labelsToCorrelate, 0)
if args.PROCESSES is None: args.PROCESSES = multiprocessing.cpu_count()
print("\n\tStarting Discrete DIC (with {} process{})".format(args.PROCESSES, 'es' if args.PROCESSES > 1 else ''))
......
......@@ -45,6 +45,9 @@ class testAll(unittest.TestCase):
try:
rm(testFolder+"balls-2b-ddic.tsv")
rm(testFolder+"balls-2b-ddic.vtk")
rm(testFolder+"balls-2c-reg-passed-labelled.tsv")
rm(testFolder+"balls-2d-ddic.tsv")
rm(testFolder+"balls-2d-ddic.vtk")
rm(testFolder+"balls-3a-ddic.tsv")
rm(testFolder+"balls-3a-ddic.vtk")
rm(testFolder+"balls-5a-pixelSearch.tsv")
......@@ -53,7 +56,10 @@ class testAll(unittest.TestCase):
rm(testFolder+"balls-5c-pixelSearchPropagate.tsv")
rm(testFolder+"balls-5d-ddic.tsv")
rm(testFolder+"balls-5d-ddic.vtk")
rm(testFolder+"balls-6a-pixelSearch.tsv")
rm(testFolder+"balls-6a-ddic.tsv")
rm(testFolder+"balls-6b-ddic.tsv")
rm(testFolder+"balls-6b-ddic.vtk")
rm(testFolder+"balls-7a-pixelSearch.tsv")
rm(testFolder+"extreme-im1-extreme-im2-ddic.tsv")
rm(testFolder+"extreme-im1-extreme-im2-ddic.vtk")
rm(testFolder+"extreme-im1lab.tif")
......@@ -66,6 +72,8 @@ class testAll(unittest.TestCase):
rm(testFolder+"snow-def-cgs.tif")
rm(testFolder+"snow-def-onlyDisp.tif")
rm(testFolder+"snow-def.tif")
rm(testFolder+"snow-def-cgs-zoom.tif")
rm(testFolder+"snow-def-zoom.tif")
rm(testFolder+"snow-grid-2d3d-pixelSearch-CC.tif")
rm(testFolder+"snow-grid-2d3d-pixelSearch-returnStatus.tif")
rm(testFolder+"snow-grid-2d3d-pixelSearch.tsv")
......@@ -85,6 +93,8 @@ class testAll(unittest.TestCase):
rm(testFolder+"snow-grid-3b-pixelSearch.tsv")
rm(testFolder+"snow-grid-3c-pixelSearch.tsv")
rm(testFolder+"snow-grid-3e-pixelSearch.tsv")
rm(testFolder+"snow-grid-3f-passed-ns20.tsv")
rm(testFolder+"snow-grid-3g-pixelSearch.tsv")
rm(testFolder+"snow-grid-4a-pixelSearchPropagate.tsv")
rm(testFolder+"snow-grid-5a-ldic-deltaPhiNorm.tif")
rm(testFolder+"snow-grid-5a-ldic-error.tif")
......@@ -113,6 +123,9 @@ class testAll(unittest.TestCase):
rm(testFolder+"snow-ref.tif")
rm(testFolder+"snow-ref-watershed.tif")
rm(testFolder+"Step0-Step1-registration.tsv")
rm(testFolder+"Step0-Step1-ddic.tsv")
rm(testFolder+"Step0-Step1-ldic.tsv")
rm(testFolder+"Step0-Step1-registration.tsv")
rm(testFolder+"Step0.tif")
rm(testFolder+"Step1.tif")
rm(testFolder+"Step2.tif")
......@@ -949,7 +962,7 @@ class testAll(unittest.TestCase):
"-pre", "balls-5d"])
self.assertEqual(exitCode, 0)
DDICresult5d = spam.helpers.readCorrelationTSV(testFolder + "balls-5d-ddic.tsv")
DDICresult5d = spam.helpers.readCorrelationTSV(testFolder + "balls-5d-ddic.tsv", readConvergence=True, readError= True, readLabelDilate=True, readPixelSearchCC=True)
self.assertTrue(numpy.isclose(numpy.median(DDICresult5d['PhiField'][1:,0,-1]), translationStep2[0], atol=0.3))
self.assertTrue(numpy.isclose(numpy.median(DDICresult5d['PhiField'][1:,1,-1]), translationStep2[1], atol=0.3))
self.assertTrue(numpy.isclose(numpy.median(DDICresult5d['PhiField'][1:,2,-1]), translationStep2[2], atol=0.3))
......@@ -957,20 +970,84 @@ class testAll(unittest.TestCase):
### 5e ddic result passed to same label image with spam-passPhiField (ideally it would be differently labelled)
#...
#######################################################
### 6. Rerun ddic -- Step0 -> Step2 with prev result
### 6. Check -skp
#######################################################
# 6a repeat pixelSearch to give exactly same result
# Manually modify the RS of the TSV from 5d
DDICresult5d['returnStatus'][-3:] = -3
# Save the new TSV2
outMatrix = numpy.array([numpy.array(range(DDICresult5d['numberOfLabels'])),
DDICresult5d['fieldCoords'][:,0], DDICresult5d['fieldCoords'][:,1], DDICresult5d['fieldCoords'][:,2],
DDICresult5d['PhiField'][:, 0, 3], DDICresult5d['PhiField'][:, 1, 3], DDICresult5d['PhiField'][:, 2, 3],
DDICresult5d['PhiField'][:, 0, 0], DDICresult5d['PhiField'][:, 0, 1], DDICresult5d['PhiField'][:, 0, 2],
DDICresult5d['PhiField'][:, 1, 0], DDICresult5d['PhiField'][:, 1, 1], DDICresult5d['PhiField'][:, 1, 2],
DDICresult5d['PhiField'][:, 2, 0], DDICresult5d['PhiField'][:, 2, 1], DDICresult5d['PhiField'][:, 2, 2],
DDICresult5d['pixelSearchCC'],
DDICresult5d['error'], DDICresult5d['iterations'], DDICresult5d['returnStatus'], DDICresult5d['deltaPhiNorm'],
DDICresult5d['LabelDilate']]).T
numpy.savetxt(testFolder + "balls-6a-ddic.tsv",
outMatrix,
fmt='%.7f',
delimiter='\t',
newline='\n',
comments='',
header="Label\tZpos\tYpos\tXpos\t" +
"Zdisp\tYdisp\tXdisp\t" +
"Fzz\tFzy\tFzx\t" +
"Fyz\tFyy\tFyx\t" +
"Fxz\tFxy\tFxx\t" +
"PSCC\terror\titerations\treturnStatus\tdeltaPhiNorm\tLabelDilate")
# Run
# Just run a simple DVC with no outputs except TSV
exitCode = subprocess.call(["spam-ddic",
"-pf", testFolder + "balls-6a-ddic.tsv",
testFolder + "Step0.tif",
testFolder + "Lab0.tif",
testFolder + "Step2.tif",
"-od", testFolder + "",
"-skp",
"-pre", "balls-6b"])
self.assertEqual(exitCode, 0)
# Read both TSV files
DDICresult6a = spam.helpers.readCorrelationTSV(testFolder + "balls-6a-ddic.tsv", readConvergence=True, readError= True, readLabelDilate=True, readPixelSearchCC=True)
DDICresult6b = spam.helpers.readCorrelationTSV(testFolder + "balls-6b-ddic.tsv", readConvergence=True, readError= True, readLabelDilate=True, readPixelSearchCC=True)
# Check that both files are identical for the converged grains of DDICresult6a
self.assertTrue(DDICresult6a['fieldDims'] == DDICresult6b['fieldDims'])
self.assertTrue((DDICresult6a['fieldCoords'] == DDICresult6b['fieldCoords']).all())
self.assertTrue(DDICresult6a['numberOfLabels'] == DDICresult6b['numberOfLabels'])
convLabDDICresult6a = numpy.where(DDICresult6a['returnStatus'] == 2)[0]
# Loop through each label and verify each key
for label in convLabDDICresult6a:
# Check returnStatus
self.assertTrue(DDICresult6a['returnStatus'][label] == DDICresult6b['returnStatus'][label])
# Check deltaPhiNorm
self.assertTrue(DDICresult6a['deltaPhiNorm'][label] == DDICresult6b['deltaPhiNorm'][label])
# Check iterations
self.assertTrue(DDICresult6a['iterations'][label] == DDICresult6b['iterations'][label])
# Check error
self.assertTrue(DDICresult6a['error'][label] == DDICresult6b['error'][label])
# Check pixelSearchCC
self.assertTrue(DDICresult6a['pixelSearchCC'][label] == DDICresult6b['pixelSearchCC'][label])
# Chekc LabelDilate
self.assertTrue(DDICresult6a['LabelDilate'][label] == DDICresult6b['LabelDilate'][label])
# Check PhiField
self.assertTrue((DDICresult6a['PhiField'][label] == DDICresult6b['PhiField'][label]).all())
#######################################################
### 7. Rerun ddic -- Step0 -> Step2 with prev result
#######################################################
# 7a repeat pixelSearch to give exactly same result
exitCode = subprocess.call(["spam-pixelSearch", "-pf", testFolder + "balls-5a-pixelSearch.tsv",
"-sr",
"-3", "3", "-3", "3", "-3", "3",
testFolder + "Step0.tif", testFolder + "Step2.tif",
"-lab1", testFolder + "Lab0.tif",
"-od", testFolder + "",
"-pre", "balls-6a"
"-pre", "balls-7a"
])
PSresult6a = spam.helpers.readCorrelationTSV(testFolder + "balls-6a-pixelSearch.tsv")
PSresult6a = spam.helpers.readCorrelationTSV(testFolder + "balls-7a-pixelSearch.tsv")
self.assertTrue(numpy.sum(PSresult6a['returnStatus']) == len(radii))
# Al displacements should be exactly the same as before
#print(PSresult5a['PhiField'][1:,0:3,-1])
......@@ -979,11 +1056,7 @@ class testAll(unittest.TestCase):
#######################################################
### 7. Check -skp
#######################################################
# Manually modify the status of the last label
# TODO
#######################################################
......
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