Skip to content

Commit 9db8414

Browse files
committed
Merge pull request #92 from christianmbrodbeck/label.hemi
ENH Brain.add_label(): use the label.hemi and label.color attributes
2 parents 1655e0f + 7a85e07 commit 9db8414

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

surfer/viz.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -991,18 +991,19 @@ 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, scalar_thresh=None,
994+
def add_label(self, label, color=None, alpha=1, scalar_thresh=None,
995995
borders=False, hemi=None, subdir=None):
996996
"""Add an ROI label to the image.
997997
998998
Parameters
999999
----------
10001000
label : str | instance of Label
10011001
label filepath or name. Can also be an instance of
1002-
an object with attributes "hemi", "vertices", "name",
1003-
and (if scalar_thresh is not None) "values".
1004-
color : matplotlib-style color
1005-
anything matplotlib accepts: string, RGB, hex, etc.
1002+
an object with attributes "hemi", "vertices", "name", and
1003+
optionally "color" and "values" (if scalar_thresh is not None).
1004+
color : matplotlib-style color | None
1005+
anything matplotlib accepts: string, RGB, hex, etc. (default
1006+
"crimson")
10061007
alpha : float in [0, 1]
10071008
alpha level to control opacity
10081009
scalar_thresh : None or number
@@ -1026,8 +1027,11 @@ def add_label(self, label, color="crimson", alpha=1, scalar_thresh=None,
10261027
-----
10271028
To remove previously added labels, run Brain.remove_labels().
10281029
"""
1029-
hemi = self._check_hemi(hemi)
10301030
if isinstance(label, basestring):
1031+
hemi = self._check_hemi(hemi)
1032+
if color is None:
1033+
color = "crimson"
1034+
10311035
if os.path.isfile(label):
10321036
filepath = label
10331037
label_name = os.path.basename(filepath).split('.')[1]
@@ -1052,12 +1056,19 @@ def add_label(self, label, color="crimson", alpha=1, scalar_thresh=None,
10521056
else:
10531057
# try to extract parameters from label instance
10541058
try:
1055-
lhemi = label.hemi
1059+
hemi = label.hemi
10561060
ids = label.vertices
10571061
if label.name is None:
10581062
label_name = 'unnamed'
10591063
else:
10601064
label_name = str(label.name)
1065+
1066+
if color is None:
1067+
if hasattr(label, 'color') and label.color is not None:
1068+
color = label.color
1069+
else:
1070+
color = "crimson"
1071+
10611072
if scalar_thresh is not None:
10621073
scalars = label.values
10631074
except Exception:
@@ -1066,9 +1077,8 @@ def add_label(self, label, color="crimson", alpha=1, scalar_thresh=None,
10661077
'must have attributes "hemi", "vertices", '
10671078
'"name", and (if scalar_thresh is not None)'
10681079
'"values"')
1069-
if not lhemi == hemi:
1070-
raise ValueError('label hemisphere (%s) and brain hemisphere '
1071-
'(%s) must match' % (lhemi, hemi))
1080+
hemi = self._check_hemi(hemi)
1081+
10721082
if scalar_thresh is not None:
10731083
ids = ids[scalars >= scalar_thresh]
10741084

0 commit comments

Comments
 (0)