-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_sim.py
206 lines (149 loc) · 5.29 KB
/
test_sim.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import pytest
from globalsat.sim import (
system_capacity,
calc_geographic_metrics,
calc_free_space_path_loss,
generate_log_normal_dist_value,
calc_antenna_gain,
calc_losses,
calc_eirp,
calc_received_power,
calc_noise,
calc_cnr,
calc_spectral_efficiency,
calc_capacity,
calc_agg_capacity
)
def test_system_capacity(setup_params, setup_lut):
"""
Integration test for main system capacity function.
"""
number_of_satellites = 10
results = system_capacity('starlink', number_of_satellites, setup_params, setup_lut)[0]
assert results['number_of_satellites'] == 10
assert round(results['distance']) == 10
assert results['satellite_coverage_area'] == 10
assert results['iteration'] == 0
assert round(results['path_loss']) == 136
assert round(results['antenna_gain']) == 38
assert round(results['eirp']) == 68
assert round(results['received_power']) == -41
assert round(results['noise']) == -90
assert round(results['cnr']) == 49.0
assert results['spectral_efficiency'] == 5.768987
assert round(results['channel_capacity']) == 1442
assert round(results['capacity_kmsq']) == 144
def test_calc_geographic_metrics():
"""
Unit test for calculating geographic metrics including:
- Distance between the transmitter and reciever
- Coverage area for each satellite.
"""
number_of_satellites = 10
params = {
'total_area_earth_km_sq': 100,
'altitude_km': 10,
}
# area_of_earth_covered = total_area_earth_km_sq * portion_of_earth_covered
# network_density = number_of_satellites / area_of_earth_covered
# satellite_coverage_area = (area_of_earth_covered / number_of_satellites) / 1000
# mean_distance_between_assets = math.sqrt((1 / network_density)) / 2
# distance = math.sqrt((mean_distance_between_assets**2) + (altitude_km**2))
# 80 km^2 = 100 * 0.8
# 0.125 satellites km^2 = 10 satellites / 80 km^2
# 8 km^2 satellite coverage area = 80 km^2 / 10 satellites
# 1.41 km on average = math.sqrt((1 / 0.125 km^2 )) / (2)
# 10.1 km = math.sqrt((1.41**2) + (10**2))
distance, satellite_coverage_area = calc_geographic_metrics(
number_of_satellites, params
)
assert round(distance) == 10
assert satellite_coverage_area == 10
def test_calc_free_space_path_loss():
"""
Unit test for calculating the free space path loss.
"""
distance = 10
params = {'speed_of_light': 300000000, 'dl_frequency': 13500000000}
i = 0
random_variations = [1]
result, random_variation = calc_free_space_path_loss(
distance, params, i, random_variations
)
assert round(result) == 136
def test_generate_log_normal_dist_value():
"""
Unit test for generating random values using a lognormal distribution.
"""
assert round(generate_log_normal_dist_value(13.5, 2, 1, 1, 1)[0]) == 1
assert round(generate_log_normal_dist_value(13.5, 2, 1, None, 1)[0]) == 2
def test_antenna_gain():
"""
Unit test for calculating the antenna gain.
"""
c = 3e8 #speed of light m/s
d = 0.7 #Antenna Diameter in metres
f = 13500000000 #Frequency in Hertz
n = 0.6 #Antenna Efficiency
assert round(calc_antenna_gain(c, d, f, n)) == 38
def test_calc_losses():
"""
Unit test for estimating the transmission losses
"""
rain_attenuation = 10
all_other_losses = 0.53
result = calc_losses(rain_attenuation, all_other_losses)
assert result == 10.53
def test_calc_eirp():
"""
Unit test for calculating the Equivalent Isotropically Radiated Power.
"""
power = 30 # watts
antenna_gain = 38 # dB
# losses = 4 #dB
assert round(calc_eirp(power, antenna_gain)) == 68
def test_calc_received_power():
"""
Unit test for calculating received power.
"""
eirp = 68 # dBi
path_loss = 136 # dB
receiver_gain = 37 # dummy values
losses = 10.57
assert round(calc_received_power(eirp, path_loss, receiver_gain, losses)) == -42
def test_calc_noise():
"""
Unit test for calculating receiver noise.
"""
assert round(calc_noise()) == -90
def test_calc_cnr():
"""
Unit test for calculating the Carrier-to-Noise Ratio (CNR).
"""
received_power = -62 # dB
noise = -90 # dB
assert round(calc_cnr(received_power, noise)) == 28
def test_calc_spectral_efficiency(setup_lut):
"""
Unit test for finding the spectral efficiency.
"""
#using actual lut
assert calc_spectral_efficiency(0, setup_lut) == 1.647211 # bits/Hz/s
assert calc_spectral_efficiency(7.5, setup_lut) == 2.193247 # bits/Hz/s
assert calc_spectral_efficiency(10.7, setup_lut) == 2.856231 # bits/Hz/s
assert calc_spectral_efficiency(18.83, setup_lut) == 5.593162 # bits/Hz/s
assert calc_spectral_efficiency(28, setup_lut) == 5.768987 # bits/Hz/s
def test_calc_capacity():
"""
Unit test for calculating the channel capacity.
"""
spectral_efficiency = 1 # bits per Hertz
dl_bandwidth = 1e6 # Hertz
assert calc_capacity(spectral_efficiency, dl_bandwidth) == 1 #mbps
def test_calc_agg_capacity():
"""
Unit test for calculating the aggregate capacity.
"""
channel_capacity = 100
number_of_beams = 1
assert calc_agg_capacity(channel_capacity, number_of_beams) == 100 #mbps