Create a gist now

Instantly share code, notes, and snippets.

@daniestevez /kiss
Last active Jun 25, 2017

What would you like to do?
LilacSat-1 downlink usage analysis
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
FEND = np.byte(0xc0)
kiss = np.fromfile('/tmp/kiss', dtype=np.byte)
image = np.empty(kiss.shape, dtype=np.float)
other = np.empty(kiss.shape, dtype=np.float)
in_image = False
in_other = False
for i in range(kiss.size):
if kiss[i] == FEND:
in_image = False
in_other = False
elif not in_image and not in_other:
# start of packet. guess packet type
# image packets are sent to CSP dest 6
if (kiss[i+1] >> 4) & 0x7 == 0x6:
in_image = True
image[i] = 1
in_other = True
other[i] = 1
elif in_image:
image[i] = 1
else: # in other
other[i] =1
t = np.linspace(0, image.size/(3400/8), num=image.size)
fig = plt.figure(figsize=(25,2))
ax = fig.add_subplot(111)
plt.fill_between(t, 0, image, color='blue', linewidth=0)
plt.fill_between(t, 0, other, color='red', linewidth=0)
plt.title('LilacSat-1 downlink usage (per byte)')
plt.xlabel('Time (s)')
plt.legend(['Image', 'Other (telemetry)'])
plt.axis([0, t[-1], 0, 1])
fig.savefig('lilacsat1-perbyte.png', bbox_inches='tight')
average = np.ones(int(5*3600/8))
average = average/average.size
fig = plt.figure(figsize=(25,10))
plt.plot(t, np.convolve(image, average, mode='same'), color='blue')
plt.plot(t, np.convolve(other, average, mode='same'), color='red')
plt.plot(t, np.convolve(image+other, average, mode='same'), color='green')
plt.legend(['Image', 'Other (telemetry)', 'Total'])
plt.title('LilacSat-1 downlink usage (5 second average)')
plt.xlabel('Time (s)')
plt.axis([0, t[-1], 0, 1])
fig.savefig('lilacsat1-5savg.png', bbox_inches='tight')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment