From 0f856a99ed78f50442574ae0e2c0913a1a096f21 Mon Sep 17 00:00:00 2001 From: Josh Bailey Date: Sun, 10 Dec 2023 20:50:33 +0000 Subject: [PATCH] meta. --- gamutrf/grsource.py | 3 +- gamutrf/sample_reader.py | 53 +++++++++++++++++------------------- gamutrf/waterfall_samples.py | 2 +- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/gamutrf/grsource.py b/gamutrf/grsource.py index 345af2a9..f1dd4eb2 100644 --- a/gamutrf/grsource.py +++ b/gamutrf/grsource.py @@ -50,7 +50,8 @@ def __init__( in_sig=None, out_sig=[np.complex64], ) - _, self.samples, self.center_freq = get_samples(input_file) + _, self.samples, meta = get_samples(input_file) + self.center_freq = meta["center_frequency"] self.n_samples = len(self.samples) self.i = 0 self.message_port_register_in(pmt.intern(cmd_port)) diff --git a/gamutrf/sample_reader.py b/gamutrf/sample_reader.py index 8ed9c4ad..6aa62445 100644 --- a/gamutrf/sample_reader.py +++ b/gamutrf/sample_reader.py @@ -36,35 +36,32 @@ def default_reader(x): def parse_filename(filename): + timestamp = None + nfft = None + center_frequency = None + sample_rate = None + sample_type = None + # FFT is always float not matter the original sample type. if is_fft(filename): sample_type = "raw" match = FFT_FILENAME_RE.match(filename) - try: - timestamp = int(match.group(1)) - nfft = int(match.group(2)) - freq_center = int(match.group(3)) - sample_rate = int(match.group(4)) - # sample_type = match.group(3) - except AttributeError: - timestamp = None - nfft = None - freq_center = None - sample_rate = None - sample_type = None + if match is not None: + timestamp, nfft, center_frequency, sample_rate = ( + int(match.group(1)), + int(match.group(2)), + int(match.group(3)), + int(match.group(4)), + ) else: match = SAMPLE_FILENAME_RE.match(filename) - nfft = None - try: - timestamp = int(match.group(1)) - freq_center = int(match.group(2)) - sample_rate = int(match.group(3)) - sample_type = match.group(4) - except AttributeError: - timestamp = None - freq_center = None - sample_rate = None - sample_type = None + if match is not None: + timestamp, center_frequency, sample_rate, sample_type = ( + int(match.group(1)), + int(match.group(2)), + int(match.group(3)), + match.group(4), + ) sample_dtype, sample_type = SAMPLE_DTYPES.get(sample_type, (None, None)) sample_bits = None @@ -72,15 +69,15 @@ def parse_filename(filename): if sample_dtype: if is_fft(filename): sample_dtype = np.float32 - sample_bits = 32 - sample_len = 4 + sample_bits = sample_dtype.itemsize * 8 + sample_len = sample_dtype.itemsize else: sample_dtype = np.dtype([("i", sample_dtype), ("q", sample_dtype)]) sample_bits = sample_dtype[0].itemsize * 8 sample_len = sample_dtype[0].itemsize * 2 - file_info = { + meta = { "filename": filename, - "freq_center": freq_center, + "center_frequency": center_frequency, "sample_rate": sample_rate, "sample_dtype": sample_dtype, "sample_len": sample_len, @@ -89,7 +86,7 @@ def parse_filename(filename): "nfft": nfft, "timestamp": timestamp, } - return file_info + return meta def read_recording( diff --git a/gamutrf/waterfall_samples.py b/gamutrf/waterfall_samples.py index 49e2b2ff..9fa013b7 100644 --- a/gamutrf/waterfall_samples.py +++ b/gamutrf/waterfall_samples.py @@ -133,7 +133,7 @@ def main(): f = os.path.join(sample_dir, f) # freq_center, sample_rate, sample_dtype, sample_bytes, sample_type, sample_bits, _, timestamp = parse_filename(f) file_info = parse_filename(f) - freq_center = file_info["freq_center"] + freq_center = file_info["center_frequency"] sample_rate = file_info["sample_rate"] if ( (