sigmf.sigmffile.fromarray

sigmf.sigmffile.fromarray(data)

Create a SigMFFile from a numpy array.

Convenience function that infers the SigMF datatype from the numpy dtype and creates an in-memory SigMFFile with a single capture at index 0. The returned object can then be written to disk using tofile() or archive(). For full control over captures, annotations, and global fields, use SigMFFile directly.

Parameters:

data (np.ndarray) – Signal samples.

Returns:

The SigMFFile object with in-memory data and metadata.

Return type:

SigMFFile

Examples

>>> import numpy as np
>>> import sigmf, tempfile
>>> from pathlib import Path
>>> data = (np.random.randn(16) + 1j * np.random.randn(16))
>>> meta = sigmf.fromarray(data)
>>> meta.sample_rate = 1e6                                            # set global fields via attribute
>>> meta.add_capture(0, metadata={sigmf.FREQUENCY_KEY: 915e6})       # add capture metadata
>>> meta.add_annotation(0, length=len(data), metadata={sigmf.LABEL_KEY: 'example'})  # add annotation
>>> tmpdir = Path(tempfile.mkdtemp())
>>> meta.tofile(tmpdir / 'recording')        # creates recording.sigmf-meta and recording.sigmf-data
>>> meta.tofile(tmpdir / 'recording.sigmf')  # creates recording.sigmf archive