tweaking some arg names
@@ -6,7 +6,7 @@ import psutil
import time
-def maximal_ball(im, filename, path, voxel_size=1e-6):
+def maximal_ball(im, prefix, path_to_exe, voxel_size=1e-6):
r"""
Implementing a maximal ball algorithm on an image
@@ -14,10 +14,10 @@ def maximal_ball(im, filename, path, voxel_size=1e-6):
----------
im : ndarray
The image of the porous material.
- filename : string
- The name to save the files.
- path : string
- path to the maximal ball .exe file (pnextract.exe)
+ prefix : string
+ The prefix to append to the filenames (i.e. 'prefix_node1.dat')
+ path_to_exe : string
+ Path to the maximal ball .exe file (pnextract.exe). See Notes
voxel_size : scalar
The size of a voxel side in preferred units. The default is 1e-6, so the
user can apply the scaling to the returned results after the fact.
@@ -25,10 +25,13 @@ def maximal_ball(im, filename, path, voxel_size=1e-6):
Notes
-----
outputs four DAT files:
- filename_link1, filename_link2, filename_node1, filename_node2
+ prefix_link1, prefix_link2, prefix_node1, prefix_node2
+
+ This function only runs on Windows since the Windows compatible binary is
+ provided by the Imperial College team.
"""
- file = os.path.splitext(filename)[0]
+ file = os.path.splitext(prefix)[0]
imageio.volsave(file + ".tif", np.array(im.astype("uint8")))
f = open(file + ".mhd", "w")
f.write("ObjectType = Image\n\
@@ -43,19 +46,20 @@ def maximal_ball(im, filename, path, voxel_size=1e-6):
f.close()
subprocess.Popen([path, file + ".mhd"])
i = 0
- while checkIfProcessRunning('pnextract'):
+ while is_running('pnextract'):
print('maximal ball algorithm is running: ' + str(i) + 's')
time.sleep(10)
i = i+10
-def checkIfProcessRunning(processName):
+
+def is_running(process_name):
r"""
Check if there is any running process that contains the given name.
"""
for proc in psutil.process_iter():
try:
# Check if process name contains the given name string.
- if processName.lower() in proc.name().lower():
+ if process_name.lower() in proc.name().lower():
return True
except (psutil.NoSuchProcess, psutil.AccessDenied):
pass
