fix: add nsamples to recognised sigproc header keys#54
Open
fix: add nsamples to recognised sigproc header keys#54
Conversation
Some filterbank files include nsamples in their binary header. Since nsamples was not in the header_keys dictionary, parse_header() raised KeyError when encountering it. Add "nsamples": "I" (unsigned 32-bit integer) to header_keys so the parser can read past the field. The computed nsamples value on line 288 still overwrites whatever the file declares, preserving the existing behavior of deriving it from actual file dimensions. Fixes FRBs#53 Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #53
Filterbank files that include
nsamplesin their binary header causeparse_header()to crash withKeyError: 'nsamples'because the key is not in theheader_keysdictionary.Root Cause
In
sigpyproc/io/sigproc.py,header_keysdefines the set of recognised sigproc header keywords and theirstructformat codes. Thensampleskeyword is a valid sigproc header field (unsigned 32-bit integer), but it was missing from the dictionary.When
parse_header()reads a header key from the file and looks up its format:it crashes because
nsamplesis not a recognised key.Fix
Added
"nsamples": "I"to theheader_keysdictionary. This allows the parser to correctly read past thensamplesfield in the binary header.The computed
nsamplesvalue on lines 288-290 still overwrites whatever the file declares, preserving the existing behavior of deriving the sample count from the actual file dimensions (datalen,nbits,nchans).Testing
nsamplesin the header: behavior unchangednsamplesin the header: parsed correctly instead of crashingspp_header printworks on files that previously triggered the crash