Skip to content

Commit 70bbf3b

Browse files
committed
NF: added the option to specify list of colors for cortex kw argument
1 parent 498f27e commit 70bbf3b

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

surfer/viz.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,16 @@ class Brain(object):
307307
this to ``None`` is equivalent to ``(0.5, 0.5, 0.5)``.
308308
3. The name of a colormap used to render binarized
309309
curvature values, e.g., ``Grays``.
310-
4. A container with four entries for colormap (string
310+
4. A list of colors used to render binarized curvature
311+
values. Only the first and last colors are used. E.g.,
312+
['red', 'blue'] or [(1, 0, 0), (0, 0, 1)].
313+
5. A container with four entries for colormap (string
311314
specifiying the name of a colormap), vmin (float
312315
specifying the minimum value for the colormap), vmax
313316
(float specifying the maximum value for the colormap),
314317
and reverse (bool specifying whether the colormap
315318
should be reversed. E.g., ``('Greys', -1, 2, False)``.
316-
5. A dict of keyword arguments that is passed on to the
319+
6. A dict of keyword arguments that is passed on to the
317320
call to surface.
318321
alpha : float in [0, 1]
319322
Alpha level to control opacity of the cortical surface.
@@ -577,11 +580,18 @@ def _get_geo_params(self, cortex, alpha=1.0):
577580
if 'vmax' not in cortex:
578581
cortex['vmax'] = 2
579582
geo_params = cortex, False, True
580-
elif cortex in colormap_map:
581-
geo_params = colormap_map[cortex]
582-
elif cortex in lut_manager.lut_mode_list():
583-
geo_params = dict(colormap=cortex, vmin=-1, vmax=2,
584-
opacity=alpha), False, True
583+
elif isinstance(cortex, basestring):
584+
if cortex in colormap_map:
585+
geo_params = colormap_map[cortex]
586+
elif cortex in lut_manager.lut_mode_list():
587+
geo_params = dict(colormap=cortex, vmin=-1, vmax=2,
588+
opacity=alpha), False, True
589+
else:
590+
try:
591+
color = colorConverter.to_rgb(cortex)
592+
geo_params = dict(color=color, opacity=alpha), False, False
593+
except ValueError:
594+
pass
585595
# check for None before checking len:
586596
elif cortex is None:
587597
geo_params = dict(color=(0.5, 0.5, 0.5),
@@ -590,16 +600,20 @@ def _get_geo_params(self, cortex, alpha=1.0):
590600
# avoid 4 letter strings and 4-tuples not specifying a
591601
# colormap name in the first position (color can be specified
592602
# as RGBA tuple, but the A value will be dropped by to_rgb()):
593-
elif (not isinstance(cortex, basestring)) and (len(cortex) == 4) and (
594-
isinstance(cortex[0], basestring)):
603+
elif (len(cortex) == 4) and (isinstance(cortex[0], basestring)):
595604
geo_params = dict(colormap=cortex[0], vmin=cortex[1],
596605
vmax=cortex[2], opacity=alpha), cortex[3], True
597606
else:
598-
try:
607+
try: # check if it's a non-string color specification
599608
color = colorConverter.to_rgb(cortex)
600609
geo_params = dict(color=color, opacity=alpha), False, False
601610
except ValueError:
602-
geo_params = cortex, False, True
611+
try:
612+
lut = create_color_lut(cortex)
613+
geo_params = dict(colormap="Greys", opacity=alpha,
614+
lut=lut), False, True
615+
except ValueError:
616+
geo_params = cortex, False, True
603617
return geo_params
604618

605619
def get_data_properties(self):
@@ -2480,9 +2494,17 @@ def __init__(self, subject_id, hemi, surf, figure, geo, geo_curv,
24802494
# add surface normals
24812495
self._geo_mesh.data.point_data.normals = self._geo.nn
24822496
self._geo_mesh.data.cell_data.normals = None
2497+
if 'lut' in geo_kwargs:
2498+
# create a new copy we can modify:
2499+
geo_kwargs = dict(geo_kwargs)
2500+
lut = geo_kwargs.pop('lut')
2501+
else:
2502+
lut = None
24832503
self._geo_surf = mlab.pipeline.surface(self._geo_mesh,
24842504
figure=self._f, reset_zoom=True,
24852505
**geo_kwargs)
2506+
if lut is not None:
2507+
self._geo_surf.module_manager.scalar_lut_manager.lut.table = lut
24862508
if geo_curv and geo_reverse:
24872509
curv_bar = mlab.scalarbar(self._geo_surf)
24882510
curv_bar.reverse_lut = True

0 commit comments

Comments
 (0)