-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtempCodeRunnerFile.py
172 lines (140 loc) · 4.55 KB
/
tempCodeRunnerFile.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
from matplotlib.pyplot import step
from numpy.linalg import norm
from sgp4.api import Satrec
from sgp4.api import jday
from datetime import datetime
from scipy.integrate import ode
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import mpl_toolkits.mplot3d.axes3d as p3
import ReadingFile as rf
#CONSTS
# gravitational constant
G_meters = 6.67430e-11 # m**3 / kg / s**2
G = G_meters * 10**-9 # km**3/ kg / s**2
EARTH_EQUATORIAL_RADIUS = 6378.135 # equatorial radius
EARTH_FLATTENING_CONSTANT = 1 / 298.26
GEO_SYNC_RADIUS = 42164.57
EARTH_MU=5.972e24 * G
class Debris(object):
def __init__(self,s,t):
self.t=t
self.s=s
self.satellite = Satrec.twoline2rv(s, t)
self.propagar
self.get_trayectory
self.trayectory=[]
def propagar(self):
#get actual date
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
now = now.split()
#separar la fecha y la hora
year,month,day=now[0].split('-')
hour,minute,seconds=now[1].split(':')
#get jd and fr from jday funcation
self.jd, self.fr = jday(int(year),int(month),int(day),int(hour),int(minute),int(seconds))
#get position and velocity based on jd and fr
e, self.position, self.velocity = self.satellite.sgp4(self.jd, self.fr)
return self.position,self.velocity
def two_body(self,t,y,mu=EARTH_MU):
rx,ry,rz,vx,vy,vz=y
r=np.array([rx,ry,rz])
#calc norm of r
norm_r=np.linalg.norm(r)
#two body aceleration
ax,ay,az= r*mu/norm_r**3
return [vx,vy,vz,ax,ay,az]
def get_trayectory(self,tspan=100.0*60.0,dt=100.0,mu=EARTH_MU):
#r0,v0=d.propagar()
r0=[*self.position]
v0=[*self.velocity]
#number of steps
n_steps=int(np.ceil(tspan/dt))
ys=np.zeros((n_steps,6))
ts=np.zeros((n_steps,1))
#initial conditions
y0=r0+v0
ys[0]=np.array(y0)
step=1
#solver
solver=ode(self.two_body)
solver.set_integrator('lsoda')
solver.set_initial_value(y0,0)
solver.set_f_params(mu)
while step<n_steps:
solver.integrate(solver.t+dt)
#print(solver.t,solver.y)
ts[step]=solver.t
ys[step]=solver.y
step+=1
self.rs=ys[:,:3]
return self.rs
def animate(self,i):
self.propagar()
self.pos = self.get_trayectory()
self.pos = self.pos[-1:]
self.last_pos = self.pos[-1]
self.trayectory.append(self.last_pos.tolist())
self.trayectory_f = np.asarray(self.trayectory)
#ax.clear()
ax.plot([0], [0], [0], 'bo', markersize=9, label="Earth")
#ax.plot(self.pos[::, 0], self.pos[::, 1], self.pos[::, 2], 'ro')
ax.plot(self.trayectory_f[::, 0], self.trayectory_f[::, 1], self.trayectory_f[::, 2], 'w--')
def graficar(info):
#plot grafica
plt.style.use('dark_background')
fig = plt.figure()
fig.set_facecolor('black')
global ax
ax = p3.Axes3D(fig)
ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
#ax.set_visible(False)
ax.grid(False)
# Hide axes ticks
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])
debris=[]
anim=[]
for line in info:
debris.append(Debris(*line))
for i in range(0, 15):
try:
anim.append(animation.FuncAnimation(fig, debris[i].animate, interval=1000, cache_frame_data=False))
except:
pass
plt.axis('off')
plt.show()
#gui
import tkinter as tk
from PIL import ImageTk, Image
window = tk.Tk()
window.geometry("300x400")
window.resizable(0,0)
window.title("Mapping Space Trash")
ico = tk.PhotoImage(file = 'sat.png')
window.iconphoto(False, ico)
satimg = Image.open("sat.png")
test = ImageTk.PhotoImage(satimg)
lab1 = tk.Label(image=test)
lab1.image = test
lab1.place(x=100, y= 45)
lab2 = tk.Label(window, text='Select the debris you want to map').place(x=60, y=210)
satelites = [
"COSMOS",
"FENGYUN",
"IRIDIUM33",
"MICROSAT"
]
satelite = tk.StringVar(window)
satelite.set(satelites[0])
sat_menu = tk.OptionMenu(window, satelite, *satelites)
sat_menu.place(x=100, y=250, width=100)
def get_grafica(name):
info = rf.ReadFile(name + ".txt")
graficar(info)
tk.Button(window,command=lambda: get_grafica(satelite.get()), text = "Map", width=10, bg='#25387d', fg='white').place(x=110,y=300)
window.mainloop()