Skip to content

Commit 1655e0f

Browse files
committed
Merge pull request #85 from christianmbrodbeck/label-path
ENH Brain.add_label(): find labels in SUBJECTS_DIR subfolder
2 parents 5345dd7 + ffa0325 commit 1655e0f

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

surfer/viz.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -991,8 +991,8 @@ def add_annotation(self, annot, borders=True, alpha=1, hemi=None,
991991
self.annot_list = al
992992
self._toggle_render(True, views)
993993

994-
def add_label(self, label, color="crimson", alpha=1,
995-
scalar_thresh=None, borders=False, hemi=None):
994+
def add_label(self, label, color="crimson", alpha=1, scalar_thresh=None,
995+
borders=False, hemi=None, subdir=None):
996996
"""Add an ROI label to the image.
997997
998998
Parameters
@@ -1015,6 +1015,12 @@ def add_label(self, label, color="crimson", alpha=1,
10151015
If None, it is assumed to belong to the hemipshere being
10161016
shown. If two hemispheres are being shown, an error will
10171017
be thrown.
1018+
subdir : None | str
1019+
If a label is specified as name, subdir can be used to indicate
1020+
that the label file is in a sub-directory of the subject's
1021+
label directory rather than in the label directory itself (e.g.
1022+
for ``$SUBJECTS_DIR/$SUBJECT/label/aparc/lh.cuneus.label``
1023+
``brain.add_label('cuneus', subdir='aparc')``).
10181024
10191025
Notes
10201026
-----
@@ -1027,10 +1033,13 @@ def add_label(self, label, color="crimson", alpha=1,
10271033
label_name = os.path.basename(filepath).split('.')[1]
10281034
else:
10291035
label_name = label
1030-
filepath = pjoin(self.subjects_dir,
1031-
self.subject_id,
1032-
'label',
1033-
".".join([hemi, label_name, 'label']))
1036+
label_fname = ".".join([hemi, label_name, 'label'])
1037+
if subdir is None:
1038+
filepath = pjoin(self.subjects_dir, self.subject_id,
1039+
'label', label_fname)
1040+
else:
1041+
filepath = pjoin(self.subjects_dir, self.subject_id,
1042+
'label', subdir, label_fname)
10341043
if not os.path.exists(filepath):
10351044
raise ValueError('Label file %s does not exist'
10361045
% filepath)

0 commit comments

Comments
 (0)