File formats#

The formats Larmor reads and writes, with the Python functions for each. The load_ and save_ functions of larmor.io, and the lar commands, choose the format from the end of the file name; the read_ and write_ functions of larmor.io.formats read or write one format.

Images#

Format

File names

Read

Write

Python

NIfTI-1 and NIfTI-2

.nii, .nii.gz

yes

yes (NIfTI-2 only when a dimension needs it)

load_volume(), save_volume(), read_nifti(), write_nifti()

MRtrix image (MIF)

.mif, .mif.gz, .mih with its .dat

yes

yes

load_volume(), save_volume(), read_mif(), write_mif()

A MIF header can hold the gradient table (dw_scheme), which load_dwi() reads with the image and save_volume() writes into it.

Gradient tables#

Format

File names

Read

Write

Python

FSL bvals and bvecs

any, often .bval and .bvec

yes

yes

read_bvals_bvecs(), write_bvals_bvecs()

MRtrix gradient table

any, often .b

yes

yes

read_mrtrix_gradients(), write_mrtrix_gradients()

b-matrix, one row per volume

any

yes

yes

read_b_matrix(), write_b_matrix()

Tractograms#

Format

File names

Read

Write

Python

MRtrix tracks (TCK)

.tck, .tck.gz

yes

yes

load_tractogram(), save_tractogram(), read_tck(), write_tck()

TrackVis (TRK)

.trk, .trk.gz

yes

yes (version 2)

load_tractogram(), save_tractogram(), read_trk(), write_trk()

Legacy VTK polydata

.vtk, .fib, each also .gz

yes

yes

load_tractogram(), save_tractogram(), read_vtk(), write_vtk()

MRIToolkit tractography

.mat

yes

no

load_tractogram(), read_mritoolkit_tracts()

Large uncompressed TCK and TRK files can be read and written batch by batch, with iter_tractogram() and open_tractogram_writer().

Values along streamlines#

Format

File names

Read

Write

Python

MRtrix track scalar file (TSF): one value per point

.tsf

yes

yes

read_tsf(), write_tsf()

Streamline weights, as tcksift2 writes them: one value per streamline

any text file

yes

yes

read_streamline_weights(), write_streamline_weights()

Surfaces#

Format

File names

Read

Write

Python

GIfTI surface

.gii, such as .surf.gii

yes

yes

load_surface(), save_surface(), read_gifti_surface(), write_gifti_surface()

GIfTI values per vertex

.shape.gii, .func.gii, .label.gii

yes

yes (.shape.gii, .func.gii)

read_gifti_values(), write_gifti_values()

FreeSurfer surface

no extension, such as lh.white, lh.pial

yes

yes

load_surface(), save_surface(), read_freesurfer_surface(), write_freesurfer_surface()

FreeSurfer values per vertex (“new curv”)

such as lh.curv, lh.thickness

yes

yes

read_freesurfer_values(), write_freesurfer_values()

FreeSurfer label

.label, such as lh.cortex.label

yes

no

read_freesurfer_label()

Registrations#

Transforms are read, not written; load_transform() tells the format from the file where it can.

Format

File names

Read

Write

Python

ANTs (ITK) affine

binary .mat (such as 0GenericAffine.mat), text .txt, .tfm

yes

no

read_ants_transform()

ANTs displacement field

NIfTI, such as 1Warp.nii.gz

yes

no

read_ants_transform()

FSL FLIRT matrix

text, such as .mat from -omat

yes

no

read_flirt_transform()

FSL warp field

NIfTI (fnirt --fout, convertwarp, invwarp)

yes

no

read_fsl_warp()

MRtrix3 linear transform

text (mrregister, transformconvert)

yes

no

read_mrtrix_transform()

MRtrix3 deformation or displacement field

.mif or NIfTI

yes

no

read_mrtrix_warp()

MATLAB and MRIToolkit#

Format

File names

Read

Write

Python

MATLAB file, versions 4, 5 to 7 and 7.3

.mat

yes

no

read_matlab()

MRIToolkit DTI or DKI fit

.mat

yes

no

read_mritoolkit_fit(), read_mritoolkit_map()

MRIToolkit image, its values as stored

.mat

yes

no

read_mritoolkit_volume()

MRIToolkit FODs

.mat

yes

no

read_mritoolkit_fod(), read_mritoolkit_sh()

MRIToolkit peaks

.mat

yes

no

read_mritoolkit_peaks()

Tables and other text files#

Format

File names

Read

Write

Python

Lookup table, FreeSurfer or MRtrix layout

text, such as FreeSurferColorLUT.txt

yes

no

read_lookup_table()

Connectome matrix with region names

.csv, or text separated by spaces

no

yes

write_connectome()

Regions of each streamline’s endpoints, as tck2connectome writes them

text

no

yes

write_node_assignments()

Seeds, one row per seed

text

yes

yes

read_seeds(), write_seeds()

Tract profile, one row per point

.csv

no

yes

TractProfile.write_csv

BrainViewer session

.lar.json

yes

yes

Viewer.load_session, Viewer.save_session