@@ -22,26 +22,28 @@ the recording of the SigMF logo used in this example `from the specification
2222 signal = sigmffile.fromfile(path)
2323
2424 # Get some metadata and all annotations
25- sample_rate = signal.get_global_field(SigMFFile .SAMPLE_RATE_KEY )
25+ sample_rate = signal.get_global_field(sigmf .SAMPLE_RATE_KEY )
2626 sample_count = signal.sample_count
2727 signal_duration = sample_count / sample_rate
2828 annotations = signal.get_annotations()
2929
3030 # Iterate over annotations
3131 for adx, annotation in enumerate (annotations):
32- annotation_start_idx = annotation[SigMFFile.START_INDEX_KEY ]
33- annotation_length = annotation[SigMFFile.LENGTH_INDEX_KEY ]
34- annotation_comment = annotation.get(SigMFFile.COMMENT_KEY , " [annotation {} ]" .format(adx))
32+ annotation_start_idx = annotation[sigmf.SAMPLE_START_KEY ]
33+ annotation_length = annotation[sigmf.SAMPLE_COUNT_KEY ]
34+ annotation_comment = annotation.get(
35+ sigmf.COMMENT_KEY , " [annotation {} ]" .format(adx)
36+ )
3537
3638 # Get capture info associated with the start of annotation
3739 capture = signal.get_capture_info(annotation_start_idx)
38- freq_center = capture.get(SigMFFile .FREQUENCY_KEY , 0 )
40+ freq_center = capture.get(sigmf .FREQUENCY_KEY , 0 )
3941 freq_min = freq_center - 0.5 * sample_rate
4042 freq_max = freq_center + 0.5 * sample_rate
4143
4244 # Get frequency edges of annotation (default to edges of capture)
43- freq_start = annotation.get(SigMFFile .FREQ_LOWER_EDGE_KEY )
44- freq_stop = annotation.get(SigMFFile .FREQ_UPPER_EDGE_KEY )
45+ freq_start = annotation.get(sigmf .FREQ_LOWER_EDGE_KEY )
46+ freq_stop = annotation.get(sigmf .FREQ_UPPER_EDGE_KEY )
4547
4648 # Get the samples corresponding to annotation
4749 samples = signal.read_samples(annotation_start_idx, annotation_length)
@@ -72,19 +74,19 @@ First, create a single SigMF Recording and save it to disk:
7274 meta = SigMFFile(
7375 data_file = " example_cf32.sigmf-data" , # extension is optional
7476 global_info = {
75- SigMFFile .DATATYPE_KEY : get_data_type_str(data), # in this case, 'cf32_le'
76- SigMFFile .SAMPLE_RATE_KEY : 48000 ,
77- SigMFFile .AUTHOR_KEY : " jane.doe@domain.org" ,
78- SigMFFile .DESCRIPTION_KEY : " All zero complex float32 example file." ,
77+ sigmf .DATATYPE_KEY : get_data_type_str(data), # in this case, 'cf32_le'
78+ sigmf .SAMPLE_RATE_KEY : 48000 ,
79+ sigmf .AUTHOR_KEY : " jane.doe@domain.org" ,
80+ sigmf .DESCRIPTION_KEY : " All zero complex float32 example file." ,
7981 },
8082 )
8183
8284 # create a capture key at time index 0
8385 meta.add_capture(
8486 0 ,
8587 metadata = {
86- SigMFFile .FREQUENCY_KEY : 915000000 ,
87- SigMFFile .DATETIME_KEY : get_sigmf_iso8601_datetime_now(),
88+ sigmf .FREQUENCY_KEY : 915000000 ,
89+ sigmf .DATETIME_KEY : get_sigmf_iso8601_datetime_now(),
8890 },
8991 )
9092
@@ -93,9 +95,9 @@ First, create a single SigMF Recording and save it to disk:
9395 100 ,
9496 200 ,
9597 metadata = {
96- SigMFFile. FLO_KEY : 914995000.0 ,
97- SigMFFile. FHI_KEY : 915005000.0 ,
98- SigMFFile .COMMENT_KEY : " example annotation" ,
98+ sigmf. FREQ_LOWER_EDGE_KEY : 914995000.0 ,
99+ sigmf. FREQ_UPPER_EDGE_KEY : 915005000.0 ,
100+ sigmf .COMMENT_KEY : " example annotation" ,
99101 },
100102 )
101103
@@ -118,9 +120,9 @@ Now lets add another SigMF Recording and associate them with a SigMF Collection:
118120 meta_ci16 = SigMFFile(
119121 data_file = " example_ci16.sigmf-data" , # extension is optional
120122 global_info = {
121- SigMFFile .DATATYPE_KEY : " ci16_le" , # get_data_type_str() is only valid for numpy types
122- SigMFFile .SAMPLE_RATE_KEY : 48000 ,
123- SigMFFile .DESCRIPTION_KEY : " All zero complex int16 file." ,
123+ sigmf .DATATYPE_KEY : " ci16_le" , # get_data_type_str() is only valid for numpy types
124+ sigmf .SAMPLE_RATE_KEY : 48000 ,
125+ sigmf .DESCRIPTION_KEY : " All zero complex int16 file." ,
124126 },
125127 )
126128 meta_ci16.add_capture(0 , metadata = meta.get_capture_info(0 ))
@@ -153,59 +155,34 @@ The SigMF Collection and its associated Recordings can now be loaded like this:
153155Load a SigMF Archive and slice without untaring
154156-----------------------------------------------
155157
156- Since an *archive * is a tarball (uncompressed by default), and since there are many
157- excellent tools for manipulating tar files, it's fairly straightforward to
158- access the *data * part of a SigMF archive without un-taring it. This is a
159- compelling feature because **1 ** archives make it harder for the ``-data `` and
160- the ``-meta `` to get separated, and **2 ** some datasets are so large that it
161- can be impractical (due to available disk space, or slow network speeds if the
162- archive file resides on a network file share) or simply obnoxious to untar it
163- first.
158+ Since an *archive * is a tarball (uncompressed by default), you can access the
159+ *data * part of a SigMF archive without un-taring it. This is a compelling
160+ feature because **1 ** archives make it harder for the ``-data `` and the
161+ ``-meta `` to get separated, and **2 ** some datasets are so large that it can be
162+ impractical (due to available disk space, or slow network speeds if the archive
163+ file resides on a network file share) or simply obnoxious to untar it first.
164164
165165::
166166
167167 >>> import sigmf
168- >>> arc = sigmf.SigMFArchiveReader ('/src/LTE.sigmf')
169- >>> arc .shape
168+ >>> signal = sigmf.fromarchive ('/src/LTE.sigmf')
169+ >>> signal .shape
170170 (15379532,)
171- >>> arc .ndim
171+ >>> signal .ndim
172172 1
173- >>> arc [:10]
173+ >>> signal [:10]
174174 array([-20.+11.j, -21. -6.j, -17.-20.j, -13.-52.j, 0.-75.j, 22.-58.j,
175175 48.-44.j, 49.-60.j, 31.-56.j, 23.-47.j], dtype=complex64)
176176
177- The preceeding example exhibits another feature of this approach; the archive
178- ``LTE.sigmf `` is actually ``complex-int16 ``'s on disk, for which there is no
179- corresponding type in ``numpy ``. However, the ``.sigmffile `` member keeps track of
180- this, and converts the data to ``numpy.complex64 `` *after * slicing it, that is,
181- after reading it from disk.
177+ If the archive contains ``complex-int16 `` data on disk (which has no
178+ corresponding ``numpy `` type), the data is automatically converted to
179+ ``numpy.complex64 `` after slicing:
182180
183181::
184182
185- >>> arc.sigmffile. get_global_field(sigmf.SigMFFile .DATATYPE_KEY)
183+ >>> signal. get_global_field(sigmf.DATATYPE_KEY)
186184 'ci16_le'
187185
188- >>> arc.sigmffile._memmap.dtype
189- dtype('int16')
190-
191- >>> arc.sigmffile._return_type
192- '<c8'
193-
194- Another supported mode is the case where you might have an archive that *is not
195- on disk * but instead is simply ``bytes `` in a python variable.
196-
197- Instead of needing to write this out to a temporary file before being able to
198- read it, this can be done "in mid air" or "without touching the ground (disk)".
199-
200- ::
201-
202- >>> import sigmf, io
203- >>> sigmf_bytes = io.BytesIO(open('/src/LTE.sigmf', 'rb').read())
204- >>> arc = sigmf.SigMFArchiveReader(archive_buffer=sigmf_bytes)
205- >>> arc[:10]
206- array([-20.+11.j, -21. -6.j, -17.-20.j, -13.-52.j, 0.-75.j, 22.-58.j,
207- 48.-44.j, 49.-60.j, 31.-56.j, 23.-47.j], dtype=complex64)
208-
209186------------------------------
210187Compressed SigMF Archives
211188------------------------------
0 commit comments