Below is the example code I used:
import os
import numpy as np
import mne
sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = os.path.join(sample_data_folder, 'MEG', 'sample',
'sample_audvis_filt-0-40_raw.fif')
raw = mne.io.read_raw_fif(sample_data_raw_file)
ica = mne.preprocessing.ICA(n_components=20, random_state=97, max_iter=800)
ica.fit(raw)
ica.exclude = [1, 2] # details on how we picked these are omitted here
ica.plot_properties(raw, picks=ica.exclude)
entr = np.zeros([dat.shape[0],1])
N=10000 # take 10000 as a quick test
for i in range(dat.shape[0]):
print(i)
ts=dat[i,:N]
#en = entropy(ts) # entropy is my code
entr[i]=en
meginfo=mne.pick_info(raw.info, meg_channel_indices)
megidx=mne.pick_types(raw.info, meg='mag', eeg=False, exclude=[])
meginfo=mne.pick_info(raw.info, megidx)
mne.viz.plot_topomap(np.squeeze(entr[megidx]), meginfo, ch_type='meg', cmap='Spectral_r',extrapolate='head',sensors = True)