@@ -22,28 +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 ]
32+ annotation_start_idx = annotation[sigmf. SAMPLE_START_KEY ]
33+ annotation_length = annotation[sigmf. SAMPLE_COUNT_KEY ]
3434 annotation_comment = annotation.get(
35- SigMFFile .COMMENT_KEY , " [annotation {} ]" .format(adx)
35+ sigmf .COMMENT_KEY , " [annotation {} ]" .format(adx)
3636 )
3737
3838 # Get capture info associated with the start of annotation
3939 capture = signal.get_capture_info(annotation_start_idx)
40- freq_center = capture.get(SigMFFile .FREQUENCY_KEY , 0 )
40+ freq_center = capture.get(sigmf .FREQUENCY_KEY , 0 )
4141 freq_min = freq_center - 0.5 * sample_rate
4242 freq_max = freq_center + 0.5 * sample_rate
4343
4444 # Get frequency edges of annotation (default to edges of capture)
45- freq_start = annotation.get(SigMFFile. FLO_KEY )
46- freq_stop = annotation.get(SigMFFile. FHI_KEY )
45+ freq_start = annotation.get(sigmf. FREQ_LOWER_EDGE_KEY )
46+ freq_stop = annotation.get(sigmf. FREQ_UPPER_EDGE_KEY )
4747
4848 # Get the samples corresponding to annotation
4949 samples = signal.read_samples(annotation_start_idx, annotation_length)
@@ -74,19 +74,19 @@ First, create a single SigMF Recording and save it to disk:
7474 meta = SigMFFile(
7575 data_file = " example_cf32.sigmf-data" , # extension is optional
7676 global_info = {
77- SigMFFile .DATATYPE_KEY : get_data_type_str(data), # in this case, 'cf32_le'
78- SigMFFile .SAMPLE_RATE_KEY : 48000 ,
79- SigMFFile .AUTHOR_KEY : " jane.doe@domain.org" ,
80- 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." ,
8181 },
8282 )
8383
8484 # create a capture key at time index 0
8585 meta.add_capture(
8686 0 ,
8787 metadata = {
88- SigMFFile .FREQUENCY_KEY : 915000000 ,
89- SigMFFile .DATETIME_KEY : get_sigmf_iso8601_datetime_now(),
88+ sigmf .FREQUENCY_KEY : 915000000 ,
89+ sigmf .DATETIME_KEY : get_sigmf_iso8601_datetime_now(),
9090 },
9191 )
9292
@@ -95,9 +95,9 @@ First, create a single SigMF Recording and save it to disk:
9595 100 ,
9696 200 ,
9797 metadata = {
98- SigMFFile. FLO_KEY : 914995000.0 ,
99- SigMFFile. FHI_KEY : 915005000.0 ,
100- 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" ,
101101 },
102102 )
103103
@@ -120,9 +120,9 @@ Now lets add another SigMF Recording and associate them with a SigMF Collection:
120120 meta_ci16 = SigMFFile(
121121 data_file = " example_ci16.sigmf-data" , # extension is optional
122122 global_info = {
123- SigMFFile .DATATYPE_KEY : " ci16_le" , # get_data_type_str() is only valid for numpy types
124- SigMFFile .SAMPLE_RATE_KEY : 48000 ,
125- 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." ,
126126 },
127127 )
128128 meta_ci16.add_capture(0 , metadata = meta.get_capture_info(0 ))
@@ -155,59 +155,36 @@ The SigMF Collection and its associated Recordings can now be loaded like this:
155155Load a SigMF Archive and slice without untaring
156156-----------------------------------------------
157157
158- Since an *archive * is a tarball (uncompressed by default), and since there are many
159- excellent tools for manipulating tar files, it's fairly straightforward to
160- access the *data * part of a SigMF archive without un-taring it. This is a
161- compelling feature because **1 ** archives make it harder for the ``-data `` and
162- the ``-meta `` to get separated, and **2 ** some datasets are so large that it
163- can be impractical (due to available disk space, or slow network speeds if the
164- archive file resides on a network file share) or simply obnoxious to untar it
165- 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.
166164
167165::
168166
169167 >>> import sigmf
170- >>> arc = sigmf.SigMFArchiveReader ('/src/LTE.sigmf')
171- >>> arc .shape
168+ >>> signal = sigmf.fromarchive ('/src/LTE.sigmf')
169+ >>> signal .shape
172170 (15379532,)
173- >>> arc .ndim
171+ >>> signal .ndim
174172 1
175- >>> arc[:10]
176- array([-20.+11.j, -21. -6.j, -17.-20.j, -13.-52.j, 0.-75.j, 22.-58.j,
177- 48.-44.j, 49.-60.j, 31.-56.j, 23.-47.j], dtype=complex64)
173+ >>> signal[:10]
174+ array([-0.023+0.012j, -0.021-0.006j, -0.017-0.020j, -0.013-0.052j,
175+ 0.000-0.075j, 0.022-0.058j, 0.048-0.044j, 0.049-0.060j,
176+ 0.031-0.056j, 0.023-0.047j], dtype=complex64)
178177
179- The preceeding example exhibits another feature of this approach; the archive
180- ``LTE.sigmf `` is actually ``complex-int16 ``'s on disk, for which there is no
181- corresponding type in ``numpy ``. However, the ``.sigmffile `` member keeps track of
182- this, and converts the data to ``numpy.complex64 `` *after * slicing it, that is,
183- after reading it from disk.
178+ Archives can contain fixed-point data types like ``complex-int16 `` (``ci16 ``),
179+ which have no direct ``numpy `` equivalent. By default, this data is automatically
180+ scaled to floating-point values in the range ``[-1.0, 1.0] `` and returned as
181+ ``numpy.complex64 ``:
184182
185183::
186184
187- >>> arc.sigmffile. get_global_field(sigmf.SigMFFile .DATATYPE_KEY)
185+ >>> signal. get_global_field(sigmf.DATATYPE_KEY)
188186 'ci16_le'
189187
190- >>> arc.sigmffile._memmap.dtype
191- dtype('int16')
192-
193- >>> arc.sigmffile._return_type
194- '<c8'
195-
196- Another supported mode is the case where you might have an archive that *is not
197- on disk * but instead is simply ``bytes `` in a python variable.
198-
199- Instead of needing to write this out to a temporary file before being able to
200- read it, this can be done "in mid air" or "without touching the ground (disk)".
201-
202- ::
203-
204- >>> import sigmf, io
205- >>> sigmf_bytes = io.BytesIO(open('/src/LTE.sigmf', 'rb').read())
206- >>> arc = sigmf.SigMFArchiveReader(archive_buffer=sigmf_bytes)
207- >>> arc[:10]
208- array([-20.+11.j, -21. -6.j, -17.-20.j, -13.-52.j, 0.-75.j, 22.-58.j,
209- 48.-44.j, 49.-60.j, 31.-56.j, 23.-47.j], dtype=complex64)
210-
211188------------------------------
212189Compressed SigMF Archives
213190------------------------------
@@ -248,7 +225,7 @@ The file extension determines the archive format:
248225
249226 >>> signal = sigmf.fromfile('recording.sigmf.xz')
250227 >>> signal[:10]
251- array([-20.+11.j , ...], dtype=complex64)
228+ array([-0.023+0.012j, -0.021-0.006j , ...], dtype=complex64)
252229
253230**Memory behavior: **
254231
0 commit comments