Skip to content

feat: add SigMFReader for .sigmf-data/.sigmf-meta file pairs (closes #282)#463

Open
easton-ring wants to merge 7 commits into
TorchDSP:mainfrom
techring-live:feat/sigmf-reader
Open

feat: add SigMFReader for .sigmf-data/.sigmf-meta file pairs (closes #282)#463
easton-ring wants to merge 7 commits into
TorchDSP:mainfrom
techring-live:feat/sigmf-reader

Conversation

@easton-ring
Copy link
Copy Markdown

Summary

Adds SigMFReader(FileReader) and SigMFFileHandler(BaseFileHandler) to torchsig.utils.file_handlers, enabling users to load .sigmf-data + .sigmf-meta file pairs as TorchSig datasets via StaticTorchSigDataset.

Closes #282.

What's new

  • torchsig/utils/file_handlers/sigmf.py — new SigMFReader + SigMFFileHandler
    • Supports 9 SigMF datatypes: cf32_le/be, cf64_le, ci32_le/be, ci16_le/be, ci8, cu8
    • Output always np.complex64
    • No import sigmf dependency — JSON parsed directly (avoids >2 GB memmap limitation)
    • Handles both .sigmf-meta and .sigmf-data.sigmf-meta naming conventions
    • Multi-channel (core:num_channels > 1) raises NotImplementedError with a clear message
  • torchsig/utils/file_handlers/__init__.pySigMFReader, SigMFFileHandler added to exports
  • tests/utils/test_sigmf_reader.py — 25 tests covering dtype handling, indexing, metadata mapping, StaticTorchSigDataset integration, and SigMFFileHandler
  • examples/bring_your_own_data_sigmf_example.ipynb — updated to use the new SigMFReader import; inline class definition removed; multi-file usage cell added

Usage

from torchsig.datasets.static_dataset import StaticTorchSigDataset
from torchsig.utils.file_handlers import SigMFReader

dataset = StaticTorchSigDataset(
    root="./my_captures/",
    file_handler_class=SigMFReader,
    target_labels=["class_name"],
)
data, label = dataset[0]   # → (np.ndarray shape (N,) complex64, "elrs")

Test plan

  • pytest tests/utils/test_sigmf_reader.py -v — 25 tests pass, 0 failures
  • pytest tests/ -x -q — full suite passes, 0 regressions
  • pylint --rcfile=.pylintrc torchsig/utils/file_handlers/sigmf.py tests/utils/test_sigmf_reader.py — both score 10.00/10
  • Notebook executes top-to-bottom twice without errors (idempotent)
  • python -c "import torchsig; print(torchsig.__version__)"2.1.2
  • No import sigmf anywhere in torchsig/utils/file_handlers/sigmf.py

easton-ring and others added 6 commits April 18, 2026 17:40
Implements FileReader subclass that loads SigMF file pairs as TorchSig
datasets without requiring the sigmf library. Supports cf32, cf64, ci32,
ci16, ci8, cu8 datatypes. Handles multi-file roots (annotations from all
.sigmf-data files are concatenated in sorted order).

Closes TorchDSP#282.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Fix _find_meta_for_data candidate_a path for foo.sigmf-meta convention
- Sanitize colon-keyed annotation fields (lora:x → lora_x) for attribute access
- Raise ValueError on sample_count=0 instead of returning empty Signal
- Replace unreachable class_index=-1 fallback with assert
- Set writer_class=None (never reachable; create_handler raises for write mode)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
23 tests covering:
- Dtype roundtrips (cf32_le, ci16_le/be, ci8, cu8)
- Byte offset indexing (single and multi-file)
- Metadata mapping (sample_rate, center_freq, class_name/index, custom fields)
- Both .sigmf-meta naming conventions
- StaticTorchSigDataset integration
- Error cases (no files, bad dtype, sample_count=0, write mode)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…gMFReader

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…le_handlers

Remove the inline BYODExampleFileHandler class definition; import and use
the new SigMFReader directly. Add a multi-file demo cell showing two .sigmf
pairs in one root with annotation counts verified via assert.
Add overwrite=True to both meta.tofile() calls so re-execution does not
raise SigMFFileExistsError. Move kernelspec from top-level notebook JSON
into metadata where nbformat schema expects it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ereoh
Copy link
Copy Markdown
Collaborator

ereoh commented May 13, 2026

This code looks really useful, so thank you. If you could resolve the merge conflicts I can merge it into main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] File Format Support

2 participants