Commit b8f38577 authored by Olga Stamati's avatar Olga Stamati
Browse files

multiprocessing in tomopack with divergent beam, also modified the...

multiprocessing in tomopack with divergent beam, also modified the environmental variables of numpy in __init__
parent 9578d3d8
Pipeline #80329 passed with stage
in 1 minute and 59 seconds
......@@ -7,10 +7,10 @@ If a new function is added it should be called at the bottom of the function
"""
import radioSphere
import numpy
import unittest
import matplotlib.pyplot as plt
import radioSphere
class TestDetection(unittest.TestCase):
def tearDown(self):
......
import os
os.environ['OPENBLAS_NUM_THREADS'] = '1'
os.environ['OMP_NUM_THREADS'] = '1'
__all__ = ["optimisePositions", "projectSphere", "DEM", "detectSpheres", "calibrateAttenuation"]
#from .blender_viewer import *
......
'''
Tool for sphere detection in parallel and divergent beam
Library of RadioSphere spheres detection functions.
'''
import radioSphere.projectSphere
import os
import numpy
import radioSphere.projectSphere
import scipy.ndimage
import scipy.signal
from scipy.spatial import distance
......@@ -12,6 +12,12 @@ from scipy.spatial import distance
import matplotlib.pyplot as plt
import tifffile
import multiprocessing
import progressbar
# Global number of processes
nProcessesDefault = multiprocessing.cpu_count()
# _kernel = numpy.ones((1,3,3))/9. # square kernel
#_kernel = numpy.array([[[1,2,1],[2,4,2],[1,2,1]]])/16. # gaussian kernel
_kernel = numpy.array([[1,2,1], [2,4,2], [1,2,1]])/16. # gaussian kernel 2D
......@@ -440,6 +446,7 @@ def tomopackDivergentScanTo3DPositions(radioMM, radiusMM,
sourceDetectorDistMM=100, pixelSizeMM=0.1, l=0.2, kTrustRatio=0.7, useCache=True,
blur=0.0,
cacheFile='fXseries.tif',
nProcesses=nProcessesDefault,
verbose=False):
"""
This function takes in a single divergent projection, and will run tomopack
......@@ -501,9 +508,13 @@ def tomopackDivergentScanTo3DPositions(radioMM, radiusMM,
sourceDetectorDistMM=sourceDetectorDistMM,
blur=blur)
for posN, CORxPos in enumerate(CORxPositions):
### "Structuring Element"
print("\t{}/{} CORxPos = {:0.2f}mm".format(posN+1, len(CORxPositions), CORxPos), end='\r')
pbar = progressbar.ProgressBar(maxval=len(CORxPositions)).start()
finishedPos = 0
# Loop over CORx
global computeOneCOR
def computeOneCOR(pos):
CORxPos = CORxPositions[pos]
psiMM = radioSphere.projectSphere.projectSphereMM(numpy.array([[CORxPos, 0., 0.]]),
numpy.array([radiusMM]),
detectorResolution=radioMM.shape,
......@@ -511,9 +522,37 @@ def tomopackDivergentScanTo3DPositions(radioMM, radiusMM,
sourceDetectorDistMM=sourceDetectorDistMM,
blur=blur)
fXseries[posN] = radioSphere.detectSpheres.tomopack(radioMM, psiMM, maxIterations=maxIterations, l=l, kTrustRatio=kTrustRatio)
psiXseries[posN] = radioSphere.detectSpheres.tomopack(psiRefMM, psiMM, maxIterations=maxIterations, l=l, kTrustRatio=kTrustRatio)
psiMMseries[posN] = psiMM
fX = radioSphere.detectSpheres.tomopack(radioMM, psiMM, maxIterations=maxIterations, l=l, kTrustRatio=kTrustRatio)
psiX = radioSphere.detectSpheres.tomopack(psiRefMM, psiMM, maxIterations=maxIterations, l=l, kTrustRatio=kTrustRatio)
return pos, fX, psiX, psiMM
# Run multiprocessing
with multiprocessing.Pool(processes=nProcesses) as pool:
for returns in pool.imap_unordered(computeOneCOR, range(len(CORxPositions))):
fXseries[returns[0]] = returns[1]
psiXseries[returns[0]] = returns[2]
psiMMseries[returns[0]] = returns[3]
finishedPos += 1
pbar.update(finishedPos)
pool.close()
pool.join()
pbar.finish()
#for posN, CORxPos in enumerate(CORxPositions):
#### "Structuring Element"
#print("\t{}/{} CORxPos = {:0.2f}mm".format(posN+1, len(CORxPositions), CORxPos), end='\r')
#psiMM = radioSphere.projectSphere.projectSphereMM(numpy.array([[CORxPos, 0., 0.]]),
#numpy.array([radiusMM]),
#detectorResolution=radioMM.shape,
#pixelSizeMM=pixelSizeMM,
#sourceDetectorDistMM=sourceDetectorDistMM,
#blur=blur)
#fXseries[posN] = radioSphere.detectSpheres.tomopack(radioMM, psiMM, maxIterations=maxIterations, l=l, kTrustRatio=kTrustRatio)
#psiXseries[posN] = radioSphere.detectSpheres.tomopack(psiRefMM, psiMM, maxIterations=maxIterations, l=l, kTrustRatio=kTrustRatio)
#psiMMseries[posN] = psiMM
if useCache and not loadedCache:
print("Saving indicator functions for next time... ", end="")
......
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