Skip to content

Commit 8ca4192

Browse files
committed
Merge pull request #115 from effigies/nibabel_io
RF Use nibabel.freesurfer.read_label
2 parents b10739c + dd37048 commit 8ca4192

File tree

3 files changed

+4
-28
lines changed

3 files changed

+4
-28
lines changed

surfer/io.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,31 +71,6 @@ def read_scalar_data(filepath):
7171
return scalar_data
7272

7373

74-
def read_label(filepath, read_scalars=False):
75-
"""Load in a Freesurfer .label file.
76-
77-
Parameters
78-
----------
79-
filepath : str
80-
Path to label file
81-
read_scalars : bool
82-
If true, read and return scalars associated with each vertex
83-
84-
Returns
85-
-------
86-
label_array : numpy array (ints)
87-
Array with indices of vertices included in label
88-
scalar_array : numpy array (floats)
89-
If read_scalars is True, array of scalar data for each vertex
90-
91-
"""
92-
label_array = np.loadtxt(filepath, dtype=np.int, skiprows=2, usecols=[0])
93-
if read_scalars:
94-
scalar_array = np.loadtxt(filepath, skiprows=2, usecols=[-1])
95-
return label_array, scalar_array
96-
return label_array
97-
98-
9974
def read_stc(filepath):
10075
"""Read an STC file from the MNE package
10176

surfer/tests/test_viz.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def test_probabilistic_labels():
256256

257257
label_file = pjoin(subj_dir, "fsaverage", "label", "lh.BA6.label")
258258
prob_field = np.zeros_like(brain._geo.x)
259-
ids, probs = io.read_label(label_file, read_scalars=True)
259+
ids, probs = nib.freesurfer.read_label(label_file, read_scalars=True)
260260
prob_field[ids] = probs
261261
brain.add_data(prob_field, thresh=1e-5)
262262

surfer/viz.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,9 +1055,10 @@ def add_label(self, label, color=None, alpha=1, scalar_thresh=None,
10551055
% filepath)
10561056
# Load the label data and create binary overlay
10571057
if scalar_thresh is None:
1058-
ids = io.read_label(filepath)
1058+
ids = nib.freesurfer.read_label(filepath)
10591059
else:
1060-
ids, scalars = io.read_label(filepath, read_scalars=True)
1060+
ids, scalars = nib.freesurfer.read_label(filepath,
1061+
read_scalars=True)
10611062
ids = ids[scalars >= scalar_thresh]
10621063
else:
10631064
# try to extract parameters from label instance

0 commit comments

Comments
 (0)