-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathline_of_sight_test.py
150 lines (104 loc) · 5.62 KB
/
line_of_sight_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
"""Tests to check line of sight computations."""
import sys
sys.path.append("../..")
from skspatial.objects import Sphere
from paseos import SpacecraftActor, ActorBuilder, GroundstationActor
from paseos.communication.is_in_line_of_sight import is_in_line_of_sight
import pykep as pk
from test_utils import get_default_instance, _PASEOS_TESTS_EARTH_RADIUS
def test_los_between_sats():
"""create satellites where sat1 and 2 are in sight of each other (as well as sat 1 and 3)
but sat 2 and 3 are on opposite sides of the planet"""
_, sat1, earth = get_default_instance()
sat2 = ActorBuilder.get_actor_scaffold("sat2", SpacecraftActor, pk.epoch(0))
ActorBuilder.set_orbit(sat2, [0, 10000000, 0], [0, 0, 8000.0], pk.epoch(0), earth)
sat2.set_central_body_shape(Sphere([0, 0, 0], _PASEOS_TESTS_EARTH_RADIUS))
sat3 = ActorBuilder.get_actor_scaffold("sat3", SpacecraftActor, pk.epoch(0))
sat3.set_central_body_shape(Sphere([0, 0, 0], _PASEOS_TESTS_EARTH_RADIUS))
ActorBuilder.set_orbit(sat3, [0, -10000000, 0], [0, 0, -8000.0], pk.epoch(0), earth)
# check that LOS is correct
assert sat1.is_in_line_of_sight(sat2, pk.epoch(0))
assert sat1.is_in_line_of_sight(sat3, pk.epoch(0))
assert not sat2.is_in_line_of_sight(sat3, pk.epoch(0))
# also check the backend function directly
# also check reverse case (should be same)
assert is_in_line_of_sight(sat1, sat2, pk.epoch(0))
assert is_in_line_of_sight(sat2, sat1, pk.epoch(0))
assert is_in_line_of_sight(sat1, sat3, pk.epoch(0))
assert is_in_line_of_sight(sat3, sat1, pk.epoch(0))
assert not is_in_line_of_sight(sat2, sat3, pk.epoch(0))
assert not is_in_line_of_sight(sat3, sat2, pk.epoch(0))
def test_los_sat_to_ground_station_equatorial():
"""Equatorial ground station and orbit"""
t = pk.epoch(0)
ground_station = GroundstationActor("gs", t)
# Put GS at lat long 0 , 0 with elevation 0m
ActorBuilder.set_ground_station_location(ground_station, 0, 0, 0)
_, sat1, earth = get_default_instance()
# Put the sat over the equator
# Velocity 0, so it's angle to Earth doesn't change, only ground station
# movement due to Earth's rotation will impact visibility short-term this way
ActorBuilder.set_orbit(sat1, [10000000, 0, 0], [0, 0, 0], t, earth)
# Not in vision initially.
assert not ground_station.is_in_line_of_sight(sat1, t, 30.0)
# But after 0.7 days
assert ground_station.is_in_line_of_sight(sat1, pk.epoch(0.7), 65.0)
# Put the sat over the equator, higher up
ActorBuilder.set_orbit(sat1, [100000000, 0, 0], [0, 0, 0], t, earth)
# Not in vision initially.
assert not ground_station.is_in_line_of_sight(sat1, t, 30.0)
# But after 0.7 days
assert ground_station.is_in_line_of_sight(sat1, pk.epoch(0.7), 80.0)
def test_los_sat_to_ground_station_polar():
"""Satellite above the north pole, ground station on the equator and vice versa"""
t = pk.epoch(0)
ground_station = GroundstationActor("gs", t)
# Put GS at lat long 0 , 0 with elevation 0m
ActorBuilder.set_ground_station_location(ground_station, 0, 0, 0)
_, sat1, earth = get_default_instance()
# Put the sat over the north pole
# Velocity 0, so it's angle to Earth doesn't change, only ground station
# movement due to Earth's rotation will impact visibility short-term this way
ActorBuilder.set_orbit(sat1, [0, 0, 10000000], [0, 0, 0], t, earth)
# Not in vision at this height
assert not ground_station.is_in_line_of_sight(sat1, t, 0.1)
# Even after 0.7 days
assert not ground_station.is_in_line_of_sight(sat1, pk.epoch(0.7), 0.1)
# Put GS at Norht Pole lat 90 long 0 , 0 with elevation 0m
ActorBuilder.set_ground_station_location(ground_station, 90, 0, 0)
# Always vision now (almost 90deg)
assert ground_station.is_in_line_of_sight(sat1, t, 89.0)
# Even after 0.7 days
assert ground_station.is_in_line_of_sight(sat1, pk.epoch(0.7), 89.0)
# Put the sat over the equator, GS remains at north pole
ActorBuilder.set_orbit(sat1, [0, 10000000, 0], [0, 0, 0], t, earth)
# Never vision now
assert not ground_station.is_in_line_of_sight(sat1, t, 0.1)
# Even after 0.7 days
assert not ground_station.is_in_line_of_sight(sat1, pk.epoch(0.7), 0.1)
def test_los_sat_to_ground_station_elevation():
"""Testing how elevation of ground station affects angle"""
t = pk.epoch(0)
ground_station = GroundstationActor("gs", t)
# Start with GS at lat long 10 / 30 , 0 with elevation 0m
ActorBuilder.set_ground_station_location(ground_station, 10, 30, 0)
_, sat1, earth = get_default_instance()
# Put the sat over the equator
# Velocity 0, so it's angle to Earth doesn't change, only ground station
# movement due to Earth's rotation will impact visibility short-term this way
ActorBuilder.set_orbit(sat1, [100000000, 0, 0], [0, 0, 0], t, earth)
# Not in vision at this height initially
assert not ground_station.is_in_line_of_sight(sat1, t, 0.1)
# But after 0.6 days at angle > 68.2
assert ground_station.is_in_line_of_sight(sat1, pk.epoch(0.6), 68.2)
# Start with GS at lat long 10 / 30 , 0 with elevation 10000m
ActorBuilder.set_ground_station_location(ground_station, 10, 30, 10000)
# Not in vision at this height initially
assert not ground_station.is_in_line_of_sight(sat1, t, 0.1)
# Still not at this height!
assert not ground_station.is_in_line_of_sight(sat1, pk.epoch(0.6), 68.2)
if __name__ == "__main__":
test_los_between_sats()
test_los_sat_to_ground_station_equatorial()
test_los_sat_to_ground_station_polar()
test_los_sat_to_ground_station_elevation()