SigMF icon indicating copy to clipboard operation
SigMF copied to clipboard

assert meta.validate() multiple annotations bug

Open lmr12 opened this issue 4 years ago • 8 comments

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', })

lmr12 avatar Sep 27 '21 19:09 lmr12

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.

jacobagilbert avatar Sep 27 '21 22:09 jacobagilbert

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 `

lmr12 avatar Sep 27 '21 22:09 lmr12

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?

jacobagilbert avatar Sep 27 '21 22:09 jacobagilbert

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.

Teque5 avatar Sep 27 '21 23:09 Teque5

The fix for this maybe should be merged with #174. The validator makes this weird distinction between sections and keys which should be simplified.

Teque5 avatar Sep 27 '21 23:09 Teque5

Makes sense to me. Is this something you can get together?

jacobagilbert avatar Sep 28 '21 00:09 jacobagilbert

Ya either me or someone at my work will submit a PR soon.

Teque5 avatar Sep 28 '21 15:09 Teque5

Marked for v1.0.0 release as gating item

bhilburn avatar Sep 30 '21 02:09 bhilburn