-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathgraphdist.py
executable file
·42 lines (39 loc) · 1.25 KB
/
graphdist.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
#!/usr/bin/env python3
#
# graphdist.py - Don Cross - 2020-01-01
#
# Graphs the distance between Neptune and the Sun
# as a function of time. Shows that the movement
# of the Solar System Barycenter causes two
# local minima and one local maximum of the distance
# function within one small arc of Neptune's orbit.
#
import sys
import matplotlib.pyplot as plt
import astronomy
def GraphPlanetHelioDistance(body, t1, t2, npoints):
xlist = []
ylist = []
for i in range(npoints+1):
ut = t1.ut + ((i / npoints) * (t2.ut - t1.ut))
time = astronomy.Time(ut)
vec = astronomy.HelioVector(body, time)
dist = vec.Length()
xlist.append(ut)
ylist.append(dist)
plt.plot(xlist, ylist, 'b.')
plt.show()
plt.close('all')
if __name__ == '__main__':
if not (4 <= len(sys.argv) <= 5):
print('USAGE: graphdist.py planet yyyy-mm-ddThh:mm:ssZ yyyy-mm-ddThh:mm:ssZ [npoints]')
sys.exit(1)
body = astronomy.Body[sys.argv[1]]
time1 = astronomy.Time.Parse(sys.argv[2])
time2 = astronomy.Time.Parse(sys.argv[3])
if len(sys.argv) > 4:
npoints = int(sys.argv[4])
else:
npoints = 1200
GraphPlanetHelioDistance(body, time1, time2, npoints)
sys.exit(0)