Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mne/viz/_brain/_timeviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(self, brain):
smoothing_slider = self.plotter.add_slider_widget(
set_smoothing,
value=default_smoothing_value,
rng=[1, 15], title="smoothing",
rng=[0, 15], title="smoothing",
pointa=(0.82, 0.90),
pointb=(0.98, 0.90)
)
Expand Down
2 changes: 1 addition & 1 deletion mne/viz/_brain/tests/test_brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_brain_add_data(renderer):

brain_data.add_data(hemi_data, fmin=fmin, hemi=hemi, fmax=fmax,
colormap='hot', vertices=hemi_vertices,
colorbar=False, time=None)
smoothing_steps=0, colorbar=False, time=None)
brain_data.add_data(hemi_data, fmin=fmin, hemi=hemi, fmax=fmax,
colormap='hot', vertices=hemi_vertices,
initial_time=0., colorbar=True, time=None)
Expand Down
20 changes: 20 additions & 0 deletions mne/viz/_brain/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ def mesh_edges(faces):
return edges


def _nearest(vertices, adj_mat):
from scipy.sparse.csgraph import dijkstra
# Vertices can be out of order, so sort them to start ...
order = np.argsort(vertices)
vertices = vertices[order]
_, _, sources = dijkstra(adj_mat, False, indices=vertices, min_only=True,
return_predecessors=True)
col = np.searchsorted(vertices, sources)
# ... then get things back to the correct configuration.
col = order[col]
row = np.arange(len(col))
data = np.ones(len(col))
mat = sparse.coo_matrix((data, (row, col)))
assert mat.shape == (adj_mat.shape[0], len(vertices)), mat.shape
return mat


@verbose
def smoothing_matrix(vertices, adj_mat, smoothing_steps=20, verbose=None):
"""Create a smoothing matrix.
Expand Down Expand Up @@ -67,6 +84,9 @@ def smoothing_matrix(vertices, adj_mat, smoothing_steps=20, verbose=None):

logger.info("Updating smoothing matrix, be patient..")

if smoothing_steps == 0:
return _nearest(vertices, adj_mat)

e = adj_mat.copy()
e.data[e.data == 2] = 1
n_vertices = e.shape[0]
Expand Down