-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathautomated_frequency_selection.py
More file actions
90 lines (75 loc) · 2.28 KB
/
automated_frequency_selection.py
File metadata and controls
90 lines (75 loc) · 2.28 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
import copy
import requests
import urllib3
import numpy as np
# Compare a pool of frequencies to recommend the best one for a link
FREQUENCIES = [600, 1220, 2222]
CLOUDRF_API = "https://api.cloudrf.com"
CLOUDRF_API_KEY = ""
REQUEST_VERIFY_SSL = True
TEMPLATE = {
"network": "FreqSelection",
"transmitter": {
"lat": 51.833420,
"lon": -2.233008,
"alt": 10,
"txw": 10,
"bwi": 1,
},
"antenna": {
"txg": 2.15,
"ant": 1,
},
"receiver": {
"lat": 51.879889,
"lon": -2.264917,
"alt": 2,
"rxs": 10,
},
"model": {
"pm": 10,
"pe": 2,
"ked": 4,
"rel": 50,
},
"environment": {
"clt": "Minimal.clt",
"elevation": 2,
"landcover": 1,
"buildings": 1,
"obstacles": 1,
},
"output": {
"out": 4,
"nf": "database",
"res": 30,
},
}
if __name__ == "__main__":
if not REQUEST_VERIFY_SSL:
urllib3.disable_warnings()
results = []
for freq in FREQUENCIES:
request = copy.deepcopy(TEMPLATE)
request["transmitter"]["frq"] = freq
request["site"] = f"Freq_{freq}"
response = requests.post(
f"{CLOUDRF_API}/path",
json=request,
headers={"key": CLOUDRF_API_KEY},
verify=REQUEST_VERIFY_SSL,
).json()
received_power = np.array(response["Transmitters"][0]["dBm"])
noise_floor = np.array(response["Transmitters"][0]["Noise_dBm"])
channel_noise = response["Transmitters"][0]["Johnson Nyquist noise dB"]
snr = received_power - noise_floor - channel_noise
count_above_threshold = (snr > TEMPLATE["receiver"]["rxs"]).sum()
results.append([freq, 100.0 * count_above_threshold / len(received_power)])
freq_title = "Frequency (MHz)"
percent_title = "Percentage above threshold (%)"
print(f"|-{'-' * len(freq_title)}-|-{'-' * len(percent_title )}-|")
print(f"| {freq_title} | {percent_title} |")
print(f"|-{'-' * len(freq_title)}-|-{'-' * len(percent_title )}-|")
for freq, percent in results:
print(f"| {freq:{len(freq_title)}.2f} | {percent:{len(percent_title)}.2f} |")
print(f"|-{'-' * len(freq_title)}-|-{'-' * len(percent_title )}-|")