Skip to content

Commit

Permalink
Merge pull request #1032 from anarkiwi/off
Browse files Browse the repository at this point in the history
More offline features.
  • Loading branch information
anarkiwi authored Dec 11, 2023
2 parents 30ad3cd + 0b35ebf commit 8ea40bc
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 21 deletions.
116 changes: 99 additions & 17 deletions gamutrf/offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,44 @@ def argument_parser():
action=BooleanOptionalAction,
help="use VkFFT",
)
parser.add_argument(
"--scaling",
dest="scaling",
type=str,
default="spectrum",
help="""Same as --scaling parameter in scipy.signal.spectrogram().
Selects between computing the power spectral density ('density')
where `Sxx` has units of V**2/Hz and computing the power
spectrum ('spectrum') where `Sxx` has units of V**2, if `x`
is measured in V and `fs` is measured in Hz. Defaults to
'spectrum'.""",
)
parser.add_argument(
"--fft_batch_size",
dest="fft_batch_size",
type=int,
default=256,
help="offload FFT batch size",
)
parser.add_argument(
"--tuneoverlap",
dest="tuneoverlap",
type=float,
default=0.85,
help="multiple of samp_rate when retuning",
)
parser.add_argument(
"--bucket_range",
dest="bucket_range",
type=float,
default=0.85,
help="what proportion of FFT buckets to use",
)
parser.add_argument(
"--db_clamp_floor",
dest="db_clamp_floor",
type=float,
default=-150,
default=-200,
help="clamp dB output floor",
)
parser.add_argument(
Expand All @@ -41,6 +74,19 @@ def argument_parser():
default=50,
help="clamp dB output ceil",
)
parser.add_argument(
"--dc_block_len",
dest="dc_block_len",
type=int,
default=0,
help="if > 0, use dc_block_cc filter with length",
)
parser.add_argument(
"--dc_block_long",
dest="dc_block_long",
action="store_true",
help="Use dc_block_cc long form",
)
parser.add_argument(
"--nfft",
dest="nfft",
Expand All @@ -55,6 +101,41 @@ def argument_parser():
default=10,
help="if > 1, only log 1/n images",
)
parser.add_argument(
"--inference_min_db",
dest="inference_min_db",
type=float,
default=-150,
help="run inference over minimum dB power",
)
parser.add_argument(
"--inference_model_server",
dest="inference_model_server",
type=str,
default="",
help="torchserve model server inference API address (e.g. localhost:1234)",
)
parser.add_argument(
"--inference_model_name",
dest="inference_model_name",
type=str,
default="",
help="torchserve model name (e.g. yolov8)",
)
parser.add_argument(
"--logaddr",
dest="logaddr",
type=str,
default="0.0.0.0", # nosec
help="Log FFT results to this address",
)
parser.add_argument(
"--logport",
dest="logport",
type=int,
default=8001,
help="Log FFT results to this port",
)
return parser


Expand All @@ -65,23 +146,24 @@ def main():
out_dir = os.path.dirname(filename)
_data_filename, _samples, meta = get_samples(filename)
freq_start = int(meta["center_frequency"] - (meta["sample_rate"] / 2))
tb = grscan(
db_clamp_floor=-1e9,
fft_batch_size=256,
freq_end=0,
freq_start=freq_start,
inference_min_db=-1e9,
inference_output_dir=out_dir,
iqtlabs=iqtlabs,
n_image=options.n_image,
nfft=options.nfft,
pretune=True,
samp_rate=int(meta["sample_rate"]),
sample_dir=out_dir,
sdr="file:" + filename,
tune_step_fft=options.tune_step_fft,
vkfft=options.vkfft,
scan_args = {
"iqtlabs": iqtlabs,
"freq_end": 0,
"freq_start": freq_start,
"inference_output_dir": out_dir,
"pretune": True,
"samp_rate": int(meta["sample_rate"]),
"sample_dir": out_dir,
"sdr": "file:" + filename,
}
scan_args.update(
{
k: getattr(options, k)
for k in dir(options)
if not k.startswith("_") and k != "filename"
}
)
tb = grscan(**scan_args)
tb.start()
while not tb.sources[0].complete():
time.sleep(1)
Expand Down
33 changes: 29 additions & 4 deletions tests/test_grscan.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/python3
import glob
import os
import subprocess
import tempfile
import time
import unittest
Expand Down Expand Up @@ -101,11 +103,33 @@ def test_get_source_smoke(self):
for sdr in ("ettus", "bladerf"):
self.assertRaises(RuntimeError, get_source, sdr, 1e3, 10)

def run_grscan_smoke(self, pretune, wavelearner, write_samples):
def run_grscan_smoke(self, pretune, wavelearner, write_samples, test_file):
with tempfile.TemporaryDirectory() as tempdir:
freq_start = 1e9
freq_end = 2e9
samp_rate = int(1.024e6)
sdr = "tuneable_test_source"
if test_file:
freq_end = 0
sdr_file = os.path.join(
tempdir,
f"gamutrf_recording1_{int(freq_start)}Hz_{int(samp_rate)}sps.raw",
)
subprocess.check_call(
[
"dd",
"if=/dev/urandom",
f"of={sdr_file}",
f"bs={samp_rate}",
"count=10",
]
)
sdr = "file:" + sdr_file
tb = grscan(
sdr="tuneable_test_source",
samp_rate=int(1.024e6),
freq_start=freq_start,
freq_end=freq_end,
sdr=sdr,
samp_rate=samp_rate,
write_samples=write_samples,
sample_dir=tempdir,
iqtlabs=iqtlabs,
Expand All @@ -128,9 +152,10 @@ def run_grscan_smoke(self, pretune, wavelearner, write_samples):

def test_grscan_smoke(self):
for pretune in (True, False):
self.run_grscan_smoke(pretune, False, True, True)
for wavelearner in (FakeWaveLearner(), None):
for write_samples in (0, 1):
self.run_grscan_smoke(pretune, wavelearner, write_samples)
self.run_grscan_smoke(pretune, wavelearner, write_samples, False)


if __name__ == "__main__": # pragma: no cover
Expand Down

0 comments on commit 8ea40bc

Please sign in to comment.