/usr/lib/python2.7/dist-packages/dipy/io/trackvis.py is in python-dipy 0.10.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import nibabel as nib
import numpy as np
from dipy.tracking import utils
def save_trk(filename, points, vox_to_ras, shape):
"""A temporary helper function for saving trk files.
This function will soon be replaced by better trk file support in nibabel.
"""
voxel_order = nib.orientations.aff2axcodes(vox_to_ras)
voxel_order = "".join(voxel_order)
# Compute the vox_to_ras of "trackvis space"
zooms = np.sqrt((vox_to_ras * vox_to_ras).sum(0))
vox_to_trk = np.diag(zooms)
vox_to_trk[3, 3] = 1
vox_to_trk[:3, 3] = zooms[:3] / 2.
points = utils.move_streamlines(points,
input_space=vox_to_ras,
output_space=vox_to_trk)
data = ((p, None, None) for p in points)
hdr = nib.trackvis.empty_header()
hdr['dim'] = shape
hdr['voxel_order'] = voxel_order
hdr['voxel_size'] = zooms[:3]
nib.trackvis.write(filename, data, hdr)
|