-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKCWI_Offset.sin
executable file
·205 lines (169 loc) · 6.92 KB
/
KCWI_Offset.sin
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#! @KPYTHON3@
import sys,os
import subprocess
from PyQt5.QtWidgets import QCheckBox,QFrame,QLabel,QHBoxLayout,QLineEdit,QPushButton,QVBoxLayout,QApplication,QWidget, QTextEdit, QGridLayout
def main():
app = QApplication(sys.argv)
w = MyWindow()
w.show()
sys.exit(app.exec_())
class separator(QFrame):
def __init__(self):
super().__init__()
self.setFrameShape(QFrame.HLine)
self.setFrameShadow(QFrame.Sunken)
self.setLineWidth(3)
class MyWindow(QWidget):
def __init__(self, *args):
super().__init__()
#self.runMode = 'debug'
self.objectMoveColor = 'Gold'
self.telescopeMoveColor = 'SkyBlue'
self.slicerMoveColor = 'Plum'
self.takeGuiderImageColor = 'LawnGreen'
self.runMode = ''
self.init_ui()
self.setWindowTitle("KCWI Target Alignment")
def init_ui(self):
# create objects
#self.lbl = QLabel('Offsetig mode')
#self.en = QRadioButton('East-North (arcseconds')
#self.xy = QRadioButton('Magiq coordinates (arcseconds)')
#self.xyp = QRadioButton('Magiq coordinates (pixels)')
#self.sl = QRadioButton('Slicer (slices)')
# layout for radio buttons
#v1_layout = QVBoxLayout()
#v1_layout.addWidget(self.en)
#v1_layout.addWidget(self.xy)
#v1_layout.addWidget(self.xyp)
#v1_layout.addWidget(self.sl)
separator1 = separator()
separator2 = separator()
separator3 = separator()
separator4 = separator()
# value of offset
self.lbl1 = QLabel('Value')
self.value = QLineEdit()
self.value.setText('1')
self.lbl5 = QLabel('positive value, arcseconds or slices')
h1_layout = QHBoxLayout()
h1_layout.addWidget(self.lbl1)
h1_layout.addWidget(self.value)
h1_layout.addWidget(self.lbl5)
# direction of offset
self.lbl2 = QLabel('Move object in guider coordinates')
self.up = QPushButton('Up')
self.down = QPushButton('Down')
self.left = QPushButton('Left')
self.right = QPushButton('Right')
list = [self.up, self.down, self.left, self.right]
for button in list:
button.setStyleSheet("background-color : %s" % self.objectMoveColor)
g2_layout = QGridLayout()
g2_layout.addWidget(self.lbl2,0,0,1,3)
g2_layout.addWidget(self.up,1,1)
g2_layout.addWidget(self.down,3,1)
g2_layout.addWidget(self.left,2,0)
g2_layout.addWidget(self.right,2,2)
# direction of offset
self.lbl3 = QLabel('Move telescope in absolute coordinates')
self.e = QPushButton('E')
self.w = QPushButton('W')
self.n = QPushButton('N')
self.s = QPushButton('S')
list = [self.e, self.w, self.n, self.s]
for button in list:
button.setStyleSheet("background-color : %s" % self.telescopeMoveColor)
g3_layout = QGridLayout()
g3_layout.addWidget(self.lbl3, 0, 0, 1, 3)
g3_layout.addWidget(self.e, 2, 0)
g3_layout.addWidget(self.w, 2, 2)
g3_layout.addWidget(self.n, 1, 1)
g3_layout.addWidget(self.s, 3, 1)
# direction of offset
self.lbl4 = QLabel('Move object across slicer')
self.sliceleft = QPushButton('Slice Left')
self.sliceright = QPushButton('Slice Right')
list = [self.sliceleft, self.sliceright]
for button in list:
button.setStyleSheet("background-color : %s" % self.slicerMoveColor)
h4_layout = QHBoxLayout()
h4_layout.addWidget(self.lbl4)
h4_layout.addWidget(self.sliceleft)
h4_layout.addWidget(self.sliceright)
self.te = QTextEdit()
self.take_guider = QCheckBox('Take guider image after every move')
self.test_mode = QCheckBox('Test mode (show command, no moves)')
# layout
v_layout = QVBoxLayout(self)
#v_layout.addLayout(v1_layout)
v_layout.addLayout(h1_layout)
v_layout.addWidget(separator1)
v_layout.addLayout(g2_layout)
v_layout.addWidget(separator2)
v_layout.addLayout(g3_layout)
v_layout.addWidget(separator3)
v_layout.addLayout(h4_layout)
v_layout.addWidget(separator4)
self.take_guider_button = QPushButton('Take Guider Image')
self.take_guider_button.setStyleSheet("background-color: %s" % self.takeGuiderImageColor)
v_layout.addWidget(self.take_guider_button)
v_layout.addWidget(self.te)
v_layout.addWidget(self.take_guider)
v_layout.addWidget(self.test_mode)
self.setLayout(v_layout)
# associate action
buttons = [self.up, self.down, self.right, self.left, self.e, self.w, self.s, self.n, self.sliceleft, self.sliceright, self.take_guider_button]
for button in buttons:
button.clicked.connect(self.btn_click)
def run_command(self, command):
try:
kroot = os.environ['KROOT']
except:
kroot = ''
cmdline = os.path.join(kroot,'rel','default','bin',command)
if self.test_mode.isChecked():
self.runMode = 'debug'
else:
self.runMode = 'normal'
if self.runMode is not 'debug':
p = subprocess.Popen(cmdline, stdout = subprocess.PIPE,stderr = subprocess.PIPE, shell=True)
output, errors = p.communicate()
if len(errors)>0:
output = output + errors
self.te.setText(str(output.decode()))
else:
self.te.setText(str(cmdline))
def btn_click(self):
sender = self.sender()
value = self.value.text()
if sender.text() == 'Up':
command = '%s 0 -%f' % ('gxy', float(value))
elif sender.text() == 'Down':
command = '%s 0 %f' % ('gxy', float(value))
elif sender.text() == 'Left':
command = '%s %f 0' % ('gxy', float(value))
elif sender.text() == 'Right':
command = '%s -%f 0' % ('gxy', float(value))
elif sender.text() == 'E':
command = '%s %f 0' % ('en', float(value))
elif sender.text() == 'W':
command = '%s -%f 0' % ('en', float(value))
elif sender.text() == 'N':
command = '%s 0 %f' % ('en', float(value))
elif sender.text() == 'S':
command = '%s 0 -%f' % ('en', float(value))
elif sender.text() == 'Slice Left':
command = '%s left %f' % ('moveSlicer',float(value))
elif sender.text() == 'Slice Right':
command = '%s right %f' % ('moveSlicer',float(value))
elif sender.text() == 'Take Guider Image':
command = 'saveGuiderImageLocal'
else:
command = None
if command is not None:
self.run_command(command)
if self.take_guider.isChecked():
self.run_command('saveGuiderImageLocal')
if __name__ == "__main__":
main()