trx.io#
Unified I/O interface for tractogram file formats.
Attributes#
Functions#
Return a temporary directory honoring the |
|
|
Load a tractogram as a StatefulTractogram with an explicit reference. |
|
Load a tractogram from disk and return a TRX or StatefulTractogram. |
|
Save a tractogram object to disk. |
Module Contents#
- trx.io.get_trx_tmp_dir()[source]#
Return a temporary directory honoring the
TRX_TMPDIRsetting.When the
TRX_TMPDIRenvironment variable is set to"use_working_dir"the current working directory is used. Otherwise, the value ofTRX_TMPDIRis used directly. If the variable is not set, the system temporary directory is used.- Returns:
- tempfile.TemporaryDirectory
Context-managed temporary directory placed according to the environment configuration.
- trx.io.load_sft_with_reference(filepath, reference=None, bbox_check=True)[source]#
Load a tractogram as a StatefulTractogram with an explicit reference.
- Parameters:
- filepathstr
Path to the tractogram file (.trk, .tck, .fib, .vtk, .dpy).
- referencestr or nibabel.Nifti1Image, optional
Reference image used for formats without embedded affine information. Pass
"same"to reuse the header embedded in .trk files.- bbox_checkbool, optional
If True, validate that streamlines lie within the reference bounding box. Defaults to True.
- Returns:
- StatefulTractogram or None
Loaded tractogram. Returns
Nonewhendipyis unavailable.
- Raises:
- IOError
If the file format is unsupported or a required reference is missing.
- trx.io.load(tractogram_filename, reference)[source]#
Load a tractogram from disk and return a TRX or StatefulTractogram.
- Parameters:
- tractogram_filenamestr
Path to the input tractogram. TRX directories are supported.
- referencestr or nibabel.Nifti1Image
Reference image used for formats without embedded affine information.
- Returns:
- TrxFile or StatefulTractogram
TRX file handle for
.trxinputs, otherwise a StatefulTractogram.
- trx.io.save(tractogram_obj, tractogram_filename, bbox_valid_check=False)[source]#
Save a tractogram object to disk.
- Parameters:
- tractogram_objTrxFile or StatefulTractogram
Tractogram to persist. Non-TRX inputs are converted to StatefulTractogram before saving to non-TRX formats.
- tractogram_filenamestr
Destination file name.
.trxwill be saved using the TRX writer; all other extensions are handled bydipy.save_tractogram.- bbox_valid_checkbool, optional
If True, validate that streamlines lie within the reference bounding box when saving non-TRX formats. Defaults to False.
- Returns:
- None
The function writes to disk and returns
None. ReturnsNoneimmediately whendipyis unavailable.