Skip to content

Commit bc9492f

Browse files
committed
fromfile improvements, BLUE & WAV NCD conversion
* fromfile() now autodetects SigMF, BLUE, & WAV formats automatically * Converters now support conversion to non-conforming dataset without writing datafiles back to disk * Add utils.get_magic_bytes() for autodetection purposes * split tests for converters into separate files * Validated implementation against lots of files beyond nonsigmf-examples repo * Updated converter documentation * Added slightly more to README * Drop support for float WAV files; tricky to support NCD * Fix bug in sigmffile._count_samples for NCD files * Fig bug in read_samples when using some NCD files with header & trailing bytes
1 parent c70edd7 commit bc9492f

File tree

9 files changed

+833
-255
lines changed

9 files changed

+833
-255
lines changed

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,26 @@ freely under the terms GNU Lesser GPL v3 License.
1212

1313
This module follows the SigMF specification [html](https://sigmf.org/)/[pdf](https://sigmf.github.io/SigMF/sigmf-spec.pdf) from the [spec repository](https://github.com/sigmf/SigMF).
1414

15-
To install the latest PyPI release, install from pip:
15+
### Install Latest
1616

1717
```bash
1818
pip install sigmf
1919
```
2020

21-
**[Please visit the documentation for examples & more info.](https://sigmf.readthedocs.io/en/latest/)**
21+
### Read SigMF
22+
23+
```python
24+
import sigmf
25+
26+
# read SigMF recording
27+
meta = sigmf.fromfile("recording.sigmf-meta")
28+
samples = meta[0:1024] # get first 1024 samples
29+
30+
# fromfile() also supports BLUE and WAV files via auto-detection
31+
meta = sigmf.fromfile("recording.cdif") # BLUE file
32+
meta = sigmf.fromfile("recording.wav") # WAV file
33+
```
34+
35+
### Full API & Docs
36+
37+
**[Please visit our documentation for more info.](https://sigmf.readthedocs.io/en/latest/)**

docs/source/converters.rst

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Format Converters
33
=================
44

55
The SigMF Python library includes converters to import data from various file formats into SigMF format.
6-
These converters make it easy to migrate existing RF recordings to the standardized SigMF format while preserving metadata when possible.
6+
Converters can create standard SigMF file pairs or Non-Conforming Datasets (NCDs) that reference the original files.
77

88
Overview
99
--------
@@ -13,35 +13,52 @@ Converters are available for:
1313
* **BLUE files** - MIDAS Blue and Platinum BLUE RF recordings (``.cdif``)
1414
* **WAV files** - Audio recordings (``.wav``)
1515

16-
All converters return a :class:`~sigmf.SigMFFile` object that can be used immediately or saved to disk.
17-
Converters preserve datatypes and metadata where possible.
16+
All converters return a :class:`~sigmf.SigMFFile` object. Auto-detection is available through :func:`~sigmf.sigmffile.fromfile`.
17+
18+
19+
Auto-Detection
20+
~~~~~~~~~~~~~~
21+
22+
The :func:`~sigmf.sigmffile.fromfile` function automatically detects file formats and creates Non-Conforming Datasets:
23+
24+
.. code-block:: python
25+
26+
import sigmf
27+
28+
# auto-detect and create NCD for any supported format
29+
meta = sigmf.fromfile("recording.cdif") # BLUE file
30+
meta = sigmf.fromfile("recording.wav") # WAV file
31+
meta = sigmf.fromfile("recording.sigmf") # SigMF archive
32+
33+
samples = meta.read_samples()
1834
1935
2036
Command Line Usage
2137
~~~~~~~~~~~~~~~~~~
2238

23-
Converters can be used from the command line after ``pip install sigmf``:
39+
Converters can be used from the command line:
2440

2541
.. code-block:: bash
2642
2743
sigmf_convert_blue recording.cdif
2844
sigmf_convert_wav recording.wav
2945
30-
or by using module syntax:
46+
or by using module execution:
3147

3248
.. code-block:: bash
3349
34-
python3 -m sigmf.convert.blue recording.cdif
35-
python3 -m sigmf.convert.wav recording.wav
50+
python -m sigmf.convert.blue recording.cdif
51+
python -m sigmf.convert.wav recording.wav
52+
3653
54+
Output Options
55+
~~~~~~~~~~~~~~
3756

38-
Output Naming
39-
~~~~~~~~~~~~~
57+
Converters support multiple output modes:
4058

41-
All converters treat the value passed with ``-o/--output`` as a base name and ignore any existing suffix. The tools
42-
emit ``<base>.sigmf-data`` and ``<base>.sigmf-meta`` files (retaining any original extensions such as ``.cdif`` or
43-
``.tmp`` in the base). Supplying ``--archive`` packages the result as ``<base>.sigmf`` instead of producing separate
44-
meta/data files.
59+
* **Standard conversion**: Creates ``.sigmf-data`` and ``.sigmf-meta`` files
60+
* **Archive mode**: Creates single ``.sigmf`` archive with ``--archive``
61+
* **Non-Conforming Dataset**: Creates metadata-only file referencing original data with ``--ncd``
4562

4663

4764
BLUE Converter
@@ -56,38 +73,42 @@ The BLUE converter handles CDIF (.cdif) recordings while placing BLUE header inf
5673

5774
.. autofunction:: sigmf.convert.blue.blue_to_sigmf
5875

59-
6076
.. code-block:: python
6177
6278
from sigmf.convert.blue import blue_to_sigmf
6379
64-
# read BLUE, write SigMF, and return SigMFFile object
65-
meta = blue_to_sigmf(blue_path="recording.cdif", out_path="recording.sigmf")
80+
# standard conversion
81+
meta = blue_to_sigmf(blue_path="recording.cdif", out_path="recording")
6682
67-
# access converted data
68-
samples = meta.read_samples()
83+
# create NCD automatically (metadata-only, references original file)
84+
meta = blue_to_sigmf(blue_path="recording.cdif")
85+
86+
# access standard SigMF data & metadata
87+
all_samples = meta.read_samples()
6988
sample_rate_hz = meta.sample_rate
7089
7190
# access BLUE-specific metadata
72-
blue_type = meta.get_global_field("blue:fixed")["type"] # e.g., 1000
73-
blue_version = meta.get_global_field("blue:keywords")["IO"] # e.g., "X-Midas"
91+
blue_type = meta.get_global_field("blue:fixed")["type"] # e.g., 1000
92+
blue_version = meta.get_global_field("blue:keywords")["IO"] # e.g., "X-Midas"
7493
7594
7695
WAV Converter
7796
-------------
7897

79-
This is useful when working with audio datasets.
98+
Converts WAV audio recordings to SigMF format.
8099

81100
.. autofunction:: sigmf.convert.wav.wav_to_sigmf
82101

83-
84102
.. code-block:: python
85103
86104
from sigmf.convert.wav import wav_to_sigmf
87105
88-
# read WAV, write SigMF, and return SigMFFile object
89-
meta = wav_to_sigmf(wav_path="recording.wav", out_path="recording.sigmf")
106+
# standard conversion
107+
meta = wav_to_sigmf(wav_path="recording.wav", out_path="recording")
90108
91-
# access converted data
92-
samples = meta.read_samples()
109+
# create NCD automatically (metadata-only, references original file)
110+
meta = wav_to_sigmf(wav_path="recording.wav")
111+
112+
# access standard SigMF data & metadata
113+
all_samples = meta.read_samples()
93114
sample_rate_hz = meta.sample_rate

0 commit comments

Comments
 (0)