Skip to content

Commit c7a5912

Browse files
committed
Specifying kwargs as mlab_kws and make the documentation more clear.
1 parent 9d077da commit c7a5912

File tree

1 file changed

+50
-41
lines changed

1 file changed

+50
-41
lines changed

surfer/viz.py

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ def _iter_time(self, time_idx, interpolation):
913913
###########################################################################
914914
# ADDING DATA PLOTS
915915
def add_overlay(self, source, min=2, max="robust_max", sign="abs",
916-
name=None, hemi=None, **kwargs):
916+
name=None, hemi=None, **mlab_kws):
917917
"""Add an overlay to the overlay dict from a file or array.
918918
919919
Parameters
@@ -932,7 +932,8 @@ def add_overlay(self, source, min=2, max="robust_max", sign="abs",
932932
If None, it is assumed to belong to the hemipshere being
933933
shown. If two hemispheres are being shown, an error will
934934
be thrown.
935-
kwargs: other mayavi surface arguments.
935+
**mlab_kws: All additional keyword arguments are passed to the
936+
`mlab.pipeline.surface` call.
936937
"""
937938
hemi = self._check_hemi(hemi)
938939
# load data here
@@ -945,7 +946,7 @@ def add_overlay(self, source, min=2, max="robust_max", sign="abs",
945946
views = self._toggle_render(False)
946947
for brain in self._brain_list:
947948
if brain['hemi'] == hemi:
948-
ol.append(brain['brain'].add_overlay(old, **kwargs))
949+
ol.append(brain['brain'].add_overlay(old, **mlab_kws))
949950
if name in self.overlays_dict:
950951
name = "%s%d" % (name, len(self.overlays_dict) + 1)
951952
self.overlays_dict[name] = ol
@@ -959,7 +960,7 @@ def add_data(self, array, min=None, max=None, thresh=None,
959960
hemi=None, remove_existing=False, time_label_size=14,
960961
initial_time=None, scale_factor=None, vector_alpha=None,
961962
mid=None, center=None, transparent=False, verbose=None,
962-
**kwargs):
963+
**mlab_kws):
963964
"""Display data from a numpy array on the surface.
964965
965966
This provides a similar interface to
@@ -1037,7 +1038,8 @@ def add_data(self, array, min=None, max=None, thresh=None,
10371038
vector-valued data. If None (default), ``alpha`` is used.
10381039
verbose : bool, str, int, or None
10391040
If not None, override default verbose level (see surfer.verbose).
1040-
kwargs: other mayavi surface arguments.
1041+
**mlab_kws: All additional keyword arguments are passed to the
1042+
`mlab.pipeline.surface` call.
10411043
10421044
Notes
10431045
-----
@@ -1175,7 +1177,7 @@ def time_label(x):
11751177
s, ct, bar, gl = brain['brain'].add_data(
11761178
array, min, mid, max, thresh, lut, colormap, alpha,
11771179
colorbar, layer_id, smooth_mat, magnitude, magnitude_max,
1178-
scale_factor, vertices, vector_alpha, **kwargs)
1180+
scale_factor, vertices, vector_alpha, **mlab_kws)
11791181
surfs.append(s)
11801182
bars.append(bar)
11811183
glyphs.append(gl)
@@ -1199,7 +1201,7 @@ def time_label(x):
11991201
self._toggle_render(True, views)
12001202

12011203
def add_annotation(self, annot, borders=True, alpha=1, hemi=None,
1202-
remove_existing=True, color=None, **kwargs):
1204+
remove_existing=True, color=None, **mlab_kws):
12031205
"""Add an annotation file.
12041206
12051207
Parameters
@@ -1226,7 +1228,8 @@ def add_annotation(self, annot, borders=True, alpha=1, hemi=None,
12261228
color : matplotlib-style color code
12271229
If used, show all annotations in the same (specified) color.
12281230
Probably useful only when showing annotation borders.
1229-
kwargs: other mayavi surface arguments.
1231+
**mlab_kws: All additional keyword arguments are passed to the
1232+
`mlab.pipeline.surface` call.
12301233
"""
12311234
hemis = self._check_hemis(hemi)
12321235

@@ -1309,11 +1312,11 @@ def add_annotation(self, annot, borders=True, alpha=1, hemi=None,
13091312
if brain['hemi'] == hemi:
13101313
self.annot_list.append(
13111314
brain['brain'].add_annotation(annot, ids, cmap,
1312-
**kwargs))
1315+
**mlab_kws))
13131316
self._toggle_render(True, views)
13141317

13151318
def add_label(self, label, color=None, alpha=1, scalar_thresh=None,
1316-
borders=False, hemi=None, subdir=None, **kwargs):
1319+
borders=False, hemi=None, subdir=None, **mlab_kws):
13171320
"""Add an ROI label to the image.
13181321
13191322
Parameters
@@ -1345,7 +1348,8 @@ def add_label(self, label, color=None, alpha=1, scalar_thresh=None,
13451348
label directory rather than in the label directory itself (e.g.
13461349
for ``$SUBJECTS_DIR/$SUBJECT/label/aparc/lh.cuneus.label``
13471350
``brain.add_label('cuneus', subdir='aparc')``).
1348-
kwargs: other mayavi surface arguments.
1351+
**mlab_kws: All additional keyword arguments are passed to the
1352+
`mlab.pipeline.surface` call.
13491353
Notes
13501354
-----
13511355
To remove previously added labels, run Brain.remove_labels().
@@ -1426,7 +1430,7 @@ def add_label(self, label, color=None, alpha=1, scalar_thresh=None,
14261430
for brain in self.brains:
14271431
if brain.hemi == hemi:
14281432
array_id, surf = brain.add_label(label, label_name, color,
1429-
alpha, **kwargs)
1433+
alpha, **mlab_kws)
14301434
surfaces.append(surf)
14311435
array_ids.append((brain, array_id))
14321436
self._label_dicts[label_name] = {'surfaces': surfaces,
@@ -1536,7 +1540,7 @@ def remove_labels(self, labels=None, hemi=None):
15361540

15371541
def add_morphometry(self, measure, grayscale=False, hemi=None,
15381542
remove_existing=True, colormap=None,
1539-
min=None, max=None, colorbar=True, **kwargs):
1543+
min=None, max=None, colorbar=True, **mlab_kws):
15401544
"""Add a morphometry overlay to the image.
15411545
15421546
Parameters
@@ -1558,7 +1562,8 @@ def add_morphometry(self, measure, grayscale=False, hemi=None,
15581562
of the data is used.
15591563
colorbar : bool
15601564
If True, show a colorbar corresponding to the overlay data.
1561-
kwargs: other mayavi surface arguments.
1565+
**mlab_kws: All additional keyword arguments are passed to the
1566+
`mlab.pipeline.surface` call.
15621567
"""
15631568
hemis = self._check_hemis(hemi)
15641569
morph_files = []
@@ -1620,12 +1625,12 @@ def add_morphometry(self, measure, grayscale=False, hemi=None,
16201625
if brain.hemi == hemi:
16211626
self.morphometry_list.append(brain.add_morphometry(
16221627
morph_data, colormap, measure, min, max, colorbar,
1623-
**kwargs))
1628+
**mlab_kws))
16241629
self._toggle_render(True, views)
16251630

16261631
def add_foci(self, coords, coords_as_verts=False, map_surface=None,
16271632
scale_factor=1, color="white", alpha=1, name=None,
1628-
hemi=None, **kwargs):
1633+
hemi=None, **mlab_kws):
16291634
"""Add spherical foci, possibly mapping to displayed surf.
16301635
16311636
The foci spheres can be displayed at the coordinates given, or
@@ -1655,7 +1660,8 @@ def add_foci(self, coords, coords_as_verts=False, map_surface=None,
16551660
If None, it is assumed to belong to the hemipshere being
16561661
shown. If two hemispheres are being shown, an error will
16571662
be thrown.
1658-
kwargs: other mayavi point3d arguments.
1663+
**mlab_kws: All additional keyword arguments are passed to the
1664+
`mlab.point3d` call.
16591665
"""
16601666
from matplotlib.colors import colorConverter
16611667
hemi = self._check_hemi(hemi)
@@ -1692,14 +1698,14 @@ def add_foci(self, coords, coords_as_verts=False, map_surface=None,
16921698
if brain['hemi'] == hemi:
16931699
fl.append(brain['brain'].add_foci(foci_coords, scale_factor,
16941700
color, alpha, name,
1695-
**kwargs))
1701+
**mlab_kws))
16961702
self.foci_dict[name] = fl
16971703
self._toggle_render(True, views)
16981704

16991705
def add_contour_overlay(self, source, min=None, max=None,
17001706
n_contours=7, line_width=1.5, colormap="YlOrRd_r",
17011707
hemi=None, remove_existing=True, colorbar=True,
1702-
**kwargs):
1708+
**mlab_kws):
17031709
"""Add a topographic contour overlay of the positive data.
17041710
17051711
Note: This visualization will look best when using the "low_contrast"
@@ -1729,7 +1735,8 @@ def add_contour_overlay(self, source, min=None, max=None,
17291735
If there is an existing contour overlay, remove it before plotting.
17301736
colorbar : bool
17311737
If True, show the colorbar for the scalar value.
1732-
kwargs: other mayavi surface arguments.
1738+
**mlab_kws: All additional keyword arguments are passed to the
1739+
`mlab.pipeline.surface` call.
17331740
"""
17341741
hemi = self._check_hemi(hemi)
17351742

@@ -1756,11 +1763,12 @@ def add_contour_overlay(self, source, min=None, max=None,
17561763
if brain.hemi == hemi:
17571764
self.contour_list.append(brain.add_contour_overlay(
17581765
scalar_data, min, max, n_contours, line_width, lut,
1759-
colorbar, **kwargs))
1766+
colorbar, **mlab_kws))
17601767
self._toggle_render(True, views)
17611768

17621769
def add_text(self, x, y, text, name, color=None, opacity=1.0,
1763-
row=-1, col=-1, font_size=None, justification=None, **kwargs):
1770+
row=-1, col=-1, font_size=None, justification=None,
1771+
**mlab_kws):
17641772
""" Add a text to the visualization
17651773
17661774
Parameters
@@ -1783,13 +1791,14 @@ def add_text(self, x, y, text, name, color=None, opacity=1.0,
17831791
Row index of which brain to use
17841792
col : int
17851793
Column index of which brain to use
1786-
kwargs: other mayavi text3d arguments.
1794+
mlab_kws: All additional keyword arguments are passed to the
1795+
`mlab.text` call.
17871796
"""
17881797
if name in self.texts_dict:
17891798
self.texts_dict[name]['text'].remove()
17901799
text = self.brain_matrix[row, col].add_text(x, y, text,
17911800
name, color, opacity,
1792-
**kwargs)
1801+
**mlab_kws)
17931802
self.texts_dict[name] = dict(row=row, col=col, text=text)
17941803
if font_size is not None:
17951804
text.property.font_size = font_size
@@ -3206,7 +3215,7 @@ def _remove_vector_data(self, glyphs):
32063215
if glyphs is not None:
32073216
glyphs.parent.parent.remove()
32083217

3209-
def add_overlay(self, old, **kwargs):
3218+
def add_overlay(self, old, **mlab_kws):
32103219
"""Add an overlay to the overlay dict from a file or array"""
32113220
array_id, mesh = self._add_scalar_data(old.mlab_data)
32123221

@@ -3216,7 +3225,7 @@ def add_overlay(self, old, **kwargs):
32163225
pos = mlab.pipeline.surface(
32173226
pos_thresh, colormap="YlOrRd", figure=self._f,
32183227
vmin=old.pos_lims[1], vmax=old.pos_lims[2],
3219-
reset_zoom=False, **kwargs)
3228+
reset_zoom=False, **mlab_kws)
32203229
pos.actor.property.backface_culling = False
32213230
pos_bar = mlab.scalarbar(pos, nb_labels=5)
32223231
pos_bar.reverse_lut = True
@@ -3232,7 +3241,7 @@ def add_overlay(self, old, **kwargs):
32323241
neg = mlab.pipeline.surface(
32333242
neg_thresh, colormap="PuBu", figure=self._f,
32343243
vmin=old.neg_lims[1], vmax=old.neg_lims[2],
3235-
reset_zoom=False, **kwargs)
3244+
reset_zoom=False, **mlab_kws)
32363245
neg.actor.property.backface_culling = False
32373246
neg_bar = mlab.scalarbar(neg, nb_labels=5)
32383247
neg_bar.scalar_bar_representation.position = (0.05, 0.01)
@@ -3246,7 +3255,7 @@ def add_overlay(self, old, **kwargs):
32463255
@verbose
32473256
def add_data(self, array, fmin, fmid, fmax, thresh, lut, colormap, alpha,
32483257
colorbar, layer_id, smooth_mat, magnitude, magnitude_max,
3249-
scale_factor, vertices, vector_alpha, **kwargs):
3258+
scale_factor, vertices, vector_alpha, **mlab_kws):
32503259
"""Add data to the brain"""
32513260
# Calculate initial data to plot
32523261
if array.ndim == 1:
@@ -3289,7 +3298,7 @@ def add_data(self, array, fmin, fmid, fmax, thresh, lut, colormap, alpha,
32893298
surf = mlab.pipeline.surface(
32903299
pipe, colormap=colormap, vmin=fmin, vmax=fmax,
32913300
opacity=float(alpha), figure=self._f, reset_zoom=False,
3292-
**kwargs)
3301+
**mlab_kws)
32933302
surf.actor.property.backface_culling = False
32943303

32953304
# apply look up table if given
@@ -3314,13 +3323,13 @@ def add_data(self, array, fmin, fmid, fmax, thresh, lut, colormap, alpha,
33143323
scale_factor_norm=scale_factor_norm)
33153324
return surf, orig_ctable, bar, glyphs
33163325

3317-
def add_annotation(self, annot, ids, cmap, **kwargs):
3326+
def add_annotation(self, annot, ids, cmap, **mlab_kws):
33183327
"""Add an annotation file"""
33193328
# Add scalar values to dataset
33203329
array_id, pipe = self._add_scalar_data(ids)
33213330
with warnings.catch_warnings(record=True):
33223331
surf = mlab.pipeline.surface(pipe, name=annot, figure=self._f,
3323-
reset_zoom=False, **kwargs)
3332+
reset_zoom=False, **mlab_kws)
33243333
surf.actor.property.backface_culling = False
33253334

33263335
# Set the color table
@@ -3331,13 +3340,13 @@ def add_annotation(self, annot, ids, cmap, **kwargs):
33313340
return dict(surface=surf, name=annot, colormap=cmap, brain=self,
33323341
array_id=array_id)
33333342

3334-
def add_label(self, label, label_name, color, alpha, **kwargs):
3343+
def add_label(self, label, label_name, color, alpha, **mlab_kws):
33353344
"""Add an ROI label to the image"""
33363345
from matplotlib.colors import colorConverter
33373346
array_id, pipe = self._add_scalar_data(label)
33383347
with warnings.catch_warnings(record=True):
33393348
surf = mlab.pipeline.surface(pipe, name=label_name, figure=self._f,
3340-
reset_zoom=False, **kwargs)
3349+
reset_zoom=False, **mlab_kws)
33413350
surf.actor.property.backface_culling = False
33423351
color = colorConverter.to_rgba(color, alpha)
33433352
cmap = np.array([(0, 0, 0, 0,), color])
@@ -3349,13 +3358,13 @@ def add_label(self, label, label_name, color, alpha, **kwargs):
33493358
return array_id, surf
33503359

33513360
def add_morphometry(self, morph_data, colormap, measure,
3352-
min, max, colorbar, **kwargs):
3361+
min, max, colorbar, **mlab_kws):
33533362
"""Add a morphometry overlay to the image"""
33543363
array_id, pipe = self._add_scalar_data(morph_data)
33553364
with warnings.catch_warnings(record=True):
33563365
surf = mlab.pipeline.surface(
33573366
pipe, colormap=colormap, vmin=min, vmax=max, name=measure,
3358-
figure=self._f, reset_zoom=False, **kwargs)
3367+
figure=self._f, reset_zoom=False, **mlab_kws)
33593368

33603369
# Get the colorbar
33613370
if colorbar:
@@ -3370,27 +3379,27 @@ def add_morphometry(self, morph_data, colormap, measure,
33703379
array_id=array_id)
33713380

33723381
def add_foci(self, foci_coords, scale_factor, color, alpha, name,
3373-
**kwargs):
3382+
**mlab_kws):
33743383
"""Add spherical foci, possibly mapping to displayed surf"""
33753384
# Create the visualization
33763385
with warnings.catch_warnings(record=True): # traits
33773386
points = mlab.points3d(
33783387
foci_coords[:, 0], foci_coords[:, 1], foci_coords[:, 2],
33793388
np.ones(foci_coords.shape[0]), name=name, figure=self._f,
33803389
scale_factor=(10. * scale_factor), color=color, opacity=alpha,
3381-
reset_zoom=False, **kwargs)
3390+
reset_zoom=False, **mlab_kws)
33823391
return points
33833392

33843393
def add_contour_overlay(self, scalar_data, min=None, max=None,
33853394
n_contours=7, line_width=1.5, lut=None,
3386-
colorbar=True, **kwargs):
3395+
colorbar=True, **mlab_kws):
33873396
"""Add a topographic contour overlay of the positive data"""
33883397
array_id, pipe = self._add_scalar_data(scalar_data)
33893398
with warnings.catch_warnings(record=True):
33903399
thresh = threshold_filter(pipe, low=min)
33913400
surf = mlab.pipeline.contour_surface(
33923401
thresh, contours=n_contours, line_width=line_width,
3393-
reset_zoom=False, **kwargs)
3402+
reset_zoom=False, **mlab_kws)
33943403
if lut is not None:
33953404
l_m = surf.module_manager.scalar_lut_manager
33963405
l_m.load_lut_from_list(lut / 255.)
@@ -3408,12 +3417,12 @@ def add_contour_overlay(self, scalar_data, min=None, max=None,
34083417
# Set up a dict attribute with pointers at important things
34093418
return dict(surface=surf, colorbar=bar, brain=self, array_id=array_id)
34103419

3411-
def add_text(self, x, y, text, name, color=None, opacity=1.0, **kwargs):
3420+
def add_text(self, x, y, text, name, color=None, opacity=1.0, **mlab_kws):
34123421
""" Add a text to the visualization"""
34133422
color = self._fg_color if color is None else color
34143423
with warnings.catch_warnings(record=True):
34153424
text = mlab.text(x, y, text, name=name, color=color,
3416-
opacity=opacity, figure=self._f, **kwargs)
3425+
opacity=opacity, figure=self._f, **mlab_kws)
34173426
return text
34183427

34193428
def remove_data(self, layer_id):

0 commit comments

Comments
 (0)