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
streamlines : iterable
hdr_mapping : None, ndarray or mapping, optional
endianness : {None, ‘<’, ‘>’}, optional
points_space : {None, ‘voxel’, ‘rasmm’}, optional
|
---|---|
Returns: | None : |
Notes
Trackvis (the application) expects the points in the streamlines be in what we call trackviz voxmm coordinates. If we have a point (x, y, z) in voxmm coordinates, and voxel_size has the voxel sizes for each of the 3 dimensions, then x, y, z refer to mm in voxel space. Thus if i, j, k is a point in voxel coordinates, then x = i * voxel_size[0]; y = j * voxel_size[1]; z = k * voxel_size[2]. The spatial direction of x, y and z are defined with the “voxel_order” field. For example, if the original image had RAS voxel ordering then “voxel_order” would be “RAS”. RAS here refers to the spatial direction of the voxel axes: “R” means that moving along first voxel axis moves from left to right in space, “A” -> second axis goes from posterior to anterior, “S” -> inferior to superior. If “voxel_order” is empty we assume “LPS”.
This information comes from some helpful replies on the trackviz forum about interpreting point coordiantes
Examples
>>> from StringIO import StringIO #23dt : BytesIO
>>> file_obj = StringIO() #23dt : BytesIO
>>> pts0 = np.random.uniform(size=(10,3))
>>> pts1 = np.random.uniform(size=(10,3))
>>> streamlines = ([(pts0, None, None), (pts1, None, None)])
>>> write(file_obj, streamlines)
>>> _ = file_obj.seek(0) # returns 0 in python 3
>>> streams, hdr = read(file_obj)
>>> len(streams)
2
If there are too many streamlines to fit in memory, you can pass an iterable thing instead of a list
>>> file_obj = StringIO() #23dt : BytesIO
>>> def gen():
... yield (pts0, None, None)
... yield (pts0, None, None)
>>> write(file_obj, gen())
>>> _ = file_obj.seek(0)
>>> streams, hdr = read(file_obj)
>>> len(streams)
2