Skip to content

Commit 9e5fe1f

Browse files
authored
MRG, MAINT: Simpler vector params (#291)
* MAINT: Simpler vector params * FIX: Undo auto scaling * FIX: Dup * FIX: URL * FIX: Better * FIX: More tolerant of type
1 parent b0ca3a1 commit 9e5fe1f

File tree

3 files changed

+21
-29
lines changed

3 files changed

+21
-29
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
command: |
5050
python -m pip install --user -q --upgrade pip numpy
5151
python -m pip install --user -q --upgrade --progress-bar off scipy matplotlib vtk pyqt5 pyqt5-sip nibabel sphinx numpydoc pillow imageio imageio-ffmpeg sphinx-gallery
52-
python -m pip install --user -q --upgrade mayavi "https://api.github.com/repos/mne-tools/mne-python/zipball/master"
52+
python -m pip install --user -q --upgrade mayavi "https://github.com/mne-tools/mne-python/archive/master.zip"
5353
- save_cache:
5454
key: pip-cache
5555
paths:

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ before_install:
5050
pip install https://github.com/enthought/mayavi/zipball/master;
5151
fi;
5252
- mkdir -p $SUBJECTS_DIR
53-
- pip install "https://api.github.com/repos/mne-tools/mne-python/zipball/master";
53+
- pip install "https://github.com/mne-tools/mne-python/archive/master.zip"
5454
- python -c "import mne; mne.datasets.fetch_fsaverage(verbose=True)"
5555

5656
install:

surfer/viz.py

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def __init__(self, subject_id, hemi, surf, title=None,
423423
title = subject_id
424424
self.subject_id = subject_id
425425

426-
if not isinstance(views, list):
426+
if not isinstance(views, (list, tuple)):
427427
views = [views]
428428
n_row = len(views)
429429

@@ -1095,23 +1095,20 @@ def add_data(self, array, min=None, max=None, thresh=None,
10951095
smooth_mat = None
10961096

10971097
magnitude = None
1098-
magnitude_max = None
10991098
if array.ndim == 3:
11001099
if array.shape[1] != 3:
11011100
raise ValueError('If array has 3 dimensions, array.shape[1] '
11021101
'must equal 3, got %s' % (array.shape[1],))
11031102
magnitude = np.linalg.norm(array, axis=1)
11041103
if scale_factor is None:
1105-
distance = np.sum([array[:, dim, :].ptp(axis=0).max() ** 2
1106-
for dim in range(3)])
1104+
distance = 4 * np.linalg.norm(array, axis=1).max()
11071105
if distance == 0:
11081106
scale_factor = 1
11091107
else:
11101108
scale_factor = (0.4 * distance /
11111109
(4 * array.shape[0] ** (0.33)))
11121110
if self._units == 'm':
11131111
scale_factor = scale_factor / 1000.
1114-
magnitude_max = magnitude.max()
11151112
elif array.ndim not in (1, 2):
11161113
raise ValueError('array has must have 1, 2, or 3 dimensions, '
11171114
'got (%s)' % (array.ndim,))
@@ -1188,7 +1185,7 @@ def time_label(x):
11881185
if brain['hemi'] == hemi:
11891186
s, ct, bar, gl = brain['brain'].add_data(
11901187
array, min, mid, max, thresh, lut, colormap, alpha,
1191-
colorbar, layer_id, smooth_mat, magnitude, magnitude_max,
1188+
colorbar, layer_id, smooth_mat, magnitude,
11921189
scale_factor, vertices, vector_alpha, **kwargs)
11931190
surfs.append(s)
11941191
bars.append(bar)
@@ -2115,13 +2112,11 @@ def set_data_time_index(self, time_idx, interpolation='quadratic'):
21152112
if vectors is not None:
21162113
vectors = vectors[:, :, time_idx]
21172114

2118-
vector_values = scalar_data.copy()
21192115
if data['smooth_mat'] is not None:
21202116
scalar_data = data['smooth_mat'] * scalar_data
21212117
for brain in self.brains:
21222118
if brain.hemi == hemi:
2123-
brain.set_data(data['layer_id'], scalar_data,
2124-
vectors, vector_values)
2119+
brain.set_data(data['layer_id'], scalar_data, vectors)
21252120
del brain
21262121
data["time_idx"] = time_idx
21272122

@@ -3225,24 +3220,25 @@ def _remove_scalar_data(self, array_id):
32253220
self._mesh_clones.pop(array_id).remove()
32263221
self._mesh_dataset.point_data.remove_array(array_id)
32273222

3228-
def _add_vector_data(self, vectors, vector_values, fmin, fmid, fmax,
3229-
scale_factor_norm, vertices, vector_alpha, lut):
3223+
def _add_vector_data(self, vectors, fmin, fmid, fmax,
3224+
scale_factor, vertices, vector_alpha, lut):
32303225
vertices = slice(None) if vertices is None else vertices
32313226
x, y, z = np.array(self._geo_mesh.data.points.data)[vertices].T
32323227
vector_alpha = min(vector_alpha, 0.9999999)
32333228
with warnings.catch_warnings(record=True): # HasTraits
32343229
quiver = mlab.quiver3d(
32353230
x, y, z, vectors[:, 0], vectors[:, 1], vectors[:, 2],
3236-
scalars=vector_values, colormap='hot', vmin=fmin,
3231+
colormap='hot', vmin=fmin, scale_mode='vector',
32373232
vmax=fmax, figure=self._f, opacity=vector_alpha)
32383233

32393234
# Enable backface culling
32403235
quiver.actor.property.backface_culling = True
32413236
quiver.mlab_source.update()
32423237

3243-
# Compute scaling for the glyphs
3244-
quiver.glyph.glyph.scale_factor = (scale_factor_norm *
3245-
vector_values.max())
3238+
# Set scaling for the glyphs
3239+
quiver.glyph.glyph.scale_factor = scale_factor
3240+
quiver.glyph.glyph.clamping = False
3241+
quiver.glyph.glyph.range = (0., 1.)
32463242

32473243
# Scale colormap used for the glyphs
32483244
l_m = quiver.parent.vector_lut_manager
@@ -3293,7 +3289,7 @@ def add_overlay(self, old, **kwargs):
32933289

32943290
@verbose
32953291
def add_data(self, array, fmin, fmid, fmax, thresh, lut, colormap, alpha,
3296-
colorbar, layer_id, smooth_mat, magnitude, magnitude_max,
3292+
colorbar, layer_id, smooth_mat, magnitude,
32973293
scale_factor, vertices, vector_alpha, **kwargs):
32983294
"""Add data to the brain"""
32993295
# Calculate initial data to plot
@@ -3308,24 +3304,20 @@ def add_data(self, array, fmin, fmid, fmax, thresh, lut, colormap, alpha,
33083304
array_plot = magnitude[:, 0]
33093305
else:
33103306
raise ValueError("data has to be 1D, 2D, or 3D")
3311-
vector_values = array_plot
33123307
if smooth_mat is not None:
33133308
array_plot = smooth_mat * array_plot
33143309

33153310
# Copy and byteswap to deal with Mayavi bug
33163311
array_plot = _prepare_data(array_plot)
33173312

33183313
array_id, pipe = self._add_scalar_data(array_plot)
3319-
scale_factor_norm = None
33203314
if array.ndim == 3:
3321-
scale_factor_norm = scale_factor / magnitude_max
33223315
vectors = array[:, :, 0].copy()
33233316
glyphs = self._add_vector_data(
3324-
vectors, vector_values, fmin, fmid, fmax,
3325-
scale_factor_norm, vertices, vector_alpha, lut)
3317+
vectors, fmin, fmid, fmax,
3318+
scale_factor, vertices, vector_alpha, lut)
33263319
else:
33273320
glyphs = None
3328-
del scale_factor
33293321
mesh = pipe.parent
33303322
if thresh is not None:
33313323
if array_plot.min() >= thresh:
@@ -3364,7 +3356,7 @@ def add_data(self, array, fmin, fmid, fmax, thresh, lut, colormap, alpha,
33643356

33653357
self.data[layer_id] = dict(
33663358
array_id=array_id, mesh=mesh, glyphs=glyphs,
3367-
scale_factor_norm=scale_factor_norm)
3359+
scale_factor=scale_factor)
33683360
return surf, orig_ctable, bar, glyphs
33693361

33703362
def add_annotation(self, annot, ids, cmap, **kwargs):
@@ -3475,7 +3467,7 @@ def remove_data(self, layer_id):
34753467
self._remove_scalar_data(data['array_id'])
34763468
self._remove_vector_data(data['glyphs'])
34773469

3478-
def set_data(self, layer_id, values, vectors=None, vector_values=None):
3470+
def set_data(self, layer_id, values, vectors=None):
34793471
"""Set displayed data values and vectors."""
34803472
data = self.data[layer_id]
34813473
self._mesh_dataset.point_data.get_array(
@@ -3492,12 +3484,12 @@ def set_data(self, layer_id, values, vectors=None, vector_values=None):
34923484

34933485
# Update glyphs
34943486
q.mlab_source.vectors = vectors
3495-
q.mlab_source.scalars = vector_values
34963487
q.mlab_source.update()
34973488

34983489
# Update changed parameters, and glyph scaling
3499-
q.glyph.glyph.scale_factor = (data['scale_factor_norm'] *
3500-
values.max())
3490+
q.glyph.glyph.scale_factor = data['scale_factor']
3491+
q.glyph.glyph.range = (0., 1.)
3492+
q.glyph.glyph.clamping = False
35013493
l_m.load_lut_from_list(lut / 255.)
35023494
l_m.data_range = data_range
35033495

0 commit comments

Comments
 (0)