-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcommunication_window_test.py
176 lines (146 loc) · 5.44 KB
/
communication_window_test.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
"""Test to check the communication function(s)"""
from paseos import (
SpacecraftActor,
GroundstationActor,
ActorBuilder,
find_next_window,
get_communication_window,
)
import pykep as pk
import numpy as np
def setup_sentinel_example(t0):
"""Sets up the example with sentinel2B and maspolamas ground station."""
"""Tests the find_next_window function"""
earth = pk.planet.jpl_lp("earth")
# Define Sentinel 2 orbit
sentinel2B = ActorBuilder.get_actor_scaffold("Sentinel2B", SpacecraftActor, t0)
sentinel2B_line1 = "1 42063U 17013A 22300.18652110 .00000099 00000+0 54271-4 0 9998"
sentinel2B_line2 = "2 42063 98.5693 13.0364 0001083 104.3232 255.8080 14.30819357294601"
s2b = pk.planet.tle(sentinel2B_line1, sentinel2B_line2)
# Calculating S2B ephemerides.
sentinel2B_eph = s2b.eph(t0)
ActorBuilder.set_orbit(
actor=sentinel2B,
position=sentinel2B_eph[0],
velocity=sentinel2B_eph[1],
epoch=t0,
central_body=earth,
)
# Define ground station
maspalomas_groundstation = ActorBuilder.get_actor_scaffold(
name="maspalomas_groundstation", actor_type=GroundstationActor, epoch=t0
)
ActorBuilder.set_ground_station_location(
maspalomas_groundstation, 27.7629, -15.6338, 205.1, minimum_altitude_angle=5
)
# Add communication link
ActorBuilder.add_comm_device(sentinel2B, device_name="link1", bandwidth_in_kbps=1)
return sentinel2B, maspalomas_groundstation
def test_find_next_window():
# Test window from other test is found
t0 = pk.epoch_from_string("2022-Oct-27 22:57:00")
sentinel2B, maspalomas_groundstation = setup_sentinel_example(t0)
start, length, transmittable_data = find_next_window(
sentinel2B,
local_actor_communication_link_name="link1",
target_actor=maspalomas_groundstation,
search_window_in_s=360,
t0=t0,
)
assert np.isclose(start.mjd2000, 8335.957060185183)
assert np.isclose(length, 740.0000001071021, rtol=0.01, atol=3.0)
assert np.isclose(transmittable_data, 740000, rtol=0.01, atol=3000)
# Test correct return if no window found
t0 = pk.epoch_from_string("2022-Oct-27 20:00:00")
sentinel2B, maspalomas_groundstation = setup_sentinel_example(t0)
start, length, transmittable_data = find_next_window(
sentinel2B,
local_actor_communication_link_name="link1",
target_actor=maspalomas_groundstation,
search_window_in_s=360,
t0=t0,
)
assert start is None
assert length == 0
assert transmittable_data == 0
def test_communication_link_sat_to_ground():
"""This test checks if the communication window between Sentinel
and one of it's ground stations matches
"""
t0 = pk.epoch_from_string("2022-Oct-27 22:58:09")
sentinel2B, maspalomas_groundstation = setup_sentinel_example(t0)
# Check again after communication_window_end_time
(
communication_window_start_time,
communication_window_end_time,
_,
) = get_communication_window(
sentinel2B,
local_actor_communication_link_name="link1",
target_actor=maspalomas_groundstation,
dt=1,
t0=t0,
data_to_send_in_b=1000000,
)
window_in_s = (
communication_window_end_time.mjd2000 - communication_window_start_time.mjd2000
) * pk.DAY2SEC
expected_window_in_s = 739.0000000305008
assert np.isclose(expected_window_in_s, window_in_s)
def test_communication_link_sat_to_sat():
# create satellites where sat1 and sat2 starts from the same point but move along different orbit.
# At t=1470s they will not be in line of sight anymore.
earth = pk.planet.jpl_lp("earth")
sat1 = ActorBuilder.get_actor_scaffold("sat1", SpacecraftActor, pk.epoch(0))
sat2 = ActorBuilder.get_actor_scaffold("sat2", SpacecraftActor, pk.epoch(0))
ActorBuilder.set_orbit(
sat1,
position=[10000000, 1e-3, 1e-3],
velocity=[1e-3, 8000, 1e-3],
epoch=pk.epoch(0),
central_body=earth,
)
ActorBuilder.set_orbit(
sat2,
position=[10000000, 1e-3, 1e-3],
velocity=[1e-3, -8000, 1e-3],
epoch=pk.epoch(0),
central_body=earth,
)
# Add communication link
ActorBuilder.add_comm_device(sat1, device_name="link1", bandwidth_in_kbps=1)
# Check communication link at == 0. Satellites shall be in line of sight
(
_,
communication_window_end_time,
transmitted_data_in_b,
) = get_communication_window(
sat1,
local_actor_communication_link_name="link1",
target_actor=sat2,
dt=10,
t0=pk.epoch(0),
data_to_send_in_b=10000,
)
assert (communication_window_end_time.mjd2000 * pk.DAY2SEC >= 10) and (
transmitted_data_in_b == 10000
)
# Check again after communication_window_end_time
(
communication_window_start_time,
communication_window_end_time,
transmitted_data_in_b,
) = get_communication_window(
sat1,
local_actor_communication_link_name="link1",
target_actor=sat2,
dt=10,
t0=communication_window_end_time,
data_to_send_in_b=10000,
)
assert (transmitted_data_in_b == 0) and np.isclose(
communication_window_end_time.mjd2000, communication_window_start_time.mjd2000
)
if __name__ == "__main__":
# test_communication_link_sat_to_sat()
test_communication_link_sat_to_ground()