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:
Class which represents a GIFTI surface image.
Extracts surface data from the given
nibabel.gifti.GiftiImage.Loads vertex data from the given GIFTI file.
Prepares vertex data from the given list of GIFTI data arrays.
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:
MeshClass 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.GiftiImageinstance is stored in theMetastore, 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 theloadGiftiMesh()function.If the file contains more than one set of vertices, the additional ones are added with keys of the form
infile_i, whereinfileis the absolute path to the file, andiis an index number, starting from 1. See theaddVertices()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, theinfiledirectory is scanned for other surface files which are then loaded as additional vertex sets.
Todo
Allow loading from a
.topo.giiand.coord.giifile? Maybe.
- loadVertices(infile, key=None, *args, **kwargs)[source]
Overrides the
Mesh.loadVertices()method.Attempts to load vertices for this
GiftiMeshfrom the giveninfile, 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
GiftiMeshfrom the giveninfile, 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_TRIANGLEdata (vertex indices defining the triangles).one or more comprising
NIFTI_INTENT_POINTSETdata (the surface vertices)
A
ValueErrorwill 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.GiftiImageinstanceA
(M, 3)array containing the vertex indices forMtriangles.A list of at least one
(N, 3)arrays containingNvertices.A
(M, N)numpy array containingNdata points forMvertices, orNoneif the file does not contain any vertex data.
- fsl.data.gifti.loadGiftiVertexData(filename)[source]
Loads vertex data from the given GIFTI file.
Returns a tuple containing:
The loaded
nibabel.gifti.GiftiImageobjectA
(M, N)numpy array containingNdata points forMvertices
- 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, containingNdata points forMvertices.It is assumed that the given file does not contain any
NIFTI_INTENT_POINTSETorNIFTI_INTENT_TRIANGLEdata arrays, and which contains either:One
(M, N)data array containingNdata points forMverticesOne or more
(M, 1)data arrays each containing a single data point forMvertices, and all with the same intent code
Returns a
(M, N)numpy array containingNdata points forMvertices.
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>.giiBIDS-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.