Skip to content

ENH Brain.add_label(): find labels in subfolder #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 26, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions surfer/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,8 +991,8 @@ def add_annotation(self, annot, borders=True, alpha=1, hemi=None,
self.annot_list = al
self._toggle_render(True, views)

def add_label(self, label, color="crimson", alpha=1,
scalar_thresh=None, borders=False, hemi=None):
def add_label(self, label, color="crimson", alpha=1, scalar_thresh=None,
borders=False, hemi=None, subdir=None):
"""Add an ROI label to the image.

Parameters
Expand All @@ -1015,6 +1015,12 @@ def add_label(self, label, color="crimson", alpha=1,
If None, it is assumed to belong to the hemipshere being
shown. If two hemispheres are being shown, an error will
be thrown.
subdir : None | str
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make it a bit clearer that this is only relevant when the label is in the Freesurfer SUBJECTS_DIR tree.

If a label is specified as name, subdir can be used to indicate
that the label file is in a sub-directory of the subject's
label directory rather than in the label directory itself (e.g.
for ``$SUBJECTS_DIR/$SUBJECT/label/aparc/lh.cuneus.label``
``brain.add_label('cuneus', subdir='aparc')``).

Notes
-----
Expand All @@ -1027,10 +1033,13 @@ def add_label(self, label, color="crimson", alpha=1,
label_name = os.path.basename(filepath).split('.')[1]
else:
label_name = label
filepath = pjoin(self.subjects_dir,
self.subject_id,
'label',
".".join([hemi, label_name, 'label']))
label_fname = ".".join([hemi, label_name, 'label'])
if subdir is None:
filepath = pjoin(self.subjects_dir, self.subject_id,
'label', label_fname)
else:
filepath = pjoin(self.subjects_dir, self.subject_id,
'label', subdir, label_fname)
if not os.path.exists(filepath):
raise ValueError('Label file %s does not exist'
% filepath)
Expand Down