Skip to content

Commit 7c979a4

Browse files
messybearTeque5
authored andcommitted
Fix annotation core:sample_count requirement
According to spec, core:sample_count for annotation is optional
1 parent 6b14f62 commit 7c979a4

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

sigmf/schema-meta.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@
238238
"$id": "#/properties/annotations/items/anyOf/0",
239239
"description": "The annotations value is an array of annotation segment objects that describe anything regarding the signal data not part of the Captures and Global objects. It MUST be sorted by the value of each Annotation Segment's `core:sample_start` key, ascending.",
240240
"required": [
241-
"core:sample_start",
242-
"core:sample_count"
241+
"core:sample_start"
243242
],
244243
"type": "object",
245244
"properties": {

sigmf/sigmffile.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,17 @@ def get_capture_byte_boundarys(self, index):
368368
end_byte += (self.get_capture_start(index+1) - self.get_capture_start(index)) * self.get_sample_size() * self.get_num_channels()
369369
return (start_byte, end_byte)
370370

371-
def add_annotation(self, start_index, length, metadata=None):
371+
def add_annotation(self, start_index, length=None, metadata=None):
372372
"""
373-
Insert annotation at start_index with length.
373+
Insert annotation at start_index with length (if != None).
374374
"""
375375
assert start_index >= self._get_start_offset()
376-
assert length >= 1
376+
377377
new_annot = metadata or {}
378378
new_annot[self.START_INDEX_KEY] = start_index
379-
new_annot[self.LENGTH_INDEX_KEY] = length
379+
if length is not None:
380+
assert length >= 1
381+
new_annot[self.LENGTH_INDEX_KEY] = length
380382

381383
self._metadata[self.ANNOTATION_KEY] += [new_annot]
382384
# sort annotations by start_index

tests/test_validation.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ def test_invalid_annotation_order(self):
8181
with self.assertRaises(ValidationError):
8282
SigMFFile(self.metadata).validate()
8383

84+
def test_annotation_without_sample_count(self):
85+
'''annotation without length should be accepted'''
86+
self.metadata[SigMFFile.ANNOTATION_KEY] = [
87+
{
88+
SigMFFile.START_INDEX_KEY: 2
89+
}
90+
]
91+
SigMFFile(self.metadata).validate()
92+
93+
8494
def test_invalid_hash(self):
8595
_, temp_path = tempfile.mkstemp()
8696
TEST_FLOAT32_DATA.tofile(temp_path)

0 commit comments

Comments
 (0)