Topoplots for visualizing clusters from permutation_cluster_1samp_test

Dear MNE users,

I was wondering if there are some example codes or tutorials for plotting the clusters from the permutation_cluster_1samp_test in a topomap. There is a tutorial on plotting TF plot from the output, but I could not find a way to plot topomaps from it.
Could someone please point me to the right function or tutorial I could follow. Thank you.

Best,
Manisha

1 Like

Hi, How about this example Spatiotemporal permutation F-test on full sensor data where an f_map was constructed from the cluster output (T_obs), and used to create an EvokedArray object so that topo maps could be plotted with the plot_topomap function. here is part of the relavent code.

cluster_stats = spatio_temporal_cluster_test(X, n_permutations=1000,
                                             threshold=threshold, tail=1,
                                             n_jobs=1, buffer_size=None,
                                             adjacency=adjacency)

T_obs, clusters, p_values, _ = cluster_stats
good_cluster_inds = np.where(p_values < p_accept)[0]
    f_map = T_obs[time_inds, ...].mean(axis=0)

...
# loop over clusters
for i_clu, clu_idx in enumerate(good_cluster_inds):
    # unpack cluster information, get unique indices
    time_inds, space_inds = np.squeeze(clusters[clu_idx])
    ch_inds = np.unique(space_inds)
    time_inds = np.unique(time_inds)
    # create spatial mask
    mask = np.zeros((f_map.shape[0], 1), dtype=bool)
    mask[ch_inds, :] = True

    # initialize figure
    fig, ax_topo = plt.subplots(1, 1, figsize=(10, 3))

    # plot average test statistic and mark significant sensors
    f_evoked = mne.EvokedArray(f_map[:, np.newaxis], epochs.info, tmin=0)
    f_evoked.plot_topomap(times=0, mask=mask, axes=ax_topo, cmap='Reds',
                          vmin=np.min, vmax=np.max, show=False,
                          colorbar=False, mask_params=dict(markersize=10))

Hope that helps,
Paul

3 Likes