@@ -55,16 +55,16 @@ Save a Numpy array as a SigMF Recording
5555 data = np.zeros(1024 , dtype = np.complex64)
5656
5757 # write those samples to file in cf32_le
58- data.tofile(' example_cf32 .sigmf-data' )
58+ data.tofile(" example .sigmf-data" )
5959
6060 # create the metadata
6161 meta = SigMFFile(
62- data_file = ' example_cf32 .sigmf-data' , # extension is optional
62+ data_file = " example .sigmf-data" , # extension is optional
6363 global_info = {
64- SigMFFile.DATATYPE_KEY : get_data_type_str(data), # in this case, ' cf32_le'
64+ SigMFFile.DATATYPE_KEY : get_data_type_str(data), # in this case, " cf32_le"
6565 SigMFFile.SAMPLE_RATE_KEY : 48000 ,
66- SigMFFile.AUTHOR_KEY : ' [email protected] ' , 67- SigMFFile.DESCRIPTION_KEY : ' All zero complex float32 example file.' ,
66+ SigMFFile.AUTHOR_KEY : " [email protected] " , 67+ SigMFFile.DESCRIPTION_KEY : " All zero complex float32 example file." ,
6868 }
6969 )
7070
@@ -78,52 +78,40 @@ Save a Numpy array as a SigMF Recording
7878 meta.add_annotation(100 , 200 , metadata = {
7979 SigMFFile.FLO_KEY : 914995000.0 ,
8080 SigMFFile.FHI_KEY : 915005000.0 ,
81- SigMFFile.COMMENT_KEY : ' example annotation' ,
81+ SigMFFile.COMMENT_KEY : " example annotation" ,
8282 })
8383
84- # check for mistakes & write to disk
85- meta.tofile(' example_cf32 .sigmf-meta' ) # extension is optional
84+ # validate & write to disk
85+ meta.tofile(" example .sigmf-meta" ) # extension is optional
8686
8787----------------------------------
8888Attribute Access for Global Fields
8989----------------------------------
9090
91- SigMF-Python provides convenient attribute-style access for core global metadata fields,
92- allowing you to read and write metadata using simple dot notation alongside the traditional
91+ SigMF-Python provides convenient attribute read/write access for core global
92+ metadata fields, allowing you use simple dot notation alongside the traditional
9393method-based approach.
9494
9595.. code-block :: python
9696
97- import numpy as np
98- from sigmf import SigMFFile
99-
100- # create a new recording
101- meta = SigMFFile()
97+ import sigmf
10298
103- # set global metadata using attributes
104- meta.sample_rate = 48000
105- 106- meta.datatype = ' cf32_le'
107- meta.description = ' Example recording with attribute access'
108- meta.license = ' MIT'
109- meta.recorder = ' hackrf_one'
99+ # read some recording
100+ meta = sigmf.SigMFFile(" sigmf_logo" )
110101
111- # read global metadata using attributes
102+ # read global metadata
112103 print (f " Sample rate: { meta.sample_rate} " )
113- print (f " Author: { meta.author} " )
114104 print (f " License: { meta.license} " )
115105
116- # method-based approach
117- meta.set_global_field(SigMFFile.HW_KEY , ' SDR Hardware v1.2' )
118- hw_info = meta.get_global_field(SigMFFile.HW_KEY )
119- print (f " Hardware: { hw_info} " )
106+ # set global metadata
107+ meta.description = " Updated description via attribute access"
108+ 120109
121- # attribute and method access are equivalent
122- meta.set_global_field(SigMFFile.RECORDER_KEY , ' usrp_b210' )
123- print (f " Recorder via attribute: { meta.recorder} " ) # prints: usrp_b210
110+ # validate & write changes to disk
111+ meta.tofile(" sigmf_logo_updated" )
124112
125113 .. note ::
126114
127115 Only core **global ** fields support attribute access. Capture and annotation
128- fields must still be accessed using the traditional ``add_capture () `` and
129- ``add_annotation () `` methods.
116+ fields must still be accessed using the traditional ``get_captures () `` and
117+ ``get_annotations () `` methods.
0 commit comments