-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmake_run.py
executable file
·354 lines (282 loc) · 11.4 KB
/
make_run.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/opt/homebrew/bin/Python3.10
# change the directory above #
######################################
import subprocess
import fileinput
import sys
import time
import psutil
import cv2
import shutil
import os
import re
from os.path import exists
import customtkinter
import tkinter as tk
from tkinter import ttk
from tkinter import messagebox
from tkinter import filedialog
from pathlib import Path
sys.getfilesystemencoding()
#============================================= functions ===========================================
def cell_video():
path = 'Folder_Output/Cell_desnity.avi'
file_exists = exists(path)
if not file_exists:
Files = Path('/Applications')
for file in Files.iterdir():
if re.match("ParaView", file.name):
Para_view = file
Code_name = 'cell_density_video_'+str(sys.argv[1])+'.py'
export_results = subprocess.run([str(Para_view)+'/Contents/bin/pvpython', Code_name])
cap=cv2.VideoCapture(path)
if not cap.isOpened():
print("Error opening Video File.")
while(True):
ret, frame=cap.read()
if not ret:
break
cv2.imshow("Cell density", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.waitKey(5000)
cv2.destroyAllWindows()
cap.release()
def folds_pattern_image():
path = 'Folder_Output/folds_pattern.png'
file_exists = exists(path)
if not file_exists:
Files = Path('/Applications')
for file in Files.iterdir():
if re.match("ParaView", file.name):
Para_view = file
Code_name = 'final_folding_pattren_'+str(sys.argv[1])+'.py'
export_results = subprocess.run([str(Para_view)+'/Contents/bin/pvpython', Code_name])
image = cv2.imread(path)
cv2.imshow ("Folds pattern", image)
k = cv2.waitKey(0)
if (k == ord('q')):
cv2.destroyAllWindows()
def velocity_video():
path = 'Folder_Output/Velocity.avi'
file_exists = exists(path)
if not file_exists:
Files = Path('/Applications')
for file in Files.iterdir():
if re.match("ParaView", file.name):
Para_view = file
Code_name = 'velocity_video_'+str(sys.argv[1])+'.py'
export_results = subprocess.run([str(Para_view)+'/Contents/bin/pvpython', Code_name])
cap=cv2.VideoCapture(path)
if not cap.isOpened():
print("Error opening Video File.")
while(True):
ret, frame=cap.read()
if not ret:
break
cv2.imshow("Velocity", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.waitKey(5000)
cv2.destroyAllWindows()
cap.release()
def stiffness_video():
path = 'Folder_Output/Stiffness.avi'
file_exists = exists(path)
if not file_exists:
Files = Path('/Applications')
for file in Files.iterdir():
if re.match("ParaView", file.name):
Para_view = file
Code_name = 'Stiffness_video_'+str(sys.argv[1])+'.py'
export_results = subprocess.run([str(Para_view)+'/Contents/bin/pvpython', Code_name])
cap=cv2.VideoCapture(path)
if not cap.isOpened():
print("Error opening Video File.")
while(True):
ret, frame=cap.read()
if not ret:
break
cv2.imshow("Stiffness", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.waitKey(5000)
cv2.destroyAllWindows()
cap.release()
def growth_factores_t_video():
path = 'Folder_Output/growth_factor_t.avi'
file_exists = exists(path)
if not file_exists:
Files = Path('/Applications')
for file in Files.iterdir():
if re.match("ParaView", file.name):
Para_view = file
Code_name = 'growth_factors_video_'+str(sys.argv[1])+'.py'
export_results = subprocess.run([str(Para_view)+'/Contents/bin/pvpython', Code_name])
# export_results.wait()
cap=cv2.VideoCapture(path)
if not cap.isOpened():
print("Error opening Video File.")
while(True):
ret, frame=cap.read()
if not ret:
break
cv2.imshow("Tangential growth factor", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.waitKey(5000)
cv2.destroyAllWindows()
cap.release()
def growth_factores_r_video():
path = 'Folder_Output/growth_factor_r.avi'
file_exists = exists(path)
if not file_exists:
Files = Path('/Applications')
for file in Files.iterdir():
if re.match("ParaView", file.name):
Para_view = file
Code_name = 'growth_factors_video_'+str(sys.argv[1])+'.py'
export_results = subprocess.run([str(Para_view)+'/Contents/bin/pvpython', Code_name])
cap=cv2.VideoCapture(path)
if not cap.isOpened():
print("Error opening Video File.")
while(True):
ret, frame=cap.read()
if not ret:
break
cv2.imshow("Radial growth factor", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.waitKey(5000)
cv2.destroyAllWindows()
cap.release()
def source_vz_video():
path = 'Folder_Output/source_vz.avi'
file_exists = exists(path)
if not file_exists:
Files = Path('/Applications')
for file in Files.iterdir():
if re.match("ParaView", file.name):
Para_view = file
Code_name = 'source_terms_video_'+str(sys.argv[1])+'.py'
export_results = subprocess.run([str(Para_view)+'/Contents/bin/pvpython', Code_name])
cap=cv2.VideoCapture(path)
if not cap.isOpened():
print("Error opening Video File.")
while(True):
ret, frame=cap.read()
if not ret:
break
cv2.imshow("RGCs Proliferation", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.waitKey(5000)
cv2.destroyAllWindows()
cap.release()
def source_osvz_video():
path = 'Folder_Output/source_osvz.avi'
file_exists = exists(path)
if not file_exists:
Files = Path('/Applications')
for file in Files.iterdir():
if re.match("ParaView", file.name):
Para_view = file
Code_name = 'source_terms_video_'+str(sys.argv[1])+'.py'
export_results = subprocess.run([str(Para_view)+'/Contents/bin/pvpython', Code_name])# export_results.wait()
cap=cv2.VideoCapture(path)
if not cap.isOpened():
print("Error opening Video File.")
while(True):
ret, frame=cap.read()
if not ret:
break
cv2.imshow("ORGCs Proliferation", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.waitKey(5000)
cv2.destroyAllWindows()
cap.release()
def close_fun():
close_qes = messagebox.askquestion("","Are you sure you want to continue without saving results?")
if close_qes =="yes":
root.destroy()
directory_folder = "Folder_Output"
parent_dir_folder = os.getcwd()
path_folder = os.path.join(parent_dir_folder, directory_folder)
shutil.rmtree(path_folder)
sys.exit()
else:
save_fun(True)
def save_fun(in_root):
if in_root:
root.destroy()
subprocess.run(['./save.py'])
sys.exit()
# =============================================================================================
customtkinter.set_appearance_mode("System")
customtkinter.set_default_color_theme("dark-blue")
#current_task_pid_number = 0
#for process in psutil.process_iter():
# if process.name() == "Python" :
# current_task_pid_number = process.pid
cmake_file = 'Makefile'
make_file = 'Brain_growth'
if not exists(cmake_file):
subprocess.run(['cmake','CMakeLists.txt'])
if not exists(make_file):
subprocess.run(['make'])
progress = subprocess.Popen('./progress.py')
run_simulation = subprocess.run(['./Brain_growth', 'Parameters.prm', sys.argv[1]])
progress.kill()
directory_folder = "Folder_Output"
parent_dir_folder = os.getcwd()
path_folder = os.path.join(parent_dir_folder, directory_folder)
if not os.path.exists(path_folder):
os.mkdir(path_folder)
else:
shutil.rmtree(path_folder)
os.mkdir(path_folder)
for dirs, subdirs, files in os.walk(parent_dir_folder):
for file in files:
if file.endswith('.vtk'):
filename =os.path.join(parent_dir_folder, dirs, file)
file_exists =os.path.join(path_folder, file)
if not os.path.exists(file_exists):
shutil.move(filename, path_folder)
csv_filename =os.path.join(parent_dir_folder,"timeing.csv")
shutil.copy(csv_filename, path_folder)
prm_filename =os.path.join(parent_dir_folder,"Parameters.prm")
shutil.copy(prm_filename, path_folder)
post_processing = messagebox.askquestion("", "Done! \n Do you want to see the results?")
if post_processing=="yes":
root = customtkinter.CTk()
root.title("Results Output")
root.geometry("300x500")
folds_pattern = customtkinter.CTkButton(master=root, text="Folds pattern", width = 250, command=folds_pattern_image)
folds_pattern.pack(ipadx=10, ipady=5, expand=True)
cell_video_button = customtkinter.CTkButton(master=root, text="Cell density distribution", width = 250, command=cell_video)
cell_video_button.pack(ipadx=10, ipady=5, expand=True)
stiffness_video_button = customtkinter.CTkButton(master=root, text="Stiffness distribution", width = 250, command=stiffness_video)
stiffness_video_button.pack(ipadx=10, ipady=5, expand=True)
velocity_video_button = customtkinter.CTkButton(master=root, text="Velocity distribution", width = 250, command=velocity_video)
velocity_video_button.pack(ipadx=10, ipady=5, expand=True)
growth_t_video_button = customtkinter.CTkButton(master=root, text="Tangential growth factor distribution", width = 250, command=growth_factores_t_video)
growth_t_video_button.pack(ipadx=10, ipady=5, expand=True)
growth_r_video_button = customtkinter.CTkButton(master=root, text="Radial growth factor distribution", width = 250, command=growth_factores_r_video)
growth_r_video_button.pack(ipadx=10, ipady=5, expand=True)
source_vz_video_button = customtkinter.CTkButton(master=root, text="RGCs proliferation", width = 250, command=source_vz_video)
source_vz_video_button.pack(ipadx=10, ipady=5, expand=True)
source_osvz_video_button = customtkinter.CTkButton(master=root, text="ORGCs proliferation", width = 250, command=source_osvz_video)
source_osvz_video_button.pack(ipadx=10, ipady=5, expand=True)
close_button = customtkinter.CTkButton(master=root, text="Close", hover_color="darkred" ,fg_color="red" ,width = 100, command=close_fun)
close_button.pack(ipadx=10, ipady=5,side=tk.RIGHT,expand=True, pady=6)
save_button = customtkinter.CTkButton(master=root, text="Save", hover_color="darkgreen" ,fg_color="green" ,width = 100, command = lambda:save_fun(True))
save_button.pack(ipadx=10, ipady=5,side=tk.LEFT,expand=True, pady=6)
root.mainloop()
if post_processing=="no":
qes = messagebox.askquestion("","Do you want to save the results?")
if qes =="yes":
save_fun(False)
else:
shutil.rmtree(path_folder)
sys.exit()