Skip to content

Commit

Permalink
[MAINT] Add plot_sensors_connectivity data shape check (mne-tools#217)
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Larson <[email protected]>
  • Loading branch information
tsbinns and larsoner authored Jul 25, 2024
1 parent 91ff94b commit a250e48
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mne_connectivity/viz/_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def plot_sensors_connectivity(

renderer = _get_renderer(size=(600, 600), bgcolor=(0.5, 0.5, 0.5))

if con.ndim != 2 or con.shape[0] != con.shape[1]:
raise ValueError(
"Connectivity data must be a 2D array of shape (n_channels, n_channels), "
f"got shape {con.shape}"
)

picks = _picks_to_idx(info, picks)
if len(picks) != len(con):
raise ValueError(
Expand Down
4 changes: 4 additions & 0 deletions mne_connectivity/viz/tests/test_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def test_plot_sensors_connectivity(renderer):
info = raw.info
with pytest.raises(TypeError, match="must be an instance of Info"):
plot_sensors_connectivity(info="foo", con=con, picks=picks)
with pytest.raises(ValueError, match="Connectivity data must be a 2D array"):
plot_sensors_connectivity(info=info, con=np.expand_dims(con, 3), picks=picks)
with pytest.raises(ValueError, match="2D array of shape (n_channels, n_channels)"):
plot_sensors_connectivity(info=info, con=con[:, :-1], picks=picks)
with pytest.raises(ValueError, match="does not correspond to the size"):
plot_sensors_connectivity(info=info, con=con[::2, ::2], picks=picks)
cmap = "viridis"
Expand Down

0 comments on commit a250e48

Please sign in to comment.