forked from saltastro/timDIMM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_boxes.py
executable file
·64 lines (53 loc) · 1.5 KB
/
find_boxes.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
#!/usr/bin/env python
import sys
import os
import numpy as np
import scipy.ndimage as nd
from astropy.io import fits as pyfits
def rfits(file):
f = pyfits.open(file, memmap=True)
hdu = f[0]
return hdu
def daofind(im):
mean = np.mean(im)
sig = np.std(im)
smooth = nd.gaussian_filter(im, 2.0)
clip = smooth >= (mean + 1.0)
labels, num = nd.label(clip)
pos = nd.center_of_mass(im, labels, range(num + 1))
return num, pos[1:]
def find_boxes(infile):
hdu = rfits(infile)
image = hdu.data
hdr = hdu.header
n, stars = daofind(image)
if n == 2:
print "Found boxes and writing positions."
output = open("init_cen_all", 'w')
xsum = 0.0
ysum = 0.0
for star in stars:
(y, x) = star
xsum += x
ysum += y
output.write("%8.3f %8.3f\n" % (x, y))
output.close()
x = xsum / 2
y = ysum / 2
if np.abs(x - 160.0) < 20 and \
np.abs(y - 120.0) < 20 and \
os.path.exists("SYNCME"):
print "\033[0;32mSYNCING TARGET!\033[0;39m"
os.system("./pygto900.py sync")
os.system("rm SYNCME")
os.system("sleep 2")
else:
print "No or not enough stars found."
output = open("init_cen_all", 'w')
output.write("160.0 120.0\n")
output.write("198.0 120.0\n")
output.close()
return n
if __name__ == '__main__':
infile = sys.argv[1]
find_boxes(infile)