Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nibabel/brikhead.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ def __init__(self, info):
--------
>>> fname = os.path.join(datadir, 'example4d+orig.HEAD')
>>> header = AFNIHeader(parse_AFNI_header(fname))
>>> header.get_data_dtype()
dtype('int16')
>>> header.get_data_dtype().str
'<i2'
>>> header.get_zooms()
(3.0, 3.0, 3.0, 3.0)
>>> header.get_data_shape()
Expand Down
6 changes: 3 additions & 3 deletions nibabel/streamlines/trk.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ def is_correct_format(cls, fileobj):
def _default_structarr(cls):
""" Return an empty compliant TRK header as numpy structured array
"""
st_arr = np.zeros((), dtype=header_2_dtype)
# Enforce little-endian byte order for header
st_arr = np.zeros((), dtype=header_2_dtype).newbyteorder('<')

# Default values
st_arr[Field.MAGIC_NUMBER] = cls.MAGIC_NUMBER
Expand Down Expand Up @@ -395,8 +396,7 @@ def save(self, fileobj):
pointing to TRK file (and ready to write from the beginning
of the TRK header data).
"""
# Enforce little-endian byte order for header
header = self._default_structarr().newbyteorder('<')
header = self._default_structarr()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it ends up the same, but maybe cleaner keeping the endian change in the save function with

self._default_structarr().newbyteorder('<').byteswap()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that fail on little endian systems?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry - yes. Then maybe, for clarity, add an endianness=None kwarg to _default_structarr, and pass < from save.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works. I followed the template in WrapStruct.default_structarr.

Let me know if you have any further comments.


# Override hdr's fields by those contained in `header`.
for k, v in self.header.items():
Expand Down