Examples

This is a collection of example scripts to demonstrate the capabilities of the spiceminer module.

Planet and Satellite info

 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
#!/usr/bin/env python
#-*- coding:utf-8 -*-

import numpy as np

import spiceminer as sm

# Load the necessary data (this example requires parts of the package 'base',
# which you can download with getdata.py)
sm.load('data')

# Get some planets and moons
mercury = sm.Body('mercury')
venus = sm.Body('venus')
earth = sm.Body('earth')
moon = sm.Body('moon')
mars = sm.Body('mars')

# Get position information for 2 years
times = np.arange(sm.Time(2000), sm.Time(2002), sm.Time.DAY)
mercury_pos = mercury.position(times)
venus_pos = venus.position(times)
earth_pos = earth.position(times)
moon_pos = moon.position(times)
mars_pos = mars.position(times)

# Plot them (the moon is only visible if you zoom in close)
import matplotlib.pyplot as plt
fig, axes = plt.subplots(1)
ax = axes
ax.plot(*mercury_pos[1:3], label=mercury.name)
ax.plot(*venus_pos[1:3], label=venus.name)
ax.plot(*earth_pos[1:3], label=earth.name)
ax.plot(*moon_pos[1:3], label=moon.name)
ax.plot(*mars_pos[1:3], label=mars.name)
ax.grid()
ax.legend()
plt.show(fig)

Curiosity rover on Mars

 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
#!/usr/bin/env python
#-*- coding:utf-8 -*-

import numpy as np

import spiceminer as sm
from spiceminer.extra import angle

def car2sphere(xyz):
    '''Convert cartesian to spherical coordinates.'''
    r = np.sqrt(np.sum(xyz ** 2, 0))
    theta = np.arccos(xyz[2] / r)
    phi = np.arctan(xyz[1] / xyz[0])
    return r, theta, phi

# Load the necessary data (this example requires parts of the packages 'base'
# and 'msl', which you can download with getdata.py)
sm.load('data')

# Get necessary bodies
mars = sm.Body('mars')
rover = sm.Body('msl_rover')

# Let's look at a month shortly after landing
times = np.arange(sm.Time(2013), sm.Time(2013, 2), sm.Time.HOUR)

# Get position on mars surface
position = rover.position(times, observer=mars, frame=mars)
dist, theta, phi = car2sphere(position[1:])

X, Y, Z = np.identity(3)
# Get the angle of the mars rover on the surface (obvious method)
rotation = rover.rotation(times, target=mars)
rover_x = np.array([r.dot(X) for r in rotation[1]])
rover_y = np.array([r.dot(-Y) for r in rotation[1]])
rover_z = np.array([r.dot(-Z) for r in rotation[1]])
radians = np.array([angle(z, p) for z, p in zip(rover_z, position[1:].T)])
radians_x = np.array([angle(x, p) - np.pi/2 for x, p in zip(rover_x, position[1:].T)])
radians_y = np.array([angle(y, p) - np.pi/2 for y, p in zip(rover_y, position[1:].T)])

# Get the angle of the mars rover on the surface (fast, absolute)
points = mars.position(times, observer=rover, frame=rover)
radians2 = np.array([angle(Z, p) for p in points[1:].T])
radians2_x = np.array([angle(Z[1:], p) for p in points[1::2].T])
radians2_y = np.array([angle(Z[1:], p) for p in points[2:].T])

# Some nice diagrams
import matplotlib.pyplot as plt

fig, axes = plt.subplots(2, 2)
ax = axes[0, 0]
ax.plot(phi, theta, label='position')
ax = axes[1, 0]
ax.plot(dist, label='elevation')
ax = axes[0, 1]
ax.plot(np.degrees(radians), label='Abs')
ax.plot(np.degrees(radians_x), label='X')
ax.plot(np.degrees(radians_y), label='Y')
ax = axes[1, 1]
ax.plot(np.degrees(radians2), label='Abs')
ax.plot(np.degrees(radians2_x), label='X')
ax.plot(np.degrees(radians2_y), label='Y')
for ax in axes.ravel():
    ax.legend()

plt.show(fig)