Skip to content

Commit 7af8b95

Browse files
committed
black
1 parent f38336f commit 7af8b95

17 files changed

+898
-607
lines changed

custom_handlers/iq_custom_handler.py

+15-19
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ def initialize(self, context):
6767
self.max_db = None
6868

6969
def add_to_avg(self, value):
70-
self.avg_db_historical = (self.avg_db_historical * self.avg_size + value) / (self.avg_size + 1)
70+
self.avg_db_historical = (self.avg_db_historical * self.avg_size + value) / (
71+
self.avg_size + 1
72+
)
7173
self.avg_size += 1
7274

73-
74-
7575
def _load_torchscript_model(self, model_pt_path):
7676
"""Loads the PyTorch model and returns the NN model object.
7777
@@ -90,7 +90,7 @@ def _load_torchscript_model(self, model_pt_path):
9090
# model_checkpoint = torch.load(model_pt_path)
9191
# num_classes = len(model_checkpoint["classifier.bias"])
9292
# model = efficientnet_b4(
93-
# num_classes=num_classes
93+
# num_classes=num_classes
9494
# )
9595
# model.load_state_dict(model_checkpoint)
9696

@@ -126,15 +126,15 @@ def handle(self, data, context):
126126
output, _ = self._infer_with_profiler(data=data)
127127
else:
128128
raise RuntimeError(
129-
"Profiler is enabled but current version of torch does not support."
130-
"Install torch>=1.8.1 to use profiler."
129+
"Profiler is enabled but current version of torch does not support."
130+
"Install torch>=1.8.1 to use profiler."
131131
)
132132
else:
133133
if self._is_describe():
134134
output = [self.describe_handle()]
135135
elif self.gate(data):
136136
print(f"\n NO SIGNAL \n")
137-
output = [{"No signal":None}]
137+
output = [{"No signal": None}]
138138
else:
139139
data_preprocess = self.preprocess(data)
140140

@@ -164,13 +164,12 @@ def gate(self, data):
164164

165165
data = torch.tensor(np.frombuffer(body, dtype=np.complex64), dtype=torch.cfloat)
166166

167-
avg_pwr = 10*torch.log10(torch.mean(torch.abs(data)**2))
167+
avg_pwr = 10 * torch.log10(torch.mean(torch.abs(data) ** 2))
168168
if self.max_db is None or self.max_db < avg_pwr:
169169
self.max_db = avg_pwr
170-
170+
171171
self.add_to_avg(avg_pwr)
172172

173-
174173
print("\n=====================================\n")
175174
print("\n=====================================\n")
176175
print(f"\n{data=}\n")
@@ -179,15 +178,11 @@ def gate(self, data):
179178
print("\n=====================================\n")
180179
print("\n=====================================\n")
181180

182-
if avg_pwr > ( self.max_db + self.avg_db_historical)/2:
181+
if avg_pwr > (self.max_db + self.avg_db_historical) / 2:
183182
return False
184183

185184
return True
186185

187-
188-
189-
190-
191186
def preprocess(self, data):
192187
"""
193188
Transform raw input into model input data.
@@ -200,16 +195,15 @@ def preprocess(self, data):
200195
print("could not parse body from request: ", data)
201196
raise ValueError from exc
202197

203-
204198
data = torch.tensor(np.frombuffer(body, dtype=np.complex64), dtype=torch.cfloat)
205199
print("\n=====================================\n")
206200
print(f"\n{data=}\n")
207201
print(f"\n{torch.min(torch.abs(data)**2)=}, {torch.max(torch.abs(data)**2)=}\n")
208-
avg_pwr = torch.mean(torch.abs(data)**2)
202+
avg_pwr = torch.mean(torch.abs(data) ** 2)
209203
avg_pwr_db = 10 * torch.log10(avg_pwr)
210204
print(f"\n{avg_pwr=}\n")
211205
print(f"\n{avg_pwr_db=}\n")
212-
data = data * 1/torch.norm(data, float("inf"), keepdim=True)
206+
data = data * 1 / torch.norm(data, float("inf"), keepdim=True)
213207
data = torch.view_as_real(data)
214208
data = torch.movedim(data, -1, 0).unsqueeze(0)
215209
# data should be of size (N, 2, n_samples)
@@ -237,7 +231,9 @@ def postprocess(self, inference_output):
237231
confidences, class_indexes = torch.max(inference_output.data, 1)
238232
results = {
239233
str(class_index): [{"confidence": confidence}]
240-
for class_index, confidence in zip(class_indexes.tolist(), confidences.tolist())
234+
for class_index, confidence in zip(
235+
class_indexes.tolist(), confidences.tolist()
236+
)
241237
}
242238
print(f"\n{inference_output=}\n{results=}\n")
243239
return [results]

label_scripts/label_bladerf_wifi.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@
2020
for label in s3_data:
2121
for data_glob in s3_data[label]:
2222
for f in tqdm(glob.glob(str(Path(data_glob)))):
23-
annotation_utils.annotate(f, label=label, avg_window_len=256, avg_duration=3, debug=False)
23+
annotation_utils.annotate(
24+
f, label=label, avg_window_len=256, avg_duration=3, debug=False
25+
)

label_scripts/label_env.py

+17-20
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,23 @@
44
from tqdm import tqdm
55
import os
66
import sys
7-
sys.path.insert(1, os.path.join(sys.path[0], '..'))
7+
8+
sys.path.insert(1, os.path.join(sys.path[0], ".."))
89
import rfml.annotation_utils as annotation_utils
910
import rfml.data as data_class
1011

1112

12-
1313
data_globs = {
1414
# "mini2_video": [
1515
# "data/gamutrf/gamutrf-arl/01_30_23/mini2_iq_label/*.sigmf-meta",
1616
# ],
1717
"mini2_video": [
1818
"/home/iqt/lberndt/gamutrf-depoly/data/samples/environment/samples_1722872733.648000_2408703998Hz_20480000sps.raw.sigmf-meta"
19-
#"/home/iqt/lberndt/gamutrf-depoly/data/samples/mavic-0db/samples_1722883251.180000_2408703998Hz_20480000sps.raw.sigmf-meta"
19+
# "/home/iqt/lberndt/gamutrf-depoly/data/samples/mavic-0db/samples_1722883251.180000_2408703998Hz_20480000sps.raw.sigmf-meta"
2020
]
2121
}
2222

2323

24-
2524
for label in data_globs:
2625
for data_glob in data_globs[label]:
2726
for f in tqdm(glob.glob(str(Path(data_glob)))):
@@ -30,20 +29,18 @@
3029
data_obj = data_class.Data(f)
3130
annotation_utils.reset_annotations(data_obj)
3231
annotation_utils.annotate(
33-
f,
34-
label="environment",
35-
avg_window_len=256,
36-
avg_duration=0.10,
37-
debug=False,
38-
estimate_frequency=True,
39-
spectral_energy_threshold=0.90,
40-
#force_threshold_db=-48,
41-
overwrite=True,
42-
min_bandwidth=None,
43-
max_bandwidth=None,
44-
min_annotation_length=1000,
45-
# max_annotations=500,
46-
dc_block=True
32+
f,
33+
label="environment",
34+
avg_window_len=256,
35+
avg_duration=0.10,
36+
debug=False,
37+
estimate_frequency=True,
38+
spectral_energy_threshold=0.90,
39+
# force_threshold_db=-48,
40+
overwrite=True,
41+
min_bandwidth=None,
42+
max_bandwidth=None,
43+
min_annotation_length=1000,
44+
# max_annotations=500,
45+
dc_block=True,
4746
)
48-
49-

label_scripts/label_mavic.py

+28-30
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,22 @@
44
from tqdm import tqdm
55
import os
66
import sys
7-
sys.path.insert(1, os.path.join(sys.path[0], '..'))
7+
8+
sys.path.insert(1, os.path.join(sys.path[0], ".."))
89
import rfml.annotation_utils as annotation_utils
910
import rfml.data as data_class
1011

1112

12-
1313
data_globs = {
1414
"dji_samples": [
1515
"/home/iqt/lberndt/gamutrf-depoly/data/samples/mavic-30gain/samples_1723144831.684000_2408703998Hz_20480000sps.raw.sigmf-meta",
1616
"/home/iqt/lberndt/gamutrf-depoly/data/samples/mavic-40gain/samples_1723144790.020000_2408703998Hz_20480000sps.raw.sigmf-meta",
1717
"/home/iqt/lberndt/gamutrf-depoly/data/samples/mavic-30db/samples_1722867361.666000_2408703998Hz_20480000sps.raw.sigmf-meta",
18-
"/home/iqt/lberndt/gamutrf-depoly/data/samples/mavic-0db/samples_1722883251.180000_2408703998Hz_20480000sps.raw.sigmf-meta"
18+
"/home/iqt/lberndt/gamutrf-depoly/data/samples/mavic-0db/samples_1722883251.180000_2408703998Hz_20480000sps.raw.sigmf-meta",
1919
]
2020
}
2121

2222

23-
2423
for label in data_globs:
2524
for data_glob in data_globs[label]:
2625
for f in tqdm(glob.glob(str(Path(data_glob)))):
@@ -31,34 +30,33 @@
3130
data_obj = data_class.Data(f)
3231
annotation_utils.reset_annotations(data_obj)
3332
# annotation_utils.annotate(
34-
# f,
35-
# label="mavic3_remoteid",
36-
# avg_window_len=256,
37-
# avg_duration=0.10,
38-
# debug=False,
39-
# estimate_frequency=True,
40-
# spectral_energy_threshold=0.90,
41-
# #force_threshold_db=-48,
42-
# overwrite=True,
43-
# min_bandwidth=1e5,
33+
# f,
34+
# label="mavic3_remoteid",
35+
# avg_window_len=256,
36+
# avg_duration=0.10,
37+
# debug=False,
38+
# estimate_frequency=True,
39+
# spectral_energy_threshold=0.90,
40+
# #force_threshold_db=-48,
41+
# overwrite=True,
42+
# min_bandwidth=1e5,
4443
# max_bandwidth=2e6,
45-
# min_annotation_length=500,
46-
# # max_annotations=500,
44+
# min_annotation_length=500,
45+
# # max_annotations=500,
4746
# dc_block=True
4847
# )
4948
annotation_utils.annotate(
50-
f,
51-
label="mavic3_video",
52-
avg_window_len=256,
53-
avg_duration=0.25,
54-
debug=False,
55-
estimate_frequency=True,
56-
spectral_energy_threshold=0.99,
57-
force_threshold_db=-58,
58-
overwrite=True,
59-
min_bandwidth=8e6,
60-
min_annotation_length=10000,
61-
# max_annotations=500,
62-
dc_block=True
49+
f,
50+
label="mavic3_video",
51+
avg_window_len=256,
52+
avg_duration=0.25,
53+
debug=False,
54+
estimate_frequency=True,
55+
spectral_energy_threshold=0.99,
56+
force_threshold_db=-58,
57+
overwrite=True,
58+
min_bandwidth=8e6,
59+
min_annotation_length=10000,
60+
# max_annotations=500,
61+
dc_block=True,
6362
)
64-

label_scripts/label_mini2.py

+26-29
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import rfml.data as data_class
88

99

10-
1110
data_globs = {
1211
# "mini2_video": [
1312
# "data/gamutrf/gamutrf-arl/01_30_23/mini2_iq_label/*.sigmf-meta",
@@ -19,7 +18,6 @@
1918
}
2019

2120

22-
2321
for label in data_globs:
2422
for data_glob in data_globs[label]:
2523
for f in tqdm(glob.glob(str(Path(data_glob)))):
@@ -28,33 +26,32 @@
2826
data_obj = data_class.Data(f)
2927
annotation_utils.reset_annotations(data_obj)
3028
annotation_utils.annotate(
31-
f,
32-
label="mini2_video",
33-
avg_window_len=256,
34-
avg_duration=0.25,
35-
debug=False,
36-
estimate_frequency=True,
37-
spectral_energy_threshold=0.95,
38-
force_threshold_db=-58,
39-
overwrite=False,
40-
min_bandwidth=16e6,
41-
min_annotation_length=10000,
42-
# max_annotations=500,
43-
dc_block=True
29+
f,
30+
label="mini2_video",
31+
avg_window_len=256,
32+
avg_duration=0.25,
33+
debug=False,
34+
estimate_frequency=True,
35+
spectral_energy_threshold=0.95,
36+
force_threshold_db=-58,
37+
overwrite=False,
38+
min_bandwidth=16e6,
39+
min_annotation_length=10000,
40+
# max_annotations=500,
41+
dc_block=True,
4442
)
4543
annotation_utils.annotate(
46-
f,
47-
label="mini2_telem",
48-
avg_window_len=256,
49-
avg_duration=0.25,
50-
debug=False,
51-
estimate_frequency=True,
52-
spectral_energy_threshold=0.95,
53-
force_threshold_db=-58,
54-
overwrite=False,
55-
max_bandwidth=16e6,
56-
min_annotation_length=10000,
57-
# max_annotations=500,
58-
dc_block=True
44+
f,
45+
label="mini2_telem",
46+
avg_window_len=256,
47+
avg_duration=0.25,
48+
debug=False,
49+
estimate_frequency=True,
50+
spectral_energy_threshold=0.95,
51+
force_threshold_db=-58,
52+
overwrite=False,
53+
max_bandwidth=16e6,
54+
min_annotation_length=10000,
55+
# max_annotations=500,
56+
dc_block=True,
5957
)
60-

label_scripts/label_nz_wifi.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@
2020
for label in s3_data:
2121
for data_glob in s3_data[label]:
2222
for f in tqdm(glob.glob(str(Path(data_glob)))):
23-
annotation_utils.annotate(f, label=label, avg_window_len=256, avg_duration=3, debug=False)
23+
annotation_utils.annotate(
24+
f, label=label, avg_window_len=256, avg_duration=3, debug=False
25+
)

0 commit comments

Comments
 (0)