Skip to content

Commit 0681e79

Browse files
committed
remove debug, fix cf32 typo
1 parent 0d2d134 commit 0681e79

2 files changed

Lines changed: 16 additions & 36 deletions

File tree

sigmf/convert/blue.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def detect_endian(data):
145145
elif endianness == "IEEE":
146146
return ">"
147147
else:
148-
raise SigMFConversionError(f"Unexpected endianness: {endianness}")
148+
raise SigMFConversionError(f"Unsupported endianness: {endianness}")
149149

150150

151151
def read_hcb(file_path):
@@ -313,7 +313,7 @@ def read_extended_header(file_path, h_fixed):
313313
return entries
314314

315315

316-
def data_loopback(blue_path: Path, out_path: Path, h_fixed: dict) -> np.ndarray:
316+
def data_loopback(blue_path: Path, out_path: Path, h_fixed: dict) -> None:
317317
"""
318318
Write SigMF data file from BLUE file samples.
319319
@@ -356,41 +356,26 @@ def data_loopback(blue_path: Path, out_path: Path, h_fixed: dict) -> np.ndarray:
356356

357357
# Determine destination path for SigMF data file
358358
dest_path = out_path.with_suffix(".sigmf-data")
359-
print("#" * 80)
360-
print("Writing SigMF data to:", dest_path)
361-
print("#" * 80)
362359

363360
# read raw samples
364361
raw_samples = np.fromfile(blue_path, dtype=np_dtype, offset=HEADER_SIZE_BYTES, count=elem_count)
365362

366363
if is_complex:
367-
# complex data: already in IQIQIQ... format or native complex
368-
if np_dtype == np.complex64:
364+
# check if data is already complex or needs deinterleaving
365+
if np.iscomplexobj(raw_samples):
369366
# already complex, no reassembly needed
370367
samples = raw_samples
371368
else:
372369
# reassemble interleaved IQ samples
373370
samples = raw_samples[::2] + 1j * raw_samples[1::2]
374-
log.debug(f"Deinterleaved {len(raw_samples)} samples into {len(samples)} complex samples")
375371
else:
376372
# scalar data
377373
samples = raw_samples
378374

379-
# print('dbug', samples.dtype, len(samples), get_normalization_factor(fmt))
380-
381-
# normalize if needed
382-
# if should_normalize:
383-
# norm_factor = get_normalization_factor(fmt)
384-
# if norm_factor:
385-
# samples /= norm_factor
386-
387375
# save out as SigMF IQ data file
388376
samples.tofile(dest_path)
389377
log.info("wrote %s", dest_path)
390378

391-
# return the IQ data if needed for further processing if needed
392-
return samples
393-
394379

395380
def construct_sigmf(
396381
out_path: Path, h_fixed: dict, h_keywords: dict, h_adjunct: dict, h_extended: list, is_metadata_only: bool = False
@@ -627,7 +612,7 @@ def blue_to_sigmf(
627612
implement a function that instead writes metadata only for a non-conforming
628613
dataset using the HEADER_BYTES_KEY and TRAILING_BYTES_KEY in most cases.
629614
"""
630-
log.debug(f"convert {blue_path}")
615+
log.debug(f"read {blue_path}")
631616

632617
blue_path = Path(blue_path)
633618
if out_path is None:
@@ -650,7 +635,7 @@ def blue_to_sigmf(
650635

651636
# write to SigMF data file only if samples exist
652637
if not is_metadata_only:
653-
_ = data_loopback(blue_path, out_path, h_fixed)
638+
data_loopback(blue_path, out_path, h_fixed)
654639
else:
655640
log.info("skipping data file creation for zero-sample BLUE file")
656641

tests/test_convert.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,20 @@ def test_blue_to_sigmf(self):
9191
# # plot stft of RF data for visual inspection
9292
# import matplotlib.pyplot as plt
9393
# from scipy.signal import spectrogram
94-
# from swiftfox import summary
94+
# from swiftfox import summary, smartspec
9595

96+
# if meta.get_global_field("core:metadata_only"):
97+
# print("Metadata only file, skipping plot.")
98+
# continue
9699
# samples = meta.read_samples()
97-
# plt.figure(figsize=(10, 10))
98-
# summary(samples, detail=0.1, samp_rate=meta.get_global_field("core:sample_rate"))
100+
# # plt.figure(figsize=(10, 10))
101+
# summary(samples, detail=0.1, samp_rate=meta.get_global_field("core:sample_rate"), title=sigmf_path.name)
99102
# plt.figure()
100-
# plt.plot(samples.real)
101-
# plt.plot(samples.imag)
102-
103-
# freqs, times, spec = spectrogram(samples, fs=meta.get_global_field("core:sample_rate"), nperseg=1024)
103+
# # plt.plot(samples.real)
104+
# # plt.plot(samples.imag)
105+
# # plt.figure()
106+
# spec = smartspec(samples, detail=0.5, samp_rate=meta.get_global_field("core:sample_rate"))
104107
# # use imshow to plot spectrogram
105108

106-
# plt.figure()
107-
# plt.imshow(
108-
# 10 * np.log10(spec), aspect="auto", extent=[times[0], times[-1], freqs[0], freqs[-1]], origin="lower"
109-
# )
110-
# plt.colorbar(label="Intensity [dB]")
111-
# plt.ylabel("Frequency [Hz]")
112-
# plt.xlabel("Time [s]")
113-
# plt.title(f"Spectrogram of {bluefile.name}")
114109
# plt.show()
115110
self.assertIsInstance(meta, sigmf.SigMFFile)

0 commit comments

Comments
 (0)