fsl.data.gifti

This class provides classes and functions for working with GIFTI files.

The GIFTI file format specification can be found at http://www.nitrc.org/projects/gifti/

Support is currently very basic - only the following classes/functions are available:

GiftiMesh

Class which represents a GIFTI surface image.

loadGiftiMesh

Extracts surface data from the given nibabel.gifti.GiftiImage.

loadGiftiVertexData

Loads vertex data from the given GIFTI file.

prepareGiftiVertexData

Prepares vertex data from the given list of GIFTI data arrays.

relatedFiles

Given a GIFTI file, returns a list of other GIFTI files in the same directory which appear to be related with the given one.

fsl.data.gifti.ALLOWED_EXTENSIONS = ['.surf.gii', '.gii']

List of file extensions that a file containing Gifti surface data is expected to have.

fsl.data.gifti.EXTENSION_DESCRIPTIONS = ['GIFTI surface file', 'GIFTI file']

A description for each of the ALLOWED_EXTENSIONS.

fsl.data.gifti.VERTEX_DATA_EXTENSIONS = ['.func.gii', '.shape.gii', '.label.gii', '.time.gii']

File suffixes which are interpreted as GIFTI vertex data files, containing data values for every vertex in the mesh.

class fsl.data.gifti.GiftiMesh(*args, **kwargs)[source]

Bases: Mesh

Class which represents a GIFTI surface image. This is essentially just a 3D model made of triangles.

For each GIFTI surface file that is loaded, the nibabel.gifti.GiftiImage instance is stored in the Meta store, with the absolute path to the surface file as the key.

__init__(infile, fixWinding=False, loadAll=False)[source]

Load the given GIFTI file using nibabel, and extracts surface data using the loadGiftiMesh() function.

If the file contains more than one set of vertices, the additional ones are added with keys of the form infile_i, where infile is the absolute path to the file, and i is an index number, starting from 1. See the addVertices() method.

Parameters:
  • infile – A GIFTI file (*.gii) which contains a surface definition.

  • fixWinding – Passed through to the addVertices() method for the first vertex set.

  • loadAll – If True, the infile directory is scanned for other surface files which are then loaded as additional vertex sets.

Todo

Allow loading from a .topo.gii and .coord.gii file? Maybe.

loadVertices(infile, key=None, *args, **kwargs)[source]

Overrides the Mesh.loadVertices() method.

Attempts to load vertices for this GiftiMesh from the given infile, which may be a GIFTI file or a plain text file containing vertices.

loadVertexData(infile, key=None)[source]

Overrides the Mesh.loadVertexData() method.

Attempts to load data associated with each vertex of this GiftiMesh from the given infile, which may be a GIFTI file or a plain text file which contains vertex data.

__annotations__ = {}
__module__ = 'fsl.data.gifti'
fsl.data.gifti.loadGiftiMesh(filename)[source]

Extracts surface data from the given nibabel.gifti.GiftiImage.

The image is expected to contain the following``<DataArray>`` elements:

  • one comprising NIFTI_INTENT_TRIANGLE data (vertex indices defining the triangles).

  • one or more comprising NIFTI_INTENT_POINTSET data (the surface vertices)

A ValueError will be raised if this is not the case.

Parameters:

filename – Name of a GIFTI file containing surface data.

Returns:

A tuple containing these values:

  • The loaded nibabel.gifti.GiftiImage instance

  • A (M, 3) array containing the vertex indices for M triangles.

  • A list of at least one (N, 3) arrays containing N vertices.

  • A (M, N) numpy array containing N data points for M vertices, or None if the file does not contain any vertex data.

fsl.data.gifti.loadGiftiVertexData(filename)[source]

Loads vertex data from the given GIFTI file.

See prepareGiftiVertexData().

Returns a tuple containing:

  • The loaded nibabel.gifti.GiftiImage object

  • A (M, N) numpy array containing N data points for M vertices

fsl.data.gifti.prepareGiftiVertexData(darrays, filename=None)[source]

Prepares vertex data from the given list of GIFTI data arrays.

All of the data arrays are concatenated into one (M, N) array, containing N data points for M vertices.

It is assumed that the given file does not contain any NIFTI_INTENT_POINTSET or NIFTI_INTENT_TRIANGLE data arrays, and which contains either:

  • One (M, N) data array containing N data points for M vertices

  • One or more (M, 1) data arrays each containing a single data point for M vertices, and all with the same intent code

Returns a (M, N) numpy array containing N data points for M vertices.

fsl.data.gifti.relatedFiles(fname, ftypes=None)[source]

Given a GIFTI file, returns a list of other GIFTI files in the same directory which appear to be related with the given one. Files which share the same prefix are assumed to be related to the given file.

This function assumes that the GIFTI files are named according to a standard convention - the following conventions are supported:

  • HCP-style, i.e.: <subject>.<hemi>.<type>.<space>.<ftype>.gii

  • BIDS-style, i.e.: <source_prefix>_hemi-<hemi>[_space-<space>]*_<suffix>.<ftype>.gii

If the files are not named according to one of these conventions, this function will return an empty list.

Parameters:
  • fname – Name of the file to search for related files for

  • ftype – If provided, only files with suffixes in this list are searched for. Defaults to VERTEX_DATA_EXTENSIONS.