-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
ENH: Add function to plot statistical clusters on brain surface #13366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shristibaral
wants to merge
13
commits into
mne-tools:main
Choose a base branch
from
shristibaral:plot-clusters
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+245
−5
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0c31c92
Add function to plot statistical clusters on brain surface
shristibaral 990f08e
Added enhancement PR with number
shristibaral 7ccd14f
Added newfeature PR with number
shristibaral 8e840df
Fix Error type
shristibaral 1b8edc1
change function reference
shristibaral 90b77cf
Unit test update
shristibaral 2caecf1
Update brain plot
shristibaral ec2a2ca
Merge branch 'main' into plot-clusters
shristibaral 45dc971
Merge branch 'main' into plot-clusters
shristibaral f40aab4
Updated cluster index for visualization
shristibaral 6378319
Merge branch 'main' into plot-clusters
shristibaral 8c913a4
Addressed suggestion by @wmvanvliet
shristibaral 49be698
Removed cell magic
shristibaral File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add :func:`~mne.viz.plot_stat_cluster` that plots the spatial extent of a cluster on top of a brain by `Shristi Baral`_. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ | |
plot_head_positions, | ||
plot_source_estimates, | ||
plot_sparse_source_estimates, | ||
plot_stat_cluster, | ||
snapshot_brain_montage, | ||
) | ||
from mne.viz._3d import _get_map_ticks, _linearize_map, _process_clim | ||
|
@@ -1413,3 +1414,57 @@ def test_link_brains(renderer_interactive): | |
with pytest.raises(TypeError, match="type is Brain"): | ||
link_brains("foo") | ||
link_brains(brain, time=True, camera=True) | ||
|
||
|
||
@testing.requires_testing_data | ||
def test_plot_stat_cluster(renderer_interactive): | ||
"""Test plotting clusters on brain in static and interactive mode.""" | ||
sample_src = read_source_spaces(src_fname) | ||
vertices = [s["vertno"] for s in sample_src] | ||
n_time = 5 | ||
n_verts = sum(len(v) for v in vertices) | ||
|
||
# simulate stc data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this test, I don't think it's actually needed to have STC data, we could just do: brain = Brain("sample", subjects_dir=subjects_dir, surface="white") |
||
stc_data = np.zeros(n_verts * n_time) | ||
stc_size = stc_data.size | ||
stc_data[(np.random.rand(stc_size // 20) * stc_size).astype(int)] = ( | ||
np.random.RandomState(0).rand(stc_data.size // 20) | ||
) | ||
stc_data.shape = (n_verts, n_time) | ||
stc = SourceEstimate(stc_data, vertices, 1, 1) | ||
|
||
# Simulate a cluster | ||
cluster_time_idx = [1, 1, 2, 3] | ||
cluster_vertex_idx = [0, 1, 2, 3] | ||
cluster = (cluster_time_idx, cluster_vertex_idx) | ||
|
||
brain = plot_source_estimates( | ||
stc, | ||
"sample", | ||
background=(1, 1, 0), | ||
subjects_dir=subjects_dir, | ||
colorbar=True, | ||
clim="auto", | ||
) | ||
# Test for incorrect argument in time | ||
with pytest.raises(ValueError): | ||
plot_stat_cluster(cluster, sample_src, brain, "foo") | ||
|
||
# test for incorrect shape of cluster | ||
with pytest.raises(TypeError): | ||
plot_stat_cluster(([1]), sample_src, brain) | ||
|
||
# test for incorrect data type of cluster | ||
with pytest.raises(TypeError): | ||
plot_stat_cluster([[1, 2, 3], [1, 2, 3]], sample_src, brain) | ||
|
||
# All arguments are correct | ||
plot_stat_cluster(cluster, sample_src, brain) | ||
|
||
# Check that the proper anatomical label has been constructed. | ||
assert len(brain.labels["lh"]) == 1 | ||
assert len(brain.labels["rh"]) == 0 | ||
assert brain.labels["lh"][0].name == "cluster-0" | ||
|
||
brain.close() | ||
del brain |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.