-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_pass.py
More file actions
100 lines (100 loc) · 4.12 KB
/
plot_pass.py
File metadata and controls
100 lines (100 loc) · 4.12 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import warnings
warnings.filterwarnings('ignore', category=DeprecationWarning, module='matplotlib')
try:
from numpy import VisibleDeprecationWarning
warnings.filterwarnings('ignore', category=VisibleDeprecationWarning)
except ImportError:
pass
import matplotlib.pyplot as plt
import numpy as np
from datetime import datetime
from NextPass import GetNextPass, MAX_AZ_RATE, MAX_EL_RATE, UTC
def plot_pass(ephem_file, target_name, min_el=5.0, trange_hrs=24.0):
now = datetime.now(UTC)
rtn = GetNextPass(ephem_file, target_name, min_el, now, trange_hrs)
print("Rise: {0} Az={1:.1f} El={2:.1f}".format(rtn.start_time(), rtn.start_az(), rtn.start_el()))
print("Mid: {0} Az={1:.1f} El={2:.1f}".format(rtn.midpoint_time(), rtn.midpoint_az(), rtn.midpoint_el()))
print("Set: {0} Az={1:.1f} El={2:.1f}".format(rtn.end_time(), rtn.end_az(), rtn.end_el()))
print("Duration: {0:.0f}s Wrap: {1}".format(rtn.pass_duration(), rtn.which_wrap()))
print()
print("Commands:")
rtn.print_commands()
# Unpack pre-computed trajectory
traj = rtn.trajectory
secs = traj['secs']
azs = traj['az']
els = traj['el']
az_rates = traj['az_rate']
el_rates = traj['el_rate']
fig = plt.figure(figsize=(15, 9))
fig.suptitle("{0} -- {1} UTC".format(target_name, rtn.start_time().strftime('%Y-%m-%d %H:%M:%S')))
# Helper to shade violation regions on an axis
t0 = rtn.start_time()
def shade_violations(ax):
for v in rtn.violations:
s0 = (v['start'] - t0).total_seconds()
s1 = (v['end'] - t0).total_seconds()
ax.axvspan(s0, s1, alpha=0.2, color='red', label='Rate exceeded')
handles, labels = ax.get_legend_handles_labels()
seen = set()
unique = [(h, l) for h, l in zip(handles, labels) if l not in seen and not seen.add(l)]
if unique:
ax.legend(*zip(*unique))
# Row 1: El vs Time
ax1 = fig.add_subplot(2, 3, 1)
ax1.plot(secs, els)
ax1.axhline(y=min_el, color='r', linestyle='--', label='Min El ({0})'.format(min_el))
ax1.set_xlabel('Seconds from rise')
ax1.set_ylabel('Elevation (deg)')
ax1.set_title('Elevation vs Time')
shade_violations(ax1)
ax1.grid(True)
# Row 1: Az vs Time
ax2 = fig.add_subplot(2, 3, 2)
ax2.plot(secs, azs)
ax2.set_xlabel('Seconds from rise')
ax2.set_ylabel('Azimuth (deg)')
ax2.set_title('Azimuth vs Time')
shade_violations(ax2)
ax2.grid(True)
# Row 1: Polar plot (az/el)
ax_polar = fig.add_subplot(2, 3, 3, projection='polar')
az_rad = np.radians(azs)
ax_polar.plot(az_rad, els)
ax_polar.plot(az_rad[0], els[0], 'go', markersize=8, label='Rise')
ax_polar.plot(az_rad[-1], els[-1], 'rs', markersize=8, label='Set')
ax_polar.set_theta_zero_location('N')
ax_polar.set_theta_direction(-1)
ax_polar.set_title('\nAz/El Polar')
ax_polar.legend(loc='lower right')
# Row 2: El rate vs Time
ax3 = fig.add_subplot(2, 3, 4)
ax3.plot(secs, el_rates)
ax3.axhline(y=0, color='k', linestyle='-', linewidth=0.5)
ax3.axhline(y=MAX_EL_RATE, color='r', linestyle='--', label='Max ({0} deg/s)'.format(MAX_EL_RATE))
ax3.axhline(y=-MAX_EL_RATE, color='r', linestyle='--')
ax3.set_xlabel('Seconds from rise')
ax3.set_ylabel('El Rate (deg/s)')
ax3.set_title('Elevation Rate vs Time')
shade_violations(ax3)
ax3.grid(True)
# Row 2: Az rate vs Time
ax4 = fig.add_subplot(2, 3, 5)
ax4.plot(secs, az_rates)
ax4.axhline(y=0, color='k', linestyle='-', linewidth=0.5)
ax4.axhline(y=MAX_AZ_RATE, color='r', linestyle='--', label='Max ({0} deg/s)'.format(MAX_AZ_RATE))
ax4.axhline(y=-MAX_AZ_RATE, color='r', linestyle='--')
ax4.set_xlabel('Seconds from rise')
ax4.set_ylabel('Az Rate (deg/s)')
ax4.set_title('Azimuth Rate vs Time')
shade_violations(ax4)
ax4.grid(True)
plt.tight_layout()
plt.show()
if __name__ == "__main__":
ephem_file = sys.argv[1] if len(sys.argv) > 1 else 'test_ephem.txt'
target_name = sys.argv[2] if len(sys.argv) > 2 else 'target'
plot_pass(ephem_file, target_name)