Skip to content

Commit

Permalink
meta.
Browse files Browse the repository at this point in the history
  • Loading branch information
anarkiwi committed Dec 10, 2023
1 parent 0c63339 commit 0f856a9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
3 changes: 2 additions & 1 deletion gamutrf/grsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
53 changes: 25 additions & 28 deletions gamutrf/sample_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,51 +36,48 @@ 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
sample_len = None
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,
Expand All @@ -89,7 +86,7 @@ def parse_filename(filename):
"nfft": nfft,
"timestamp": timestamp,
}
return file_info
return meta


def read_recording(
Expand Down
2 changes: 1 addition & 1 deletion gamutrf/waterfall_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
(
Expand Down

0 comments on commit 0f856a9

Please sign in to comment.