-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrossection_scan_ptvpy.py
executable file
·135 lines (84 loc) · 3.11 KB
/
crossection_scan_ptvpy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
"""
Version: 1.5
Summary: compute the segmentaiton and label of cross section image sequence
Author: suxing liu
Author-email: [email protected]
USAGE:
python3 crossection_scan_ptvpy.py -p ~/ply_data/test/
argument:
("-p", "--path", required = True, help = "path to image file")
("-ft", "--filetype", required = False, default = 'png', help = "Image filetype")
"""
import subprocess, os
import sys
import argparse
import glob
import fnmatch
import os, os.path
'''
def execute_script(cmd_line):
"""execute script inside program"""
try:
print(cmd_line)
#os.system(cmd_line)
process = subprocess.Popen(cmd_line, shell=True, stdout=subprocess.PIPE)
stdout = process.communicate()[0]
print ('STDOUT:{}'.format(stdout))
process.wait()
#print process.returncode
except OSError:
print("Failed ...!\n")
'''
def execute_script(command):
try:
subprocess.run(command, shell = True)
except OSError:
print("Failed ...!\n")
def remove_file(filePath):
#print(filePath)
if os.path.exists(filePath):
os.remove(filePath)
print("File {} was updated\n".format(filePath))
else:
print("Create new {}\n".format(filePath))
def sequence_scan_pipeline(file_path, result_file):
#delete ptvpy.toml if exist
print("Current working directory path {}\n".format(os.getcwd()))
filePath_ptvpy = os.getcwd() + "/ptvpy.toml"
remove_file(filePath_ptvpy)
filePath_ptvpy = os.getcwd() + "/ptvpy.h5"
remove_file(filePath_ptvpy)
#create a new profile file
print("Level set scan computating...\n")
profile_file = "ptvpy profile create --data-files '" + file_path + "*" + ext + "'"
print(profile_file)
execute_script(profile_file)
#compute and tracking traces from image slices
print("Tracking individual root particles...\n")
track_trace = "ptvpy process"
execute_script(track_trace)
#print tracking results
#view_result = "ptvpy view summary --all"
#execute_script(view_result)
#delete result file if exist
remove_file(result_file)
export_result = "ptvpy export --type csv " + "'" + result_file + "'"
execute_script(export_result)
if __name__ == '__main__':
# construct and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-p", "--path", required = True, help = "path to image file")
ap.add_argument("-ft", "--filetype", required = False, default = 'png', help = "Image filetype")
args = vars(ap.parse_args())
# setting path to cross section image files
file_path = args["path"]
ext = args['filetype']
#accquire image file list
filetype = '*.' + ext
image_file_path = file_path + filetype
#accquire image file list
imgList = sorted(glob.glob(image_file_path))
#print(imgList)
#Create result file path
result_file = (file_path + 'trace_result.csv')
sequence_scan_pipeline(file_path, result_file)