forked from DaRasch/spiceminer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
46 lines (40 loc) · 1.85 KB
/
example.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
# This example will show the basic usage of the spiceminer module.
from spiceminer import frange, dtrange, Time, kernel
# Or simply from spiceminer import *. I just like to be explicit.
# First we need to load some kernels:
kernel.load('data')
# Next get the object we desire info about:
obj = kernel.get('MARS')
print obj
print 'Parent: ', obj.parent()
print 'Children:', obj.children()
# Note: if you know the id of the object rather than the name, you can also
#do: kernel.get(499)
# We also need some time frame to get data from:
start = Time(2000, 1, 1)
stop = Time(2000, 2, 1)
times = frange(start, stop, Time.DAY)
# The Time-class is similar to the well known datetime but has the advantage
#that it actullay represents POSIX time instead of a date.
# Frange works just like the normal xrange(), the only difference is, that it
#can handle floats.
# If you don't want to let go off datetime there is also a range function for
#that:
import datetime
start2 = datetime.datetime(2000, 1, 1)
stop2 = datetime.datetime(2000, 2, 1)
times2 = dtrange(start2, stop2, stop2 - start2)
# Now for the interesting stuff. Getting positional data is pretty easy:
data = obj.state(times)
data2 = obj.state(times2, observer='EARTH')
print data
print data2
# Note: the matrix returned by this method is transposed for easier plotting:
# [time, time, time, time, time, time, time, time]
# [x_pos, x_pos, x_pos, x_pos, x_pos, x_pos, x_pos, x_pos]
# [y_pos, y_pos, y_pos, y_pos, y_pos, y_pos, y_pos, y_pos]
# [z_pos, z_pos, z_pos, z_pos, z_pos, z_pos, z_pos, z_pos]
# [x_speed, x_speed, x_speed, x_speed, x_speed, x_speed, x_speed, x_speed]
# [y_speed, y_speed, y_speed, y_speed, y_speed, y_speed, y_speed, y_speed]
# [z_speed, z_speed, z_speed, z_speed, z_speed, z_speed, z_speed, z_speed]
# For a real tutorial consult the documentation.