/
rerun_FLIMvivo.py
81 lines (75 loc) · 2.6 KB
/
rerun_FLIMvivo.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
#!/usr/bin/env python3
from readPTU_FLIM import PTUreader
import numpy as np
from matplotlib import pyplot as plt
from scipy.spatial import ConvexHull
from scipy.ndimage import binary_dilation
from PIL import Image
from pathlib import Path
import argparse
import os
import subprocess
import re
'''
################
################
## FLIMseg.py ##
################
################
'''
rootpath = Path(os.path.realpath(__file__)).parent.resolve()
################################################################################
#
################################################################################
def process_dir (directory):
print('Processing: ', directory)
output_dir = directory
proc = subprocess.Popen(['python3', str(rootpath / 'FLIMvivo.py'),
'-o', str(output_dir / 'FLIMvivo.output.txt'),
'-f',
'-b',
str(output_dir / 'segments' / 'segment_0.csv')],
stdout=subprocess.PIPE)
procout = str(proc.stdout.read().decode('utf-8'))
print('Biexponetial convolution fit parameters :')
print(procout)
params = np.fromstring(procout, dtype = float, sep = '\t')
fit_mu = params[-2]
fit_sigma = params[-1]
autolifetime = params[-3]
subprocess.call(['python3', str(rootpath / 'FLIMvivo.py'),
'-o', str(output_dir / 'FLIMvivo.output.txt'),
'-f',
'-b',
'-a', str(autolifetime),
'-r', str(fit_mu), str(fit_sigma),
str(output_dir / 'segments')])
print('\n-------------------------------------\n')
################################################################################
# Main function uses argparse to take directories and process files.
################################################################################
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='')
parser.add_argument('data', type=str, nargs='*', default=['./'],
help='data file directory path')
args = parser.parse_args()
datapaths = list(map(Path,args.data))
dirs_to_process = np.array([])
for datapath in datapaths:
if datapath.exists():
if datapath.is_dir():
for datafilepath in datapath.rglob('FLIMseg-output*'):
if datafilepath not in dirs_to_process:
dirs_to_process = np.append(dirs_to_process,
datafilepath)
else:
print('Path {0:s} is not a directory.'.format(str(datapath)))
else:
print('Path {0:s} does not seem to exist.'.format(str(datapath)))
for directory in dirs_to_process:
# try:
process_dir(directory)
# except:
# print('-------------------------------------\n')
# print('There was a problem with: ' + str(directory) +'\n')
# print('-------------------------------------\n')