Skip to content

Commit 99065b7

Browse files
authored
Feature: Properties for global fields (#116)
* get & set global fields via properties * created new get/set dynamic interface for global fields * fixed bug where (data_doi, meta_doi) was incorrectly (data-doi, meta_doi) * increment API version * Thanks to @gregparkes for base implementation * add documentation * add tests * remove private method, set only remaining getter to deprecation warning * update documentation
1 parent 4e2f9a7 commit 99065b7

File tree

6 files changed

+284
-65
lines changed

6 files changed

+284
-65
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ htmlcov/*
2222
# docs related
2323
docs/_build/
2424
docs/source/_autosummary/
25+
26+
# dev related
27+
.vscode/

docs/source/quickstart.rst

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ Read a SigMF Recording
2424
2525
import sigmf
2626
handle = sigmf.fromfile("example.sigmf")
27-
handle.read_samples() # returns all timeseries data
27+
# reading data
28+
handle.read_samples() # read all timeseries data
29+
handle[10:50] # read memory slice of samples 10 through 50
30+
# accessing metadata
31+
handle.sample_rate # get sample rate attribute
2832
handle.get_global_info() # returns 'global' dictionary
2933
handle.get_captures() # returns list of 'captures' dictionaries
3034
handle.get_annotations() # returns list of all annotations
31-
handle[10:50] # return memory slice of samples 10 through 50
3235
3336
-----------------------------------
3437
Verify SigMF Integrity & Compliance
@@ -52,16 +55,16 @@ Save a Numpy array as a SigMF Recording
5255
data = np.zeros(1024, dtype=np.complex64)
5356
5457
# write those samples to file in cf32_le
55-
data.tofile('example_cf32.sigmf-data')
58+
data.tofile("example.sigmf-data")
5659
5760
# create the metadata
5861
meta = SigMFFile(
59-
data_file='example_cf32.sigmf-data', # extension is optional
62+
data_file="example.sigmf-data", # extension is optional
6063
global_info = {
61-
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"
6265
SigMFFile.SAMPLE_RATE_KEY: 48000,
63-
SigMFFile.AUTHOR_KEY: 'jane.doe@domain.org',
64-
SigMFFile.DESCRIPTION_KEY: 'All zero complex float32 example file.',
66+
SigMFFile.AUTHOR_KEY: "jane.doe@domain.org",
67+
SigMFFile.DESCRIPTION_KEY: "All zero complex float32 example file.",
6568
}
6669
)
6770
@@ -75,8 +78,40 @@ Save a Numpy array as a SigMF Recording
7578
meta.add_annotation(100, 200, metadata = {
7679
SigMFFile.FLO_KEY: 914995000.0,
7780
SigMFFile.FHI_KEY: 915005000.0,
78-
SigMFFile.COMMENT_KEY: 'example annotation',
81+
SigMFFile.COMMENT_KEY: "example annotation",
7982
})
8083
81-
# check for mistakes & write to disk
82-
meta.tofile('example_cf32.sigmf-meta') # extension is optional
84+
# validate & write to disk
85+
meta.tofile("example.sigmf-meta") # extension is optional
86+
87+
----------------------------------
88+
Attribute Access for Global Fields
89+
----------------------------------
90+
91+
SigMF-Python provides convenient attribute read/write access for core global
92+
metadata fields, allowing you use simple dot notation alongside the traditional
93+
method-based approach.
94+
95+
.. code-block:: python
96+
97+
import sigmf
98+
99+
# read some recording
100+
meta = sigmf.SigMFFile("sigmf_logo")
101+
102+
# read global metadata
103+
print(f"Sample rate: {meta.sample_rate}")
104+
print(f"License: {meta.license}")
105+
106+
# set global metadata
107+
meta.description = "Updated description via attribute access"
108+
meta.author = "jane.doe@domain.org"
109+
110+
# validate & write changes to disk
111+
meta.tofile("sigmf_logo_updated")
112+
113+
.. note::
114+
115+
Only core **global** fields support attribute access. Capture and annotation
116+
fields must still be accessed using the traditional ``get_captures()`` and
117+
``get_annotations()`` methods.

sigmf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# SPDX-License-Identifier: LGPL-3.0-or-later
66

77
# version of this python module
8-
__version__ = "1.2.15"
8+
__version__ = "1.3.0"
99
# matching version of the SigMF specification
1010
__specification__ = "1.2.6"
1111

0 commit comments

Comments
 (0)