trx.utils#

Attributes#

Functions#

close_or_delete_mmap(obj)

Close the memory-mapped file if it exists, otherwise set the object to None.

split_name_with_gz(filename)

Returns the clean basename and extension of a file.

get_reference_info_wrapper(reference)

Will compare the spatial attribute of 2 references.

is_header_compatible(reference_1, reference_2)

Will compare the spatial attribute of 2 references.

get_axis_shift_vector(flip_axes)

Parameters:

get_axis_flip_vector(flip_axes)

Parameters:

get_shift_vector(sft)

When flipping a tractogram the shift vector is used to change the origin

flip_sft(sft, flip_axes)

Flip the streamlines in the StatefulTractogram according to the

load_matrix_in_any_format(filepath)

Load a matrix from a txt file OR a npy file.

get_reverse_enum(space_str, origin_str)

Convert string representation to enums for the StatefulTractogram.

convert_data_dict_to_tractogram(data)

Convert a data from a lazy tractogram to a tractogram

append_generator_to_dict(gen, data)

verify_trx_dtype(trx, dict_dtype)

Verify if the dtype of the data in the trx is the same as the one in

Module Contents#

trx.utils.dipy_available = True[source]#
trx.utils.close_or_delete_mmap(obj)[source]#

Close the memory-mapped file if it exists, otherwise set the object to None.

trx.utils.split_name_with_gz(filename)[source]#

Returns the clean basename and extension of a file. Means that this correctly manages the “.nii.gz” extensions.

Parameters:
filename: str

The filename to clean

Returns:
base, exttuple(str, str)
Clean basename and the full extension
trx.utils.get_reference_info_wrapper(reference)[source]#

Will compare the spatial attribute of 2 references.

Parameters:
referenceNifti or Trk filename, Nifti1Image or TrkFile, Nifti1Header or

trk.header (dict), TrxFile or trx.header (dict) Reference that provides the spatial attribute.

Returns
——-
outputtuple
  • affine ndarray (4,4), np.float32, tranformation of VOX to RASMM

  • dimensions ndarray (3,), int16, volume shape for each axis

  • voxel_sizes ndarray (3,), float32, size of voxel for each axis

  • voxel_order, string, Typically ‘RAS’ or ‘LPS’

trx.utils.is_header_compatible(reference_1, reference_2)[source]#

Will compare the spatial attribute of 2 references.

Parameters:
reference_1Nifti or Trk filename, Nifti1Image or TrkFile,

Nifti1Header or trk.header (dict) Reference that provides the spatial attribute.

reference_2Nifti or Trk filename, Nifti1Image or TrkFile,

Nifti1Header or trk.header (dict) Reference that provides the spatial attribute.

Returns
——-
outputbool

Does all the spatial attribute match

trx.utils.get_axis_shift_vector(flip_axes)[source]#
Parameters:
flip_axeslist of str

String containing the axis to flip. Possible values are ‘x’, ‘y’, ‘z’

Returns
——-
flip_vectornp.ndarray (3,)

Vector containing the axis to flip. Possible values are -1, 1

trx.utils.get_axis_flip_vector(flip_axes)[source]#
Parameters:
flip_axeslist of str

String containing the axis to flip. Possible values are ‘x’, ‘y’, ‘z’

Returns
——-
flip_vectornp.ndarray (3,)

Vector containing the axis to flip. Possible values are -1, 1

trx.utils.get_shift_vector(sft)[source]#

When flipping a tractogram the shift vector is used to change the origin of the grid from the corner to the center of the grid.

Parameters:
sftStatefulTractogram

StatefulTractogram object

Returns
——-
shift_vectorndarray

Shift vector to apply to the streamlines

trx.utils.flip_sft(sft, flip_axes)[source]#

Flip the streamlines in the StatefulTractogram according to the flip_axes. Uses the spatial information to flip according to the center of the grid.

Parameters:
sftStatefulTractogram

StatefulTractogram to flip

flip_axeslist of str

Axes to flip. Possible values are ‘x’, ‘y’, ‘z’

Returns
——-
sftStatefulTractogram

StatefulTractogram with flipped axes

trx.utils.load_matrix_in_any_format(filepath)[source]#

Load a matrix from a txt file OR a npy file.

Parameters:
filepathstr

Path to the matrix file.

Returns
——-
matrixnumpy.ndarray

The matrix.

trx.utils.get_reverse_enum(space_str, origin_str)[source]#

Convert string representation to enums for the StatefulTractogram.

Parameters:
space_strstr

String representing the space.

origin_strstr

String representing the origin.

Returns
——-
outputstr

Space and Origin as Enums.

trx.utils.convert_data_dict_to_tractogram(data)[source]#

Convert a data from a lazy tractogram to a tractogram

Keyword arguments:

data – The data dictionary to convert into a nibabel tractogram

Returns:

A Tractogram object

trx.utils.append_generator_to_dict(gen, data)[source]#
trx.utils.verify_trx_dtype(trx, dict_dtype)[source]#

Verify if the dtype of the data in the trx is the same as the one in the dict.

Parameters:
trxTractogram

Tractogram to verify.

dict_dtypedict

Dictionary containing all elements dtype to verify.

Returns
——-
outputbool

True if the dtype is the same, False otherwise.