-
Notifications
You must be signed in to change notification settings - Fork 3
/
run_peaksearches.py
143 lines (127 loc) · 4.91 KB
/
run_peaksearches.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
from __future__ import print_function, division
import glob, os
HOME = "/data/visitor/ma4200/id11/ImageD11_peaksearches"
THRESHOLDS = [ int(100*pow(2,i)) for i in range(9) ]
splinefiles = {
"10241024" : "/data/id11/3dxrd/inhouse/Frelon21/frelon21_mar16_2x2.spline",
"20482048" : "/data/id11/3dxrd/inhouse/Frelon21/frelon21_mar16.spline"
}
def read_info_file( infofile ):
""" get the information from the info file for peaksearch"""
with open( infofile, "r" ) as f:
info = {}
for line in f.readlines():
key, val = line.split("=")
info[key] = val.lstrip().rstrip()
command = info["Comment"]
items = command.split()
# 0 1 2 3 4 5 6
# ftomointerlaced silicon 0 180 90 0.08 1
if items[0] == "ftomointerlaced":
info[ "interlaced" ] = True
if items[6] == "1":
info[ "iflip" ] = True
# interlaced so items[2] == range
info["step"] = float(items[3])/int(items[4])/2 # interlaced
info["start"] = float( items[2] ) + info["step"]/2.
info["last"] = int(items[4])-1
info["first"] = 0
if items[0] == "ftomoscan":
# not interlaced so items[3] == range
info["step"] = float(items[3])/int(items[4]) # interlaced
info["start"] = float( items[2] ) + info["step"]/2.
info["last"] = int(items[4])-1
info["first"] = 0
return info
def do_bg( info, N=5 ):
if info.has_key( "interlaced" ):
info[ "bgstem" ] = info["Prefix"]+"0_"
else:
info[ "bgstem" ] = info["Prefix"]
cmd = []
for i in range(N):
cmd += [ "bgmaker.py",
"--namestem={Directory}/{bgstem}",
" -F .edf "
"--first=%d"%(i+int(info["first"])),
"--last=%d"%(int(info["last"]) - N - 1),
"--outfile={outfolder}/{Prefix}_b%04d.edf"%(i),
"--step=%d"%(N),
"\n" ]
cmd += ["median.py -d",
"-i {outfolder}/{Prefix}_b0000.edf",
"-f 0 -l 5",
"-o {outfolder}/{Prefix}_median",
"\n" ]
for i in range(N):
cmd.append( "rm {outfolder}/{Prefix}_b%04d.edf\n"%(i) )
# skip gzip as it gives annoying messages
# cmd.append( "gzip -q -1 {outfolder}/{Prefix}_median.edf\n" )
# writes to
return " ".join( cmd ).format( **info )
def do_peaksearch( info ):
cmd = [do_bg(info),
"peaksearch.py",
" -F .edf ",
"--namestem={Directory}/{Prefix}",
"--outfile={outfolder}/{Prefix}.spt",
"--darkfile={outfolder}/{Prefix}_median.edf"
]
for option in ("flood","first","last","ndigits"):
if info.has_key( option ):
cmd.append( "--%s={%s}"%(option, option ) )
for option in ( "interlaced", "iflip" ):
if info.has_key( option ):
cmd.append( "--"+option )
# side effects :start needs step and override
if info.has_key( "start" ):
cmd.append( "--step={step}" )
cmd.append( "--start={start}" )
cmd.append( "--OmegaOverRide" )
# spline or not
if info.has_key( "splinefile" ):
cmd += [ "--splinefile={splinefile}", "--perfect_images=N" ]
else:
cmd.append("--perfect_images=Y")
for t in info["thresholds"]:
cmd.append("--threshold=%d"%(t))
cmdline = " ".join( cmd ).format( **info )
return cmdline
shfiles = []
for line in open("scans_to_process.txt","r").readlines():
line = line.rstrip()
if len(line) == 0 or line[0] == "#":
continue
folders = sorted(glob.glob( line ))
for folder in folders:
assert os.path.isdir( folder )
ftomofolder, scanfolder = os.path.split( folder )
dataroot, ftfolder = os.path.split( ftomofolder )
outfolder = os.path.join( HOME, scanfolder )
print( "# ",folder )
print( "#\t",outfolder )
if not os.path.exists( outfolder ) :
os.makedirs( outfolder )
info = read_info_file( os.path.join( folder, scanfolder+".info" ) )
info[ "outfolder" ] = outfolder
info[ "thresholds" ] = THRESHOLDS
# print(info)
info[ "splinefile" ] = splinefiles[ info["Dim_1" ]+info["Dim_2" ] ]
cmdline = do_peaksearch( info )
with open( os.path.join( outfolder, "dopks.sh" ), "w" ) as shfile:
shfile.write("# folder %s\n"%(folder))
shfile.write(cmdline)
shfiles.append( os.path.join( outfolder ) )
todo = []
for folder in shfiles:
if os.path.exists( os.path.join(folder, "dopks.log")):
print("Done",folder)
else:
print("Todo:",folder)
#continue
todo.append( "sh " + os.path.join( folder, "dopks.sh") + " >> " +
os.path.join( folder, "dopks.log") )
import multiprocessing
p=multiprocessing.Pool(multiprocessing.cpu_count())
for r in p.imap_unordered( os.system, todo ):
pass