forked from UWMRO/TCS
/
ReadConfigFiles.py
177 lines (160 loc) · 6.9 KB
/
ReadConfigFiles.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
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
import time
import wx
import os
import signal
from astropy.time import Time
import thread
import threading
import ephem
import matplotlib
import datetime as dati
from datetime import datetime, timedelta
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.figure import Figure
from matplotlib.image import AxesImage
import matplotlib.image as mpimg
from matplotlib.backends.backend_wxagg import \
FigureCanvasWxAgg as FigCanvas, \
NavigationToolbar2WxAgg as NavigationToolbar
from astroplan import Observer, FixedTarget
from astroplan.plots import plot_sky,plot_airmass
import astropy.units as u
from astropy.coordinates import SkyCoord, EarthLocation, AltAz, FK5
from Finder_picker import plot_finder_image
from twisted.internet import wxreactor
from twisted.internet import reactor, protocol, defer
from twisted.protocols import basic
import subprocess
import Queue
from astroquery.skyview import SkyView
from astropy.wcs import WCS
import webbrowser
import glob
global pipe
pipe=None
def readConfig(self):
"""
Get the basic telescope information if it is available. It would be nice if the dictionary was defined external to the program.
Args:
None
Returns:
None
"""
self.log('==== Initializing Parameters ====')
self.log('Reading in config file ....')
f_in=open('tcc.conf','r')
for line in f_in:
l=line.split()
self.dict[l[0]]=l[1]
f_in.close()
for d in self.dict:
self.log([d,self.dict[d]])
t = self.timeCalc()
self.log('Configuration parameters read')
self.sb.SetStatusText('Tracking: False',0)
self.sb.SetStatusText('Slewing: False',1)
self.sb.SetStatusText('Guiding: False',2)
self.sb.SetStatusText('Init Telescope to Enable Slew / Track',3)
self.sb.SetStatusText('Timezone: UTC',4)
#self.init.targetDecText.SetValue(str(self.dict['lat']))
#self.init.targetEpochText.SetValue(str( '%.3f') % t['epoch'])
self.init.trackingRateRAText.SetValue(str(self.dict['RAtrackingRate']))
self.init.maxdRAText.SetValue(str(self.dict['maxdRA']))
self.init.maxdDECText.SetValue(str(self.dict['maxdDEC']))
return
# ----------------------------------------------------------------------------------
def displaystatus(self):
"""
Update TCC Status grid with information from the TCC.telescope_status dictionary.
Args:
None
Returns:
None
"""
#time.sleep(1.0)
while True:
time.sleep(1.0)
wx.CallAfter(self.control.currentRaPos.SetLabel,(self.telescope_status['RA']))
if self.telescope_status['RA']=='Unknown':
wx.CallAfter(self.control.currentRaPos.SetForegroundColour,('Red'))
else:
wx.CallAfter(self.control.currentRaPos.SetForegroundColour,((0,0,0)))
wx.CallAfter(self.control.currentDecPos.SetLabel,(self.telescope_status['Dec']))
if self.telescope_status['Dec'] == 'Unknown':
wx.CallAfter(self.control.currentDecPos.SetForegroundColour,('Red'))
else:
wx.CallAfter(self.control.currentDecPos.SetForegroundColour,((0,0,0)))
if self.telescope_status['pointState'] == False:
wx.CallAfter(self.control.currentNamePos.SetLabel,('Not Pointed'))
wx.CallAfter(self.control.currentNamePos.SetForegroundColour, ('Red'))
else:
wx.CallAfter(self.control.currentNamePos.SetLabel,(self.target_coords['Name']))
wx.CallAfter(self.control.currentNamePos.SetForegroundColour, ((0,0,0)))
# ----------------------------------------------------------------------------------
def onInit(self,event):
"""
Initialize telescope systems according to values set in the TCC config file. Enables buttons throughout the GUI that depend on initialized systems to function.
Args:
event: handler to allow function to be tethered to a wx widget. Tethered to the "Initialize Telescope Systems" button in the initialization tab.
Returns:
None
"""
if self.telescope_status.get('initState')==False:
self.mro.lon=self.dict['lon']
self.mro.lat=self.dict['lat']
self.horizonlimit=self.dict['horizonLimit']
self.RA_trackrate=self.dict['RAtrackingRate']
self.command_queue = Queue.Queue() #Set up the command queue which pushes commands to the server in a single thread.
self.control.slewButton.Enable()
self.control.trackButton.Enable()
self.control.currentRATRPos.SetLabel(str(self.RA_trackrate))
self.init.atZenithButton.Enable()
self.init.syncButton.Enable()
self.target.listButton.Enable()
self.target.selectButton.Enable()
self.target.enterButton.Enable()
self.target.removeButton.Enable()
self.target.exportButton.Enable()
self.target.plot_button.Enable()
self.target.airmass_button.Enable()
self.target.finder_button.Enable()
self.init.parkButton.Enable()
self.init.coverposButton.Enable()
#Watch Dog Threads
thread.start_new_thread(self.timer,())
thread.start_new_thread(self.checkslew,())
thread.start_new_thread(self.getstatus,())
thread.start_new_thread(self.watchstatus,())
thread.start_new_thread(self.displaystatus,())
thread.start_new_thread(self.checkhandPaddle,())
thread.start_new_thread(self.watchcommand,())
self.telescope_status['initState']=True
if self.telescope_status.get('initState')==True:
self.control.currentJDPos.SetForegroundColour('black')
self.control.currentLSTPos.SetForegroundColour('black')
self.control.currentUTCPos.SetForegroundColour('black')
self.control.currentLocalPos.SetForegroundColour('black')
self.control.currentEpochPos.SetForegroundColour('black')
self.control.currentRATRPos.SetForegroundColour('black')
self.control.currentFocusPos.SetLabel('0.0')
self.control.currentFocusPos.SetForegroundColour('black')
thread.start_new_thread(self.logstatus,())
if self.protocol != None:
self.telescope_status['connectState'] = True
else:
self.telescope_status['connectState'] = False
"""
try:
self.telescope_status['connectState']=self.server.connectState
except NameError:
self.telescope_status['connectState']= False
"""
if self.telescope_status.get('connectState'):
self.log("Successfully connected to the telescope.")
self.sb.SetStatusText('Connected to Telescope', 3)
#self.at_MRO = True #Dev Variable
else:
self.sb.SetStatusText('ERROR: Telescope Not Responding',3)
self.log("Failed to connect to telescope. Restart the application.")
# ----------------------------------------------------------------------------------