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

readCorrelationTSV() now reads error and LabelDilate (with test)

parent 9f964fbe
Pipeline #52806 failed with stages
in 13 minutes
......@@ -202,7 +202,7 @@ if mpiRank == boss or not mpi:
# Option 2 - load previous DVC
#################################
if args.PHIFILE is not None:
prevCorr = spam.helpers.tsvio.readCorrelationTSV(args.PHIFILE.name, fieldBinRatio=args.PHIFILE_BIN_RATIO)
prevCorr = spam.helpers.tsvio.readCorrelationTSV(args.PHIFILE.name, fieldBinRatio=args.PHIFILE_BIN_RATIO, readError= True, readLabelDilate=True, readPSCC=True)
# We read an F file, also prevent pixel search
# args.PS = False
......@@ -236,10 +236,9 @@ if mpiRank == boss or not mpi:
returnStatus = prevCorr["returnStatus"]
iterations = prevCorr["iterations"]
deltaPhiNorm = prevCorr["deltaPhiNorm"]
labelDilateList = numpy.genfromtxt(args.PHIFILE.name, delimiter="\t", names=True)[:]['LabelDilate']
error = numpy.genfromtxt(args.PHIFILE.name, delimiter="\t", names=True)[:]['error']
PSCC = numpy.genfromtxt(args.PHIFILE.name, delimiter="\t", names=True)[:]['PSCC']
labelDilateList = prevCorr["LabelDilate"]
error = prevCorr["error"]
PSCC = pevCorr["PSCC"]
else:
# Check if the correction of the input field is asked
if args.CF:
......
......@@ -180,7 +180,7 @@ def writeStrainTSV(fileName, points, decomposedFfield, firstColumn="StrainPointN
header=header)
def readCorrelationTSV(fileName, fieldBinRatio=1.0, readOnlyDisplacements=False, readConvergence=True, readPSCC=False):
def readCorrelationTSV(fileName, fieldBinRatio=1.0, readOnlyDisplacements=False, readConvergence=True, readPSCC=False, readError=False, readLabelDilate=False):
"""
This function reads a TSV file containing a field of deformation functions **Phi** at one or a number of points.
This is typically the output of the spam-ldic and spam-ddic scripts,
......@@ -202,12 +202,20 @@ def readCorrelationTSV(fileName, fieldBinRatio=1.0, readOnlyDisplacements=False,
Default = False
readConvergence : bool, optional
Read "returnStatus", "deltaPhiNorm", "iterations" from file
Read "returnStatus", "deltaPhiNorm", "iterations", from file
Default = True
readPSCC : bool, optional
Read "PSCC" from file
Default = False
readError : bool, optional
Read '"error"from file
Default = False
readLabelDilate : bool, optional
Read "LabelDilate" from file
Default = False
Returns
-------
......@@ -227,6 +235,10 @@ def readCorrelationTSV(fileName, fieldBinRatio=1.0, readOnlyDisplacements=False,
iterations: nx1 array of n points iterations from the correlation
PSCC: nx1 array of n points PSCC from the correlation
error: nx1 array of n points error from the correlation
labelDilate: nx1 array of n points labelDilate from the correlation
"""
if not os.path.isfile(fileName):
......@@ -302,6 +314,12 @@ def readCorrelationTSV(fileName, fieldBinRatio=1.0, readOnlyDisplacements=False,
RS = f['SubPixReturnStat']
deltaPhiNorm = f['SubPixDeltaPhiNorm']
iterations = f['SubPixIterations']
if readError:
try:
error = f['error']
except ValueError:
pass
PSCC = 0
......@@ -360,6 +378,21 @@ def readCorrelationTSV(fileName, fieldBinRatio=1.0, readOnlyDisplacements=False,
PSCC = f[:]['PSCC']
except ValueError:
pass
# Return error
if readError:
error = numpy.zeros(nPoints)
try:
error = f[:]['error']
except ValueError:
pass
# Return labelDilate
if readLabelDilate:
labelDilate = numpy.zeros(nPoints)
try:
labelDilate = f[:]['LabelDilate']
except ValueError:
pass
# Sort out the components of Phi
PhiField = numpy.zeros((nPoints, 4, 4))
......@@ -409,8 +442,12 @@ def readCorrelationTSV(fileName, fieldBinRatio=1.0, readOnlyDisplacements=False,
output.update({"returnStatus": RS,
"deltaPhiNorm": deltaPhiNorm,
"iterations": iterations})
if readError:
output.update({"error": error})
if readPSCC:
output.update({"PSCC": PSCC})
if readLabelDilate:
output.update({"LabelDilate": labelDilate})
if readOnlyDisplacements:
output.update({"displacements": PhiField[:, 0:3, -1]})
......
......@@ -31,11 +31,14 @@ for n in range(PhiField.shape[0]):
RS = numpy.full((fieldCoords.shape[0]), 2)
DF = numpy.full((fieldCoords.shape[0]), 0.0001)
IT = numpy.full((fieldCoords.shape[0]), 1)
error = numpy.full((fieldCoords.shape[0]), 0.1)
labelDilate = numpy.full((fieldCoords.shape[0]), 2)
PSCC = numpy.full((fieldCoords.shape[0]), 0.2)
# save the tsv files
TSVheader = "NodeNumber\tZpos\tYpos\tXpos\tFzz\tFzy\tFzx\tZdisp\tFyz\tFyy\tFyx\tYdisp\tFxz\tFxy\tFxx\tXdisp\treturnStatus\tdeltaPhiNorm\titerations"
TSVheaderOld = "NodeNumber\tZpos\tYpos\tXpos\tF11\tF12\tF13\tF14\tF21\tF22\tF23\tF24\tF31\tF32\tF33\tF34\tSubPixReturnStat\tSubPixDeltaPhiNorm\tSubPixIterations"
TSVheaderDiscrete = "Label\tZpos\tYpos\tXpos\tF11\tF12\tF13\tZdisp\tF21\tF22\tF23\tYdisp\tF31\tF32\tF33\tXdisp\treturnStatus\tdeltaPhiNorm\titerations"
TSVheaderDiscrete = "Label\tZpos\tYpos\tXpos\tF11\tF12\tF13\tZdisp\tF21\tF22\tF23\tYdisp\tF31\tF32\tF33\tXdisp\treturnStatus\tdeltaPhiNorm\titerations\terror\tLabelDilate\tPSCC"
outMatrix = numpy.array([numpy.array(range(PhiField.shape[0])),
fieldCoords[:, 0], fieldCoords[:, 1], fieldCoords[:, 2],
......@@ -44,10 +47,17 @@ outMatrix = numpy.array([numpy.array(range(PhiField.shape[0])),
PhiField[:, 2, 0], PhiField[:, 2, 1], PhiField[:, 2, 2], PhiField[:, 2, 3],
RS, DF, IT]).T
outMatrixDiscrete = numpy.array([numpy.array(range(PhiField.shape[0])),
fieldCoords[:, 0], fieldCoords[:, 1], fieldCoords[:, 2],
PhiField[:, 0, 0], PhiField[:, 0, 1], PhiField[:, 0, 2], PhiField[:, 0, 3],
PhiField[:, 1, 0], PhiField[:, 1, 1], PhiField[:, 1, 2], PhiField[:, 1, 3],
PhiField[:, 2, 0], PhiField[:, 2, 1], PhiField[:, 2, 2], PhiField[:, 2, 3],
RS, DF, IT, error, labelDilate, PSCC]).T
numpy.savetxt("spamPhiField.tsv", outMatrix, fmt='%.7f', delimiter='\t', newline='\n', comments='', header=TSVheader)
numpy.savetxt("spamPhiFieldOld.tsv", outMatrix, fmt='%.7f', delimiter='\t', newline='\n', comments='', header=TSVheaderOld)
numpy.savetxt("spamPhiFieldOldReg.tsv", numpy.array([outMatrix[0, :]]), fmt='%.7f', delimiter='\t', newline='\n', comments='', header=TSVheaderOld)
numpy.savetxt("spamPhiFieldDiscrete.tsv", outMatrix, fmt='%.7f', delimiter='\t', newline='\n', comments='', header=TSVheaderDiscrete)
numpy.savetxt("spamPhiFieldDiscrete.tsv", outMatrixDiscrete, fmt='%.7f', delimiter='\t', newline='\n', comments='', header=TSVheaderDiscrete)
class testAll(unittest.TestCase):
......@@ -133,10 +143,13 @@ class testAll(unittest.TestCase):
self.assertAlmostEqual(PhiField[0][0:3, -1].sum(), f2c["PhiField"][0][0:3, -1].sum(), places=4)
# case 3: read discrete tsv file
f3 = tsvio.readCorrelationTSV(fileName="spamPhiFieldDiscrete.tsv")
f3 = tsvio.readCorrelationTSV(fileName="spamPhiFieldDiscrete.tsv", readConvergence= True, readError= True, readLabelDilate=True, readPSCC=True)
self.assertEqual(20, f3["numberOfLabels"])
self.assertEqual([0, 0, 0], f3["fieldDims"])
self.assertAlmostEqual(PhiField.sum(), f3["PhiField"].sum(), places=4)
self.assertAlmostEqual(error.sum(), f3["error"].sum(), places=4)
self.assertAlmostEqual(PSCC.sum(), f3["PSCC"].sum(), places=4)
self.assertAlmostEqual(labelDilate.sum(), f3["LabelDilate"].sum(), places=4)
def test_TSVtoTIFF(self):
import tifffile
......
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