-
Notifications
You must be signed in to change notification settings - Fork 0
/
alignment_tool.py
60 lines (47 loc) · 1.44 KB
/
alignment_tool.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
#!/usr/bin/env python
"""
This script is used to compute regions of "activity", defined as been
bracketed by y peaks above some threshold.
This is used during alignment to fine tune the position of the pinhole. As
alignment improves, the "ringing" due to diffraction rings will occur
closer and closer together, until it disappears. This script is
to quantify the width of the ringing.
"""
import numpy as NP
def main(filename, *args):
data = NP.genfromtxt(
filename,
delimiter=",",
dtype=float,
skip_header=2,
comments='#')
if NP.isnan(NP.sum(data)):
# failed to load psf data using default settings, assuming it is from
# imageJ and thus tab delimited with no headers
data = NP.genfromtxt(
filename,
dtype=float)
if NP.isnan(NP.sum(data)):
print 'nan in data file, aborting'
return -1
from stats import get_stats
xvec = data[:,0]
yvec = data[:,1]
stats = get_stats(xvec, yvec, noauc=True)
ymax, ymin, ymedian = stats[:3]
leftedge = None
rightedge = None
quartermax = 0.25*(ymax + ymedian)
for idx in xrange(len(yvec)):
if yvec[idx] > quartermax:
leftedge = xvec[idx]
break
for idx in xrange(len(yvec)-1, -1, -1):
if yvec[idx] > quartermax:
rightedge = xvec[idx]
break
print 'Quartermax = ', quartermax
print 'Width of Region of Interest:', rightedge-leftedge
if __name__ == '__main__':
import sys
sys.exit(main(*sys.argv[1:]))