-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev_utils.py
89 lines (70 loc) · 2.37 KB
/
dev_utils.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
87
88
import datetime
import copy
import math
import inspect
from math import pi
import ephem
from pprint import pprint
from typing import Tuple, Type
from observatory import Observatory
from target_timeseries import TargetTimeSeries
import datetime
from datetime import timezone
extrema_pt = None
def get_utc_now() -> datetime:
''' gets datetime object without local timezone '''
d = datetime.datetime.utcnow()
epoch = datetime.datetime(1970,1,1)
t = (d - epoch).total_seconds()
return datetime.datetime.fromtimestamp(t, timezone.utc)
def peek(x):
""" quick helper util to know wtf is happening with these ephem objects"""
pprint(inspect.getmembers(x))
def sanity_check(observatory, sat, target_timeseries,
color='b--', min_to_draw=None, extrema_pt=None):
''' Function to plot f(t) '''
import matplotlib.pyplot as plt
from math import pi
import math
def distance(a_coord, b_coord) -> float:
''' Angular distance between two points '''
a_alt, a_az = a_coord
b_alt, b_az = b_coord
if a_az < 0 or b_az < 0: #
raise ValueError
if abs(a_alt) > pi or abs(b_alt) > pi:
raise ValueError
az_diff = abs(a_az - b_az)
if az_diff > pi:
az_diff = (2 * pi) - az_diff
alt_diff = abs(a_alt - b_alt)
dist = math.sqrt(alt_diff**2 + az_diff**2)
return dist
dist_list = []
tar_list = []
sat_list = []
start = target_timeseries.start_datetime
target = target_timeseries.target_body
dt = None
for i in range(target_timeseries.len()):
dt = datetime.timedelta(seconds=i)
observatory.date = start + dt
sat.compute(observatory)
target.compute(observatory)
sat_aa = (sat.alt, sat.az)
tar_aa = (target.alt, target.az)
d = distance(a_coord=sat_aa, b_coord=tar_aa)
dist_list.append(d)
sat_list.append(sat_aa)
plt.figure()
plt.title(sat.name)
print(dt)
if extrema_pt:
# print("MTD=", min_to_draw)
# plt.axhline(y=min_to_draw, color='r', linestyle='-')
plt.axhline(y=extrema_pt[1], color='b', linestyle='--')
plt.axvline(x=extrema_pt[0], color='b', linestyle='--')
#plt.scatter(extrema_pt[0], extrema_pt[1], s=200)
plt.plot(dist_list, color)
plt.ylabel('Distache to target')
plt.show()