-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjept.py
326 lines (241 loc) · 10.3 KB
/
jept.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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
import PySimpleGUI as sg
from pathlib import Path
import datetime
from datetime import timedelta
import matplotlib.animation as animation
from astroquery.jplhorizons import Horizons
import matplotlib.pyplot as plt
import numpy as np
import subprocess
import configparser
print("Welcome to:")
print(" _ ______ _____ _______ ")
print(" | | ____| __ \__ __|")
print(" | | |__ | |__) | | | ")
print(" _ | | __| | ___/ | | ")
print(" | |__| | |____| | | | ")
print(" \____/|______|_| |_| ")
print(" ")
print("by: Mnux [OK1NYA], Wyattaw [KF0CJJ], Felix [OK9UWU]")#Credits
print(" ")
print(" ")
config = configparser.ConfigParser()
config.read('assets/config.ini')
timestart = datetime.datetime.now()
timestart = datetime.datetime.utcnow().strftime("%Y-%m-%d %H-%M-%S")
timeend = datetime.datetime.now() + timedelta(hours=24)
timeend = timeend.strftime("%Y-%m-%d %H-%M-%S")
#Settings window
def settings_window(settings):
#Settings layout
layout = [
[sg.Text("Location:")],
[sg.Text("Latitude:"), sg.Text("Longitude:"), sg.Text("Altitude:")],
[sg.Input(settings["LOC"]["latitude"], s=8, key="-LAT-"),
sg.Input(settings["LOC"]["longitude"], s=8, key="-LON-"),
sg.Input(settings["LOC"]["altitude"], s=8, key="-ALT-"),],
[sg.Text("Default settings:")],
[sg.Text("Spacecraft ID:")],
[sg.Input(settings["SCID"]["default_spacecraft"], s=22, key="-SCID-")],
[sg.Text("Time step:")],
[sg.Input(settings["TIME"]["default_timestep"], s=4, key="-DTS-")],
[sg.Text("Prediction span(H):")],
[sg.Input(settings["TIME"]["default_timespan"], s=26, key="-TIMESPAN-")],
[sg.Text("Rotator controller:")],
[sg.Input(settings["ROT"]["controller_path"], s=26, key="-CTRLPATH-")],
[sg.Button("Save", key="-SAVE-", s=20)]
]
#create settings window
window = sg.Window("JEPT Settings", layout, modal=True)
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED:
break
#settings
if event == '-SAVE-':
#write to ini file
settings["LOC"]["latitude"] = values["-LAT-"]
settings["LOC"]["longitude"] = values["-LON-"]
settings["LOC"]["altitude"] = values["-ALT-"]
settings["SCID"]["default_spacecraft"] = values["-SCID-"]
settings["TIME"]["default_timestep"] = values["-DTS-"]
settings["TIME"]["default_timespan"] = values["-TIMESPAN-"]
settings["ROT"]["controller_path"] = values["-CTRLPATH-"]
break
window.close()
#Main window
def main_window():
#Main LAYOUT
layout = [
[sg.Text("Spacecraft ID:"),sg.Text("Time step:")],
[sg.Input(settings["SCID"]["default_spacecraft"], key="-SCID-", size=(14)), sg.Input(settings["TIME"]["default_timestep"], key="-STEP-", size=(10))],
[sg.Text("From (YYYY-mm-dd HH-MM-SS):")],
[sg.Input(timestart, key="-PSTART-", size=(26))],
[sg.Text("To (YYYY-mm-dd HH-MM-SS):")],
[sg.Input(timeend, key="-END-", size=(26))],
[sg.Button("Run!", key="-START-"), sg.Button("Settings", key="-SET-"), sg.Checkbox('Rotator:', key="-ROT-", default=False)]
]
#create main window
window = sg.Window("JPL EPHEMRIS PROCESSING TOOL (J.E.P.T.)", layout)
#create an even loop
while True:
event, values = window.read()
#Execute GetAZEL if Start button pressed
if event == '-START-':
settings["SCID"]["spacecraft"] = values["-SCID-"]
#Clears the temp.txt file
with open('temp.txt','w') as f:
f.write("")
#This code processes epheris data from JPL horizons
#This code was written by Wyattaw and modified by mnux
# set your lat/long/elevation
home = {'lat': float(settings["LOC"]["latitude"]), 'lon': float(settings["LOC"]["longitude"]), 'elevation': float(settings["LOC"]["altitude"])}
# set minimum el to search above
minEl = 0
# create object to query horizons website
# prediction of the whole pass/es
obj = Horizons(id= values['-SCID-'],
location=home,
epochs={
'start': values['-PSTART-'],
'stop': values['-END-'],
'step': values['-STEP-']
})
print("Downloading prediction...")
print("DATE TIME AZIMUTH ELEVAT. DISTANCE")#PRINT THE LEGEND
print(" ")#PRINT THE LEGEND
# get ephemris from query
eph = obj.ephemerides()
# make 3 lists for time, az, and el. Then print all of them together,
# so the az el and time all line up. Only print when object is above horizon
azList = []
elList = []
timeList = []
auList = []
for p in eph['datetime_str']:
timeList.append(p)
for p in eph['AZ']:
azList.append(p)
for p in eph['EL']:
elList.append(p)
for p in eph['delta']:
p = p * 149597870.7
auList.append(p)
for (T, A, E, d) in zip(timeList, azList, elList, auList):
if E >= minEl:
print(T, A, E, d) #Terminal printout, T=Time, A=Az, E=El,
print("---END OF PREDICTION--:")#PRINT THE LEGEND
print(" ")#PRINT THE LEGEND
print("Live data:")#PRINT THE LEGEND
print("DATE TIME AZIMUTH ELEVAT. DISTANCE")#PRINT THE LEGEND
print(" ")#PRINT THE LEGEND
# change az from deg to rad
polarAzList = []
for p in azList:
polarAzList.append(np.deg2rad(p))
# plot az el graph
# need to find way to include time
# plot
fig = plt.figure(values['-SCID-'])
ax = plt.subplot(121)
ax.set_ylim(0, 90)
ax.set_xlim(0, 360)
ax.set_ylabel('Elevation')
ax.set_xlabel('Azimuth')
ax.set_xticks(np.arange(0, 360, 45))
ax.grid(True)
ax.plot(azList, elList)
ax2 = plt.subplot(122, projection='polar')
# make 90deg in middle, 0deg on outside
ax2.set_rlim(bottom=90, top=0)
#rotate so 0deg AZ is on top
ax2.set_theta_zero_location('N')
# make theta increase clockwise
ax2.set_theta_direction(-1)
ax2.plot(polarAzList, elList)
ax2 = plt.subplot(122, projection='polar')
# make 90deg in middle, 0deg on outside
ax2.set_rlim(bottom=90, top=0)
#rotate so 0deg AZ is on top
ax2.set_theta_zero_location('N')
# make theta increase clockwise
ax2.set_theta_direction(-1)
ax2.plot(polarAzList, elList)
ax1 = plt.subplot(122, projection='polar')
#Live polar plot
def animate(i):
# create object to query horizons website
obj = Horizons(id=values['-SCID-'],
location=home,
epochs= None)
# get ephemris from query
eph = obj.ephemerides()
# make 3 lists for time, az, and el. Then print all of them together,
# so the az el and time all line up. Only print when object is above
# horizon
azList = []
elList = []
timeList = []
auList = []
for p in eph['datetime_str']:
timeList.append(p)
for p in eph['AZ']:
azList.append(p)
for p in eph['EL']:
elList.append(p)
for p in eph['delta']:
p = p * 149597870.7
auList.append(p)
for (T, A, E, d) in zip(timeList, azList, elList, auList):
if E >= minEl:
print(T, A, E, d)
with open('assets/temp.txt','w') as f: #Writes the values to the tepm.txt file
f.write(str(A))
f.write(",")
f.write(str(E))
f.write("\n")
graph_data = open('assets/temp.txt','r').read()
lines = graph_data.split('\n')
xs = []
ys = []
polarAzList = []
ax1.clear()
for line in lines:
if len(line) > 1:
x, y = line.split(',')
xs.append(float(x))
ys.append(float(y))
for p in xs:
polarAzList.append(np.deg2rad(p))
# make 90deg in middle, 0deg on outside
ax1.set_rlim(bottom=90, top=0)
#rotate so 0deg AZ is on top
ax1.set_theta_zero_location('N')
# make theta increase clockwise
ax1.set_theta_direction(-1)
ax1.scatter(polarAzList, ys)
#Rotator commands
if event == '-ROT-':
#Code that will send AZ EL through serial coming here
print("rot")
ani = animation.FuncAnimation(fig, animate, interval=1000, cache_frame_data=False)
plt.show()
#Open settings if settings button is pressed
if event == '-SET-':
settings_window(settings)
#end program if user closes window
if event == sg.WIN_CLOSED:
break
window.close()
if __name__ == "__main__":
SETTINGS_PATH = Path.cwd()
#create setting object and use ini format
settings = sg.UserSettings(
path=SETTINGS_PATH, filename="assets/config.ini", use_config_file=True, convert_bools_and_none=True
)
theme = settings["GUI"]["theme"]
font_family = settings["GUI"]["font_family"]
font_size = int(settings["GUI"]["font_size"])
sg.theme(theme)
sg.set_options(font=(font_family, font_size))
main_window()