Render sample_spectrogram for split-I/Q RadioDataset samples #36

Merged
benchinnery merged 1 commits from fix-spectrogram-split-iq into main 2026-07-14 13:54:10 -04:00

1 Commits

Author SHA1 Message Date
ben
3d58760b5e fix(viz): render sample_spectrogram for split-I/Q RadioDataset samples
All checks were successful
Build Sphinx Docs Set / Build Docs (pull_request) Successful in 1m5s
Build Project / Build Project (3.10) (pull_request) Successful in 3m3s
Build Project / Build Project (3.11) (pull_request) Successful in 2m27s
Build Project / Build Project (3.12) (pull_request) Successful in 1m20s
Test with tox / Test with tox (3.11) (pull_request) Successful in 2m57s
Test with tox / Test with tox (3.10) (pull_request) Successful in 4m3s
Test with tox / Test with tox (3.12) (pull_request) Successful in 1m27s
RadioDataset samples are commonly split I/Q with shape (2, T) (row 0 = I,
row 1 = Q). `sample_spectrogram_plot` assumed 1-D complex, so `len(sample)`
returned 2 (the I/Q axis) — the compatibility gate saw `2 < 32` and every
dataset showed "doesn't have sufficient signal data for spectrogram
visualization", and the fallback path raised "need at least 32 samples, got 2".

Normalize each sample to a 1-D complex signal before measuring/plotting:
- add `_to_complex_1d` (complex any-shape -> flat; (2, ...) I/Q rows and
  (..., 2) I/Q cols -> I + jQ; real 1-D -> real signal; None on empty).
- compatibility gate and `sample_spectrogram_plot` normalize first, then use
  the true length; plot returns the styled "Not Available" figure for
  unusable/too-short (<32) samples.
- `_compute_spectrogram` measures length via reshape(-1) (belt-and-suspenders).

Tests: parametrized `_to_complex_1d` and `sample_spectrogram_plot` over
complex 1-D, (2, T) rows, (T, 2) cols, real 1-D, and (2, 4, 256) multi-channel
I/Q (all render), plus (2,)/empty (still "Not Available"). 16 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-14 12:11:27 -04:00