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 bef23b7c authored by Edward Andò's avatar Edward Andò
Browse files

debug mode for ddic and 3-pane mode for imShowProgress in register

parent 67614fb3
Pipeline #47637 failed with stages
in 12 minutes and 48 seconds
......@@ -207,15 +207,15 @@ if mpiRank == boss or not mpi:
# Option 2 - load previous DVC
#################################
if args.PHIFILE is not None:
PhiFromFile = 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)
# We read an F file, also prevent pixel search
# args.PS = False
# If the read F-file has only one line -- it's a single point registration!
if PhiFromFile['fieldCoords'].shape[0] == 1:
regPhi = PhiFromFile['PhiField'][0]
regCentre = PhiFromFile['fieldCoords'][0]
if prevCorr['fieldCoords'].shape[0] == 1:
regPhi = prevCorr['PhiField'][0]
regCentre = prevCorr['fieldCoords'][0]
registrationSuccessful = True
print("\tI read a registration from a file in binning {} at centre {} at this scale".format(args.PHIFILE_BIN_RATIO, regCentre))
print("\tTranslations (px)")
......@@ -228,23 +228,19 @@ if mpiRank == boss or not mpi:
# Disactivate the application of registration
registrationSuccessful = False
# Replace F components of the current grid to zeros
# 2019-09-11 EA: I doubt this is such a wonderful idea...
for label in range(centresOfMass.shape[0]):
PhiField[label][:-1] = numpy.zeros((3, 4))
# Read the coordinates and values of the input F field
fieldCoords = PhiFromFile["fieldCoords"]
fieldCoords = prevCorr["fieldCoords"]
if args.PHIFILE_DIRECT:
print("spam-ddic: Assuming phi-file grain numbering is coherent with the current labelled image.")
PhiField = PhiFromFile["PhiField"]
print("spam-ddic: Assuming grain numbering in loaded PhiFile is coherent with the current labelled image.")
PhiField = prevCorr["PhiField"]
if args.SKIP_PARTICLES:
print("spam-ddic: Running for only the non-converged grains from the phi-file")
print("spam-ddic: Running for only the non-converged grains from the loaded PhiFile")
#Read the previous result for all grains -- new grains will be overwritten
returnStatus = PhiFromFile["returnStatus"]
iterations = PhiFromFile["iterations"]
deltaPhiNorm = PhiFromFile["deltaPhiNorm"]
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']
......@@ -256,7 +252,7 @@ if mpiRank == boss or not mpi:
fieldBinRatio=args.PHIFILE_BIN_RATIO,
correctBadPoints=True, nNeighbours=args.NEIGHBOURS)
else:
fieldValues = PhiFromFile["PhiField"]
fieldValues = prevCorr["PhiField"]
# 2020-06-08 EA: Assume LDIC guess.
# Try just to directly interpolate
......@@ -343,6 +339,7 @@ if mpiRank == boss or not mpi:
worker = numpy.where(numpy.logical_not(workersActive))[0][0]
# Get the next label off the queue
label, labelDilateCurrent = q.get()
if args.DEBUG: print("\nWorking on label:", label, "\n")
grainOK = False
getLabel = ltk.getLabel(lab1, label,
extractCube=False,
......@@ -362,13 +359,15 @@ if mpiRank == boss or not mpi:
# Maskette 1 is either a boolean array if args.MASK
# otherwise it contains ints i.e., labels
if args.MASK:
maskette1 = getLabel['subvol']
maskette1 = getLabel['subvol']
maskette1vol = numpy.sum(maskette1)
else:
maskette1 = None
maskette1 = None
maskette1vol = numpy.inf # must pass "if" below
slicette1 = getLabel['slice']
imagette1 = im1[slicette1].copy()
if numpy.sum(maskette1) > args.VOLUME_THRESHOLD:
if maskette1vol > args.VOLUME_THRESHOLD:
if args.PS == 'on' or (not registrationSuccessful and args.PS == 'auto'):
labelDisplacementInt = numpy.round(PhiField[label][0:3, -1])
#print(labelDisplacementInt)
......@@ -397,7 +396,12 @@ if mpiRank == boss or not mpi:
searchCentre = (numpy.array(imagette2.shape, dtype='<f4') - 1) / 2.0 + labelDisplacementInt - middleOfSearchRange
#searchCentre = (numpy.array(imagette2.shape, dtype='<f4') - 1) / 2.0
pixelSearchReturns = spam.DIC.correlate.pixelSearch(imagette1,
# 2020-07-05 try applying F to im1 this is expected to help with pixel searching
PhiNoDisp = PhiField[label].copy()
PhiNoDisp[0:3,-1] = 0.0
imagette1def = spam.DIC.applyPhi(imagette1, PhiNoDisp)
pixelSearchReturns = spam.DIC.correlate.pixelSearch(imagette1def,
imagette2,
searchCentre = searchCentre,
searchRange = searchRangeForThisLabel)
......@@ -411,13 +415,15 @@ if mpiRank == boss or not mpi:
if args.GRID_POINT:
labelDisplacementInt = numpy.round(PhiField[label][0:3, -1])
slicette2 = (slice(max(int(boundingBoxes[label][0] - args.GRID_POINT_MARGIN - max(labelDilateCurrent, 0) + labelDisplacementInt[0]), 0),
slicette2 = (slice(max(int(boundingBoxes[label][0] - args.GRID_POINT_MARGIN - max(labelDilateCurrent, 0) + labelDisplacementInt[0] ), 0 ),
min(int(boundingBoxes[label][1] + args.GRID_POINT_MARGIN + max(labelDilateCurrent, 0) + labelDisplacementInt[0] + 1), im1.shape[0])),
slice(max(int(boundingBoxes[label][2] - args.GRID_POINT_MARGIN - max(labelDilateCurrent, 0) + labelDisplacementInt[1]), 0),
slice(max(int(boundingBoxes[label][2] - args.GRID_POINT_MARGIN - max(labelDilateCurrent, 0) + labelDisplacementInt[1] ), 0 ),
min(int(boundingBoxes[label][3] + args.GRID_POINT_MARGIN + max(labelDilateCurrent, 0) + labelDisplacementInt[1] + 1), im1.shape[1])),
slice(max(int(boundingBoxes[label][4] - args.GRID_POINT_MARGIN - max(labelDilateCurrent, 0) + labelDisplacementInt[2]), 0),
slice(max(int(boundingBoxes[label][4] - args.GRID_POINT_MARGIN - max(labelDilateCurrent, 0) + labelDisplacementInt[2] ), 0 ),
min(int(boundingBoxes[label][5] + args.GRID_POINT_MARGIN + max(labelDilateCurrent, 0) + labelDisplacementInt[2] + 1), im1.shape[2])))
#print(slicette1)
#print(slicette2)
imagette2imagette1sizeDiff = numpy.array(im2[slicette2].shape) - numpy.array(imagette1.shape)
......@@ -438,8 +444,8 @@ if mpiRank == boss or not mpi:
maxIterations=args.GRID_POINT_MAX_ITERATIONS,
deltaPhiMin=args.GRID_POINT_MIN_PHI_CHANGE,
interpolationOrder=args.GRID_POINT_INTERPOLATION_ORDER,
verbose=False,
imShowProgress=None)
verbose=args.DEBUG,
imShowProgress='Z' if args.DEBUG else None)
writeReturns = True
elif mpi:
......
......@@ -234,10 +234,25 @@ def register(im1, im2, im1mask=None, PhiInit=None, PhiInitBinRatio=1.0, margin=N
vmax = im1crop.max() / 2
if not imShowProgressNewFig:
if imShowProgress == "Z" or imShowProgress == "z":
plt.subplot(1,3,1)
plt.axis([im1crop.shape[2], 0, im1crop.shape[1], 0])
plt.subplot(1,3,2)
plt.axis([im1crop.shape[2], 0, im1crop.shape[1], 0])
plt.subplot(1,3,3)
plt.axis([im1crop.shape[2], 0, im1crop.shape[1], 0])
if imShowProgress == "Y" or imShowProgress == "y":
plt.subplot(1,3,1)
plt.axis([im1crop.shape[2], 0, im1crop.shape[0], 0])
plt.subplot(1,3,2)
plt.axis([im1crop.shape[2], 0, im1crop.shape[0], 0])
plt.subplot(1,3,3)
plt.axis([im1crop.shape[2], 0, im1crop.shape[0], 0])
if imShowProgress == "X" or imShowProgress == "x":
plt.subplot(1,3,1)
plt.axis([im1crop.shape[1], 0, im1crop.shape[0], 0])
plt.subplot(1,3,2)
plt.axis([im1crop.shape[1], 0, im1crop.shape[0], 0])
plt.subplot(1,3,3)
plt.axis([im1crop.shape[1], 0, im1crop.shape[0], 0])
plt.ion()
......@@ -432,10 +447,10 @@ def register(im1, im2, im1mask=None, PhiInit=None, PhiInitBinRatio=1.0, margin=N
# Second divergence criterion on displacement (Issue #62)
# If any displcement is bigger than 5* the margin...
if (numpy.abs(spam.deformation.decomposePhi(Phi.copy())['t']) > 5 * realMargin).any():
if verbose: print("\t -> diverging on displacement condition")
returnStatus = -3
break
#if (numpy.abs(spam.deformation.decomposePhi(Phi.copy())['t']) > 5 * realMargin).any():
#if verbose: print("\t -> diverging on displacement condition")
#returnStatus = -3
#break
# 2018-10-02 - EA: Add divergence condition on U
trans = spam.deformation.decomposePhi(Phi.copy())
......@@ -453,14 +468,29 @@ def register(im1, im2, im1mask=None, PhiInit=None, PhiInitBinRatio=1.0, margin=N
if imShowProgress == "Z" or imShowProgress == "z":
if imShowProgressNewFig: plt.figure()
else: plt.clf()
plt.subplot(1,3,1)
plt.imshow(im1crop[im1crop.shape[0] // 2, :, :], cmap='Greys_r', vmin=0, vmax=vmax)
plt.subplot(1,3,2)
plt.imshow(im2def[crop2][im1crop.shape[0] // 2, :, :], cmap='Greys_r', vmin=0, vmax=vmax)
plt.subplot(1,3,3)
plt.imshow(numpy.subtract(im1crop, im2def[crop2])[im1crop.shape[0] // 2, :, :], cmap='coolwarm', vmin=vmin, vmax=vmax)
if imShowProgress == "Y" or imShowProgress == "y":
if imShowProgressNewFig: plt.figure()
else: plt.clf()
plt.subplot(1,3,1)
plt.imshow(im1crop[:, im1crop.shape[1] // 2, :], cmap='Greys_r', vmin=0, vmax=vmax)
plt.subplot(1,3,2)
plt.imshow(im2def[crop2][:, im1crop.shape[1] // 2, :], cmap='Greys_r', vmin=0, vmax=vmax)
plt.subplot(1,3,3)
plt.imshow(numpy.subtract(im1crop, im2def[crop2])[:, im1crop.shape[1] // 2, :], cmap='coolwarm', vmin=vmin, vmax=vmax)
if imShowProgress == "X" or imShowProgress == "x":
if imShowProgressNewFig: plt.figure()
else: plt.clf()
plt.subplot(1,3,1)
plt.imshow(im1crop[:, :, im1crop.shape[2] // 2], cmap='Greys_r', vmin=0, vmax=vmax)
plt.subplot(1,3,2)
plt.imshow(im2def[crop2][:, :, im1crop.shape[2] // 2], cmap='Greys_r', vmin=0, vmax=vmax)
plt.subplot(1,3,3)
plt.imshow(numpy.subtract(im1crop, im2def[crop2])[:, :, im1crop.shape[2] // 2], cmap='coolwarm', vmin=vmin, vmax=vmax)
plt.title('Iteration Number = {}'.format(iterations))
plt.pause(0.5)
......@@ -468,13 +498,12 @@ def register(im1, im2, im1mask=None, PhiInit=None, PhiInitBinRatio=1.0, margin=N
iterations += 1
if verbose:
r = spam.deformation.decomposePhi(Phi.copy())["r"]
U = spam.deformation.decomposePhi(Phi.copy())["U"]
widgets[3] = progressbar.FormatLabel(" dPhiNorm={:0>7.5f} error={:0>4.2f} t=[{:0>5.3f} {:0>5.3f} {:0>5.3f}] r=[{:0>5.3f} {:0>5.3f} {:0>5.3f}] Udiag=[{:0>5.3f} {:0>5.3f} {:0>5.3f}]".format(
decomposedPhi = spam.deformation.decomposePhi(Phi.copy())
widgets[3] = progressbar.FormatLabel(" dPhiNorm={:0>7.5f} error={:0>4.2f} t=[{:0>5.3f} {:0>5.3f} {:0>5.3f}] r=[{:0>5.3f} {:0>5.3f} {:0>5.3f}] z=[{:0>5.3f} {:0>5.3f} {:0>5.3f}]".format(
deltaPhiNorm, error,
Phi[0, -1], Phi[1, -1], Phi[2, -1],
r[0], r[1], r[2],
U[0, 0], U[1, 1], U[2, 2]))
decomposedPhi['t'][0], decomposedPhi['t'][1], decomposedPhi['t'][2],
decomposedPhi['r'][0], decomposedPhi['r'][1], decomposedPhi['r'][2],
decomposedPhi['z'][0], decomposedPhi['z'][1], decomposedPhi['z'][2]))
pbar.update(iterations)
# Positive return status is a healthy end of while loop:
......
......@@ -610,6 +610,13 @@ def ddicParser(parser):
dest='SKIP_PARTICLES',
help="Read the return status of the Phi file run ddic only for the non-converged grains. Default = False")
parser.add_argument('-d',
'--debug',
action="store_true",
default=0,
dest='DEBUG',
help="Extremely verbose mode with graphs and text output. Only use for a few particles. Do not use with mpirun")
args = parser.parse_args()
# If we have no out dir specified, deliver on our default promise -- this can't be done inline before since parser.parse_args() has not been run at that stage.
......
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