SigMF
SigMF copied to clipboard
assert meta.validate() multiple annotations bug
The assert meta.validate() module produces an "AssertionError" when I place two annotations with the same sample start. This should be allowable according to "sigmf-spec.md":
"There is no limit to the number of annotations that can apply to the same group of samples. If two annotations have the same sample_start, there is no defined ordering between them."
create a capture key at time index 0
meta.add_capture(0, metadata={ SigMFFile.FREQUENCY_KEY: 915000000, SigMFFile.DATETIME_KEY: dt.datetime.utcnow().isoformat()+'Z', })
add an annotation at sample 100 with length 200 & 10 KHz width
meta.add_annotation(100, 200, metadata = {
SigMFFile.FLO_KEY: 914995000.0,
SigMFFile.FHI_KEY: 915005000.0,
SigMFFile.COMMENT_KEY: 'example annotation',
})
# add an annotation at sample 100 with length 200 & 10 KHz width
meta.add_annotation(100, 200, metadata = {
SigMFFile.FLO_KEY: 914995000.0,
SigMFFile.FHI_KEY: 915005000.0,
SigMFFile.COMMENT_KEY: 'example annotation',
})
The behavior you describe should be supported and I appreciate this bug report.
While i was not able to directly reproduce your problem, I did notice several other unrelated issues. I am currently working to get some of those problems addressed and will revisit this and make sure this does work.
Thank you for taking a look. Here is the complete code I was working on: ` import datetime as dt import sigmf from sigmf import SigMFFile, sigmffile import numpy as np
suppose we have an complex timeseries signal
data = np.zeros(1024, dtype=np.complex64)
write those samples to file in cf32_le
data.tofile('example.sigmf-data')
create the metadata
meta = SigMFFile( data_file='example.sigmf-data', # extension is optional global_info = { SigMFFile.DATATYPE_KEY: 'cf32_le', SigMFFile.SAMPLE_RATE_KEY: 48000, SigMFFile.AUTHOR_KEY: '[email protected]', SigMFFile.DESCRIPTION_KEY: 'All zero example file.', SigMFFile.VERSION_KEY: sigmf.version, } )
create a capture key at time index 0
meta.add_capture(0, metadata={ SigMFFile.FREQUENCY_KEY: 915000000, SigMFFile.DATETIME_KEY: dt.datetime.utcnow().isoformat()+'Z', })
add an annotation at sample 100 with length 200 & 10 KHz width
meta.add_annotation(100, 200, metadata = { SigMFFile.FLO_KEY: 914995000.0, SigMFFile.FHI_KEY: 915005000.0, SigMFFile.COMMENT_KEY: 'example annotation', })
# add an additional annotation at sample 100 with length 200 & 10 KHz width
meta.add_annotation(100, 20, metadata = { SigMFFile.FLO_KEY: 914995000.0, SigMFFile.FHI_KEY: 915005000.0, SigMFFile.COMMENT_KEY: 'example annotation', })
check for mistakes & write to disk
assert meta.validate() meta.tofile('example.sigmf-meta') # extension is optional `
I can validate your observations now, the act of adding the annotation is not a problem, but validation fails. The specific error is:
In Section `annotations`, chunk starting at index 100 is ahead of previous section.
@Teque5 thoughts?
I think the fix for this is to simply change the line
if this_index <= last_index:
to
if this_index < last_index:
inside validate.py.
I think this logic is meant to pertain to the captures global object and not the annotations - since captures cannot share an index.
The fix for this maybe should be merged with #174. The validator makes this weird distinction between sections and keys which should be simplified.
Makes sense to me. Is this something you can get together?
Ya either me or someone at my work will submit a PR soon.
Marked for v1.0.0 release as gating item