From bf4f2b3445703eabe5c88143374851e7f60dfe52 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Mon, 23 Mar 2020 12:00:22 -0400 Subject: [PATCH 1/6] MAINT: Simpler vector params --- surfer/viz.py | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/surfer/viz.py b/surfer/viz.py index 014b19a..20bf05e 100644 --- a/surfer/viz.py +++ b/surfer/viz.py @@ -1095,7 +1095,6 @@ def add_data(self, array, min=None, max=None, thresh=None, smooth_mat = None magnitude = None - magnitude_max = None if array.ndim == 3: if array.shape[1] != 3: raise ValueError('If array has 3 dimensions, array.shape[1] ' @@ -1111,7 +1110,6 @@ def add_data(self, array, min=None, max=None, thresh=None, (4 * array.shape[0] ** (0.33))) if self._units == 'm': scale_factor = scale_factor / 1000. - magnitude_max = magnitude.max() elif array.ndim not in (1, 2): raise ValueError('array has must have 1, 2, or 3 dimensions, ' 'got (%s)' % (array.ndim,)) @@ -1188,7 +1186,7 @@ def time_label(x): if brain['hemi'] == hemi: s, ct, bar, gl = brain['brain'].add_data( array, min, mid, max, thresh, lut, colormap, alpha, - colorbar, layer_id, smooth_mat, magnitude, magnitude_max, + colorbar, layer_id, smooth_mat, magnitude, scale_factor, vertices, vector_alpha, **kwargs) surfs.append(s) bars.append(bar) @@ -2115,13 +2113,11 @@ def set_data_time_index(self, time_idx, interpolation='quadratic'): if vectors is not None: vectors = vectors[:, :, time_idx] - vector_values = scalar_data.copy() if data['smooth_mat'] is not None: scalar_data = data['smooth_mat'] * scalar_data for brain in self.brains: if brain.hemi == hemi: - brain.set_data(data['layer_id'], scalar_data, - vectors, vector_values) + brain.set_data(data['layer_id'], scalar_data, vectors) del brain data["time_idx"] = time_idx @@ -3225,24 +3221,23 @@ def _remove_scalar_data(self, array_id): self._mesh_clones.pop(array_id).remove() self._mesh_dataset.point_data.remove_array(array_id) - def _add_vector_data(self, vectors, vector_values, fmin, fmid, fmax, - scale_factor_norm, vertices, vector_alpha, lut): + def _add_vector_data(self, vectors, fmin, fmid, fmax, + scale_factor, vertices, vector_alpha, lut): vertices = slice(None) if vertices is None else vertices x, y, z = np.array(self._geo_mesh.data.points.data)[vertices].T vector_alpha = min(vector_alpha, 0.9999999) with warnings.catch_warnings(record=True): # HasTraits quiver = mlab.quiver3d( x, y, z, vectors[:, 0], vectors[:, 1], vectors[:, 2], - scalars=vector_values, colormap='hot', vmin=fmin, + colormap='hot', vmin=fmin, scale_mode='vector', vmax=fmax, figure=self._f, opacity=vector_alpha) # Enable backface culling quiver.actor.property.backface_culling = True quiver.mlab_source.update() - # Compute scaling for the glyphs - quiver.glyph.glyph.scale_factor = (scale_factor_norm * - vector_values.max()) + # Set scaling for the glyphs + quiver.glyph.glyph.scale_factor = scale_factor # Scale colormap used for the glyphs l_m = quiver.parent.vector_lut_manager @@ -3293,7 +3288,7 @@ def add_overlay(self, old, **kwargs): @verbose def add_data(self, array, fmin, fmid, fmax, thresh, lut, colormap, alpha, - colorbar, layer_id, smooth_mat, magnitude, magnitude_max, + colorbar, layer_id, smooth_mat, magnitude, scale_factor, vertices, vector_alpha, **kwargs): """Add data to the brain""" # Calculate initial data to plot @@ -3308,7 +3303,6 @@ def add_data(self, array, fmin, fmid, fmax, thresh, lut, colormap, alpha, array_plot = magnitude[:, 0] else: raise ValueError("data has to be 1D, 2D, or 3D") - vector_values = array_plot if smooth_mat is not None: array_plot = smooth_mat * array_plot @@ -3316,16 +3310,13 @@ def add_data(self, array, fmin, fmid, fmax, thresh, lut, colormap, alpha, array_plot = _prepare_data(array_plot) array_id, pipe = self._add_scalar_data(array_plot) - scale_factor_norm = None if array.ndim == 3: - scale_factor_norm = scale_factor / magnitude_max vectors = array[:, :, 0].copy() glyphs = self._add_vector_data( - vectors, vector_values, fmin, fmid, fmax, - scale_factor_norm, vertices, vector_alpha, lut) + vectors, fmin, fmid, fmax, + scale_factor, vertices, vector_alpha, lut) else: glyphs = None - del scale_factor mesh = pipe.parent if thresh is not None: if array_plot.min() >= thresh: @@ -3364,7 +3355,7 @@ def add_data(self, array, fmin, fmid, fmax, thresh, lut, colormap, alpha, self.data[layer_id] = dict( array_id=array_id, mesh=mesh, glyphs=glyphs, - scale_factor_norm=scale_factor_norm) + scale_factor=scale_factor) return surf, orig_ctable, bar, glyphs def add_annotation(self, annot, ids, cmap, **kwargs): @@ -3475,7 +3466,7 @@ def remove_data(self, layer_id): self._remove_scalar_data(data['array_id']) self._remove_vector_data(data['glyphs']) - def set_data(self, layer_id, values, vectors=None, vector_values=None): + def set_data(self, layer_id, values, vectors=None): """Set displayed data values and vectors.""" data = self.data[layer_id] self._mesh_dataset.point_data.get_array( @@ -3492,12 +3483,10 @@ def set_data(self, layer_id, values, vectors=None, vector_values=None): # Update glyphs q.mlab_source.vectors = vectors - q.mlab_source.scalars = vector_values q.mlab_source.update() # Update changed parameters, and glyph scaling - q.glyph.glyph.scale_factor = (data['scale_factor_norm'] * - values.max()) + q.glyph.glyph.scale_factor = data['scale_factor'] l_m.load_lut_from_list(lut / 255.) l_m.data_range = data_range From 1e92ac6f2c2ccaa4308b7629aeea16d1e97bde31 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Mon, 23 Mar 2020 13:11:58 -0400 Subject: [PATCH 2/6] FIX: Undo auto scaling --- surfer/viz.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/surfer/viz.py b/surfer/viz.py index 20bf05e..2ab0db0 100644 --- a/surfer/viz.py +++ b/surfer/viz.py @@ -1101,8 +1101,7 @@ def add_data(self, array, min=None, max=None, thresh=None, 'must equal 3, got %s' % (array.shape[1],)) magnitude = np.linalg.norm(array, axis=1) if scale_factor is None: - distance = np.sum([array[:, dim, :].ptp(axis=0).max() ** 2 - for dim in range(3)]) + distance = 4 * np.linalg.norm(array, axis=1).max() if distance == 0: scale_factor = 1 else: @@ -3238,6 +3237,9 @@ def _add_vector_data(self, vectors, fmin, fmid, fmax, # Set scaling for the glyphs quiver.glyph.glyph.scale_factor = scale_factor + quiver.glyph.glyph.scale_factor = scale_factor + quiver.glyph.glyph.clamping = False + quiver.glyph.glyph.range = (0., 1.) # Scale colormap used for the glyphs l_m = quiver.parent.vector_lut_manager @@ -3487,6 +3489,8 @@ def set_data(self, layer_id, values, vectors=None): # Update changed parameters, and glyph scaling q.glyph.glyph.scale_factor = data['scale_factor'] + q.glyph.glyph.range = (0., 1.) + q.glyph.glyph.clamping = False l_m.load_lut_from_list(lut / 255.) l_m.data_range = data_range From 8850212683e22d6055c5cf5a8a6724d22b23abe2 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Mon, 23 Mar 2020 13:22:10 -0400 Subject: [PATCH 3/6] FIX: Dup --- surfer/viz.py | 1 - 1 file changed, 1 deletion(-) diff --git a/surfer/viz.py b/surfer/viz.py index 2ab0db0..f991968 100644 --- a/surfer/viz.py +++ b/surfer/viz.py @@ -3237,7 +3237,6 @@ def _add_vector_data(self, vectors, fmin, fmid, fmax, # Set scaling for the glyphs quiver.glyph.glyph.scale_factor = scale_factor - quiver.glyph.glyph.scale_factor = scale_factor quiver.glyph.glyph.clamping = False quiver.glyph.glyph.range = (0., 1.) From bc2c73479faa240a5ad9c6f8787587aa6b790f55 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Mon, 23 Mar 2020 14:17:49 -0400 Subject: [PATCH 4/6] FIX: URL --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ca83d67..569e241 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,7 +50,7 @@ before_install: pip install https://github.com/enthought/mayavi/zipball/master; fi; - mkdir -p $SUBJECTS_DIR - - pip install "https://api.github.com/repos/mne-tools/mne-python/zipball/master"; + - pip install "https://github.com/mne-tools/mne-python/archive/master.zip" - python -c "import mne; mne.datasets.fetch_fsaverage(verbose=True)" install: From 0aa82d8324f5faa962e9a049b28611f4e44cda5d Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Mon, 23 Mar 2020 14:22:02 -0400 Subject: [PATCH 5/6] FIX: Better --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0071f48..18f52af 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -49,7 +49,7 @@ jobs: command: | python -m pip install --user -q --upgrade pip numpy 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 - python -m pip install --user -q --upgrade mayavi "https://api.github.com/repos/mne-tools/mne-python/zipball/master" + python -m pip install --user -q --upgrade mayavi "https://github.com/mne-tools/mne-python/archive/master.zip" - save_cache: key: pip-cache paths: From 13ae095f6c3ba6a922047e1e47d1baa5366cdd7e Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Tue, 23 Jun 2020 10:05:26 -0400 Subject: [PATCH 6/6] FIX: More tolerant of type --- surfer/viz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/surfer/viz.py b/surfer/viz.py index f991968..e42c491 100644 --- a/surfer/viz.py +++ b/surfer/viz.py @@ -423,7 +423,7 @@ def __init__(self, subject_id, hemi, surf, title=None, title = subject_id self.subject_id = subject_id - if not isinstance(views, list): + if not isinstance(views, (list, tuple)): views = [views] n_row = len(views)