Skip to content
Snippets Groups Projects
Commit 87294e3d authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

MGH files tested separately

parent 82285e88
No related branches found
No related tags found
No related merge requests found
...@@ -92,14 +92,19 @@ EXTRA_GEOMETRY_FILES = ['?h.orig.nofix', ...@@ -92,14 +92,19 @@ EXTRA_GEOMETRY_FILES = ['?h.orig.nofix',
VERTEX_DATA_FILES = ['?h.thickness', VERTEX_DATA_FILES = ['?h.thickness',
'?h.curv', '?h.curv',
'?h.area', '?h.area',
'?h.sulc', '?h.sulc']
'.mgh',
'.mgz']
"""File patterns which are interpreted as Freesurfer vertex data files, """File patterns which are interpreted as Freesurfer vertex data files,
containing a scalar value for every vertex in the mesh. containing a scalar value for every vertex in the mesh.
""" """
VERTEX_MGH_FILES = ['?h.*.mgh',
'?h.*.mgz']
"""File patterns which are interpreted as MGH files containing a
scalar value for every vertex in the mesh.
"""
VERTEX_LABEL_FILES = ['?h.*.label'] VERTEX_LABEL_FILES = ['?h.*.label']
"""File patterns which are interpreted as Freesurfer vertex label files, """File patterns which are interpreted as Freesurfer vertex label files,
containing a scalar value for a sub-set of vertices in the mesh. containing a scalar value for a sub-set of vertices in the mesh.
...@@ -196,10 +201,11 @@ class FreesurferMesh(fslmesh.Mesh): ...@@ -196,10 +201,11 @@ class FreesurferMesh(fslmesh.Mesh):
""" """
isvdata = isVertexDataFile( infile) isvdata = isVertexDataFile( infile)
isvmgh = isVertexMGHFile( infile)
isvlabel = isVertexLabelFile(infile) isvlabel = isVertexLabelFile(infile)
isvannot = isVertexAnnotFile(infile) isvannot = isVertexAnnotFile(infile)
if not any((isvdata, isvlabel, isvannot)): if not any((isvdata, isvmgh, isvlabel, isvannot)):
return fslmesh.Mesh.loadVertexData(self, infile) return fslmesh.Mesh.loadVertexData(self, infile)
infile = op.abspath(infile) infile = op.abspath(infile)
...@@ -211,9 +217,11 @@ class FreesurferMesh(fslmesh.Mesh): ...@@ -211,9 +217,11 @@ class FreesurferMesh(fslmesh.Mesh):
vdata = loadVertexDataFile(infile) vdata = loadVertexDataFile(infile)
if isvlabel: if isvlabel:
idxs, vdata = np.asarray(vdata, np.int) # Currently ignoring scalar
# values stored in label files
idxs = np.asarray(vdata[0])
expanded = np.zeros(nvertices) expanded = np.zeros(nvertices)
expanded[idxs] = vdata expanded[idxs] = 1
vdata = expanded vdata = expanded
elif isvannot: elif isvannot:
...@@ -222,7 +230,7 @@ class FreesurferMesh(fslmesh.Mesh): ...@@ -222,7 +230,7 @@ class FreesurferMesh(fslmesh.Mesh):
vdata = self.addVertexData(key, vdata) vdata = self.addVertexData(key, vdata)
if isvannot: if isvannot:
self.__luts[key] = lut, names, lut self.__luts[key] = lut, names
return vdata return vdata
...@@ -275,10 +283,16 @@ def loadVertexDataFile(infile): ...@@ -275,10 +283,16 @@ def loadVertexDataFile(infile):
return nibfs.read_label(infile, read_scalars=True) return nibfs.read_label(infile, read_scalars=True)
elif isVertexAnnotFile(infile): elif isVertexAnnotFile(infile):
return nibfs.read_annot(infile, orig_ids=False)
elif fslpath.hasExt(infile, fslmgh.ALLOWED_EXTENSIONS): # nibabel 2.2.1 is broken w.r.t. .annot files.
# raise ValueError('.annot files are not yet supported')
labels, lut, names = nibfs.read_annot(infile, orig_ids=False)
return labels, lut, names
elif isVertexMGHFile(infile):
return fslmgh.MGHImage(infile)[:].squeeze() return fslmgh.MGHImage(infile)[:].squeeze()
else: else:
raise ValueError('Unrecognised freesurfer ' raise ValueError('Unrecognised freesurfer '
'file type: {}'.format(infile)) 'file type: {}'.format(infile))
...@@ -312,6 +326,15 @@ def isVertexDataFile(infile): ...@@ -312,6 +326,15 @@ def isVertexDataFile(infile):
return any([fnmatch.fnmatch(infile, gf) for gf in VERTEX_DATA_FILES]) return any([fnmatch.fnmatch(infile, gf) for gf in VERTEX_DATA_FILES])
@memoize.memoize
def isVertexMGHFile(infile):
"""Returns ``True`` if ``infile`` looks like a Freesurfer MGH file
containing vertex data, ``False`` otherwise.
"""
infile = op.basename(infile)
return any([fnmatch.fnmatch(infile, gf) for gf in VERTEX_MGH_FILES])
@memoize.memoize @memoize.memoize
def isVertexLabelFile(infile): def isVertexLabelFile(infile):
"""Returns ``True`` if ``infile`` looks like a Freesurfer vertex """Returns ``True`` if ``infile`` looks like a Freesurfer vertex
...@@ -361,7 +384,10 @@ def relatedVertexDataFiles(fname): ...@@ -361,7 +384,10 @@ def relatedVertexDataFiles(fname):
dirname = op.dirname(fname) dirname = op.dirname(fname)
hemi = op.basename(fname)[0] hemi = op.basename(fname)[0]
fpats = VERTEX_DATA_FILES + VERTEX_LABEL_FILES + VERTEX_ANNOT_FILES fpats = (VERTEX_DATA_FILES +
VERTEX_LABEL_FILES +
VERTEX_ANNOT_FILES +
VERTEX_MGH_FILES)
fpats = [hemi + p[1:] if p.startswith('?h') else p for p in fpats] fpats = [hemi + p[1:] if p.startswith('?h') else p for p in fpats]
basedir = op.dirname(dirname) basedir = op.dirname(dirname)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment