-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplanetary_positions.py
86 lines (58 loc) · 1.81 KB
/
planetary_positions.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
#!/usr/bin/python
'''
Calculates planetary positions.
Usage
'''
import ephem
from datetime import datetime
from datetime import timedelta
import matplotlib.pylab as plt
import numpy as np
class Positions(dict):
def __init__(self, planets):
for p in planets:
self[p] = {'ra':[], 'dec':[]}
self['time'] = []
self['days'] = []
return
def planets(self):
keys = super(Positions, self).keys()
keys.remove('time')
keys.remove('days')
return keys
def generate(planets=[ephem.Mercury()],
begin=datetime(2014, 12, 1),
end=datetime(2017, 12, 5),
step=timedelta(days=1)):
positions = Positions(planets)
time = begin
while time <= end:
for planet in planets:
planet.compute(time)
positions[planet]['ra'].append(planet.ra)
positions[planet]['dec'].append(planet.dec)
positions['time'].append(time)
positions['days'].append((time - begin).total_seconds() / (3600 * 24))
time += step
for planet in planets:
positions[planet]['ra'] = np.array(positions[planet]['ra'])
positions[planet]['dec'] = np.array(positions[planet]['dec'])
return positions
def plot(positions, out='planets.png'):
for planet in positions.planets():
ra = positions[planet]['ra']
dec = [d * 180. / np.pi for d in positions[planet]['dec']]
plt.plot(ra, dec, '.', label=planet.name)
plt.xlim([0, 2 * np.pi])
#plt.ylim([-np.pi/2.0, np.pi/2.0])
plt.xticks(
(0.0, np.pi ,2 * np.pi),
('00:00', '12:00', '24:00'))
plt.xlabel(r'$\alpha$')
plt.ylabel(r'$\delta$')
plt.legend()
plt.savefig(out)
return
if __name__ == '__main__':
positions = generate()
plot(positions)