sigmf / sigmf-python

Easily interact with Signal Metadata Format (SigMF) recordings.
https://sigmf.org
GNU Lesser General Public License v3.0
42 stars 16 forks source link

Allow skip_checksum on creation #46

Closed Teque5 closed 3 days ago

Teque5 commented 8 months ago

As mentioned in the other repo, the checksum field is optional yet this repo always calculates when creating a new dataset. Need a simple PR to allow skip. Probably combine with #44.

abhaysamantni commented 8 months ago

Thank you for raising the issue here @Teque5 . What is the tentative timeline for fixing the issue?

Teque5 commented 3 days ago

After looking into this, I realized it's already possible to skip checksum on creation.

An example similar to the current README.md, note I only added skip_checksum=True:

from sigmf import SigMFFile
import numpy as np

data = np.zeros(1024, dtype=np.complex64)
data.tofile('example_cf32.sigmf-data')
meta = SigMFFile(
    data_file='example_cf32.sigmf-data',
    global_info = {
        SigMFFile.DATATYPE_KEY: 'cf32_le',
        SigMFFile.SAMPLE_RATE_KEY: 48000,
        SigMFFile.VERSION_KEY: '1.2.0',
    },
    skip_checksum=True,
)

and the resulting object will have no checksum on creation:

>>> meta
SigMFFile({
    "global": {
        "core:datatype": "cf32_le",
        "core:sample_rate": 48000,
        "core:version": "1.2.0"
    },
    "captures": [],
    "annotations": []
})

and you can still calculate the checksum manually with meta.calculate_hash(), resulting in:

>>> meta
SigMFFile({
    "global": {
        "core:datatype": "cf32_le",
        "core:sample_rate": 48000,
        "core:sha512": "18790c279e0ca614c2b57a215fecc23a6c3d2d308ce77f314378cb2d1b0f413acd3a9cd353aa6da86ec9f51916925c7210f7dfabc0ef726779f8d44f227f03b1",
        "core:version": "1.2.0"
    },
    "captures": [],
    "annotations": []
})

and the metadata validates correctly either way.