NiBabel

Access a cacophony of neuro-imaging file formats

Previous topic

nibabel.trackvis.read

Next topic

nibabel.trackvis.TrackvisFile

This Page

Reggie -- the one

nibabel.trackvis.write

nibabel.trackvis.write(fileobj, streamlines, hdr_mapping=None, endianness=None)

Write header and streamlines to trackvis file fileobj

The parameters from the streamlines override conflicting parameters in the hdr_mapping information. In particular, the number of streamlines, the number of scalars, and the number of properties are written according to streamlines rather than hdr_mapping.

Parameters :

fileobj : filename or file-like

If filename, open file as ‘wb’, otherwise fileobj should be an open file-like object, with a write method.

streamlines : iterable

iterable returning 3 element sequences with elements:

  1. points : ndarray shape (N,3) where N is the number of points
  2. scalars : None or ndarray shape (N, M) where M is the number of scalars per point
  3. properties : None or ndarray shape (P,) where P is the number of properties

If streamlines has a len (for example, it is a list or a tuple), then we can write the number of streamlines into the header. Otherwise we write 0 for the number of streamlines (a valid trackvis header) and write streamlines into the file until the iterable is exhausted

hdr_mapping : None, ndarray or mapping, optional

Information for filling header fields. Can be something dict-like (implementing items) or a structured numpy array

endianness : {None, ‘<’, ‘>’}, optional

Endianness of file to be written. ‘<’ is little-endian, ‘>’ is big-endian. None (the default) is to use the endianness of the streamlines data.

Returns :

None :