-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguideCam.py
More file actions
126 lines (101 loc) · 3.42 KB
/
guideCam.py
File metadata and controls
126 lines (101 loc) · 3.42 KB
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
#! /usr/bin/python
"""
guideCam.py
MRO guider imaging and fits routines using input from camera.cpp
"""
__author__ = "Matt Armstrong"
__copyright__ = "NA"
__credits__ = ["github.com/UWMRO/"]
__license__ = "GPL"
__version__ = "0.1"
__maintainer__ = "NA"
__email__ = "NA"
__status__ = "Developement"
import numpy as np
import pyfits
import subprocess
import time
import os
import glob
import thread
import traceback
class GuideCamera(object):
def __init__(self):
self.wait = 1.0
self.status = None
self.ssag = os.getcwd()+"/camera"
self.statusDict = {1:'idle', 2:'expose', 3:'reading'}
self.gain = 1
def expose(self, name, exp, dir, gain):
thread.start_new_thread(self.runExpose, (name, exp, dir, gain))
def runExpose(self, name, exp, dir, gain):
"""
Connect to the OpenSSAG and take image
input a given file name and exposure
output whether the image was successful
Tells camera to take an image, it will output a binary file named "test" with 1000 ms exposure.
Can also use './camera test 0 0' to check camera.
"""
if dir == None:
dir = os.getcwd()
if '.fit' not in name:
name = name+'.fits'
name = dir+'/'+str(name)
#print dir, name, self.ssag, exp
expose = float(exp)*1000
if gain == None:
gain = self.gain
try:
subprocess.Popen([self.ssag, 'image', 'binary', str(expose), str(gain)])
self.status = 2
#Pause for the camera to run
time.sleep(self.wait+float(exp))
self.status = 1
except Exception,e:
print ("failed")
print (str(e))
traceback.print_exc()
return False
return True
def binarytoFits(self, fileName, exp, gain, focus):
binary=np.fromfile(fileName, dtype='u1').reshape(1024,1280)
fileName = os.path.split(fileName)[1]
fileName = fileName[:-4]
print fileName
prihdr = self.createHeader(exp, gain) #create emtpy header information
hdu=pyfits.PrimaryHDU(binary, header = prihdr) #create a primary header file for the FITS image
hdulist=pyfits.HDUList([hdu])
prihdr['FOCUSPOS'] = str(focus)
prihdr['IMAGTYP'] = 'guide'
# Write the image and header to a FITS file using variable name.
hdulist.writeto(os.getcwd()+"/20171015/%s.fits"%fileName, clobber=True)
return
def createHeader(self, exp, gain):
prihdr = pyfits.Header()
prihdr['COMMENT'] = 'MRO Guider Camera'
prihdr['COMMENT'] = 'Orion Star Shoot Auto Guider'
prihdr['IMAGTYP'] = None
prihdr['EXPTIME'] = exp
prihdr['CCDBIN1'] = 1
prihdr['CCDBIN2'] = 1
prihdr['GAIN'] = gain
prihdr['RN'] = None
return prihdr
def checkStatus(self):
print ("return some status message")
print (self.status, self.statusDict[self.status])
return self.status
def checkConnection(self):
try:
subprocess.Popen([self.ssag, '0', '0', '0'])
except Exception, e:
print (e)
def help(self):
print (__doc__)
return
if __name__=="__main__":
gc = GuideCamera()
fNameList = glob.glob(os.getcwd()+'/20171015/*.raw')
for fName in fNameList:
gc.binarytoFits(fName, exp, gain, focus)
#c.runExpose('test',0.1, None, 8)