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

[skip-ci] applyPhiField() parallel, only pixelMask remains to be implemented

parent dac7532e
Pipeline #68864 skipped
...@@ -286,38 +286,42 @@ def applyPhiField(im, fieldCoordsRef, PhiField, displacementMode="interpolate", ...@@ -286,38 +286,42 @@ def applyPhiField(im, fieldCoordsRef, PhiField, displacementMode="interpolate",
pixCoordsRef = numpy.zeros_like(pixCoordsDef, dtype='f4') pixCoordsRef = numpy.zeros_like(pixCoordsDef, dtype='f4')
# for each group of pixels (divide mask==True into nProcesses chunks): global computeDisplacementForSeriesOfPixels
for pixNumber, pixCoordDef in enumerate(pixCoordsDef): def computeDisplacementForSeriesOfPixels(seriesNumber):
# get nNeighbours and compute distance weights
distances, indices = treeCoordDef.query(pixCoordDef, k=nNeighbours) pixelNumbers = splitPixNumbers[seriesNumber]
weights = (1/(distances+tol))
pixCoordsRefSeries = numpy.zeros((len(pixelNumbers), 3), dtype='f4')
displacement = numpy.zeros(3, dtype='float')
for localPixelNumber, globalPixelNumber in enumerate(pixelNumbers):
#print() pixCoordDef = pixCoordsDef[globalPixelNumber]
# get nNeighbours and compute distance weights
# for each neighbour distances, indices = treeCoordDef.query(pixCoordDef, k=nNeighbours)
for neighbour, index in enumerate(indices): weights = (1/(distances+tol))
# apply PhiInv to current point with PhiCentre = fieldCoordsREF <- this is important
# -> this gives a displacement for each neighbour displacement = numpy.zeros(3, dtype='float')
PhiInv = PhiFieldInvMasked[index]
#print("PhiInv", PhiInv) # for each neighbour
translationTmp = PhiInv[0:3, -1].copy() for neighbour, index in enumerate(indices):
dist = pixCoordDef - fieldCoordsRefMasked[index] # apply PhiInv to current point with PhiCentre = fieldCoordsREF <- this is important
#print(f"dist = {dist}") # -> this gives a displacement for each neighbour
translationTmp -= dist - numpy.dot(PhiInv[0:3, 0:3], dist) PhiInv = PhiFieldInvMasked[index]
#print(f"translationTmp ({neighbour}): {translationTmp} (weight = {weights[neighbour]})") #print("PhiInv", PhiInv)
displacement += translationTmp*weights[neighbour] translationTmp = PhiInv[0:3, -1].copy()
dist = pixCoordDef - fieldCoordsRefMasked[index]
# compute resulting displacement as weights * displacements #print(f"dist = {dist}")
# compute pixel coordinates in reference config translationTmp -= dist - numpy.dot(PhiInv[0:3, 0:3], dist)
#print("pixCoordDef", pixCoordDef) #print(f"translationTmp ({neighbour}): {translationTmp} (weight = {weights[neighbour]})")
#print("displacement", displacement) displacement += translationTmp*weights[neighbour]
pixCoordsRef[pixNumber] = pixCoordDef + displacement / weights.sum()
#pixCoordsRef[pixNumber] = pixCoordDef + numpy.sum(displacements*weights[:, numpy.newaxis], axis=0) # compute resulting displacement as weights * displacements
# compute pixel coordinates in reference config
#global inter #print("pixCoordDef", pixCoordDef)
#def dispOnePoint(defCoord): #print("displacement", displacement)
pixCoordsRefSeries[localPixelNumber] = pixCoordDef + displacement / weights.sum()
return pixelNumbers, pixCoordsRefSeries
#pixCoordsRef[pixNumber] = pixCoordDef + numpy.sum(displacements*weights[:, numpy.newaxis], axis=0)
## Check if we've hit the same point ## Check if we've hit the same point
#if numpy.any(distance == 0): #if numpy.any(distance == 0):
...@@ -368,22 +372,25 @@ def applyPhiField(im, fieldCoordsRef, PhiField, displacementMode="interpolate", ...@@ -368,22 +372,25 @@ def applyPhiField(im, fieldCoordsRef, PhiField, displacementMode="interpolate",
#pass #pass
#qResults.put([point, coordNew]) #qResults.put([point, coordNew])
## Iterate through flat field of Fs splitPixNumbers = numpy.array_split(numpy.arange(pixCoordsDef.shape[0]), nProcesses)
#if verbose:
#pbar = progressbar.ProgressBar(maxval=pointsToEstimate.shape[0]).start()
#finishedPoints = 0
## Run multiprocessing filling in FfieldFlatGood, which will then update FfieldFlat
#with multiprocessing.Pool(processes=nProcesses) as pool:
#for returns in pool.imap_unordered(dispOnePoint, range(pointsToEstimate.shape[0])):
#if verbose:
#finishedPoints += 1
#pbar.update(finishedPoints)
#estimatedDisplacements[returns[0]] = returns[1]
#pool.close()
#pool.join()
#if verbose: pbar.finish() # Iterate through flat field of Fs
if verbose:
pbar = progressbar.ProgressBar(maxval=len(splitPixNumbers)).start()
finishedPoints = 0
# Run multiprocessing filling in FfieldFlatGood, which will then update FfieldFlat
with multiprocessing.Pool(processes=nProcesses) as pool:
for returns in pool.imap_unordered(computeDisplacementForSeriesOfPixels, range(nProcesses)):
if verbose:
finishedPoints += 1
pbar.update(finishedPoints)
pixCoordsRef[returns[0]] = returns[1]
pool.close()
pool.join()
if verbose: pbar.finish()
## overwrite bad points displacements ## overwrite bad points displacements
#return estimatedDisplacements #return estimatedDisplacements
......
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