def test_plot_source_spectrogram(): """Test plotting of source spectrogram """ sample_src = read_source_spaces(op.join(data_dir, 'subjects', 'sample', 'bem', 'sample-oct-6-src.fif')) # dense version vertices = [s['vertno'] for s in sample_src] n_time = 5 n_verts = sum(len(v) for v in vertices) stc_data = np.ones((n_verts, n_time)) stc = SourceEstimate(stc_data, vertices, 1, 1) plot_source_spectrogram([stc, stc], [[1, 2], [3, 4]]) assert_raises(ValueError, plot_source_spectrogram, [], [])
def test_plot_source_spectrogram(): """Test plotting of source spectrogram """ sample_src = read_source_spaces( op.join(data_dir, 'subjects', 'sample', 'bem', 'sample-oct-6-src.fif')) # dense version vertices = [s['vertno'] for s in sample_src] n_time = 5 n_verts = sum(len(v) for v in vertices) stc_data = np.ones((n_verts, n_time)) stc = SourceEstimate(stc_data, vertices, 1, 1) plot_source_spectrogram([stc, stc], [[1, 2], [3, 4]]) assert_raises(ValueError, plot_source_spectrogram, [], [])
def test_plot_source_spectrogram(): """Test plotting of source spectrogram.""" sample_src = read_source_spaces(op.join(subjects_dir, 'sample', 'bem', 'sample-oct-6-src.fif')) # dense version vertices = [s['vertno'] for s in sample_src] n_times = 5 n_verts = sum(len(v) for v in vertices) stc_data = np.ones((n_verts, n_times)) stc = SourceEstimate(stc_data, vertices, 1, 1) plot_source_spectrogram([stc, stc], [[1, 2], [3, 4]]) pytest.raises(ValueError, plot_source_spectrogram, [], []) pytest.raises(ValueError, plot_source_spectrogram, [stc, stc], [[1, 2], [3, 4]], tmin=0) pytest.raises(ValueError, plot_source_spectrogram, [stc, stc], [[1, 2], [3, 4]], tmax=7) plt.close('all')
# desired baseline length, and 0 for tmax_plot. # Note, if using baseline data, the averaged evoked response in the baseline # period should be flat. noise_covs = [] for (l_freq, h_freq) in freq_bins: raw_band = raw_noise.copy() raw_band.filter(l_freq, h_freq, picks=epochs.picks, method='iir', n_jobs=1) epochs_band = mne.Epochs(raw_band, epochs_noise.events, event_id, tmin=tmin_plot, tmax=tmax_plot, baseline=None, picks=epochs.picks, proj=True) noise_cov = compute_covariance(epochs_band) noise_cov = mne.cov.regularize(noise_cov, epochs_band.info, mag=noise_reg, grad=noise_reg, eeg=noise_reg, proj=True) noise_covs.append(noise_cov) del raw_band # to save memory # Computing LCMV solutions for time-frequency windows in a label in source # space for faster computation, use label=None for full solution stcs = tf_lcmv(epochs, forward, noise_covs, tmin, tmax, tstep, win_lengths, freq_bins=freq_bins, subtract_evoked=subtract_evoked, reg=data_reg, label=label) # Plotting source spectrogram for source with maximum activity. # Note that tmin and tmax are set to display a time range that is smaller than # the one for which beamforming estimates were calculated. This ensures that # all time bins shown are a result of smoothing across an identical number of # time windows. plot_source_spectrogram(stcs, freq_bins, tmin=tmin_plot, tmax=tmax_plot, source_index=None, colorbar=True)
tmax=tmax, picks=epochs.picks, proj=True) noise_cov = compute_covariance(epochs_band) noise_cov = mne.cov.regularize(noise_cov, epochs_band.info, mag=noise_reg, grad=noise_reg, eeg=noise_reg, proj=True) noise_covs.append(noise_cov) del raw_band # to save memory # Computing LCMV solutions for time-frequency windows in a label in source # space for faster computation, use label=None for full solution stcs = tf_lcmv(epochs, forward, noise_covs, tmin, tmax, tstep, win_lengths, freq_bins=freq_bins, subtract_evoked=subtract_evoked, reg=data_reg, label=label) # Plotting source spectrogram for source with maximum activity plot_source_spectrogram(stcs, freq_bins, source_index=None, colorbar=True)
eeg=noise_reg, proj=True) noise_covs.append(noise_cov) del raw_band # to save memory # Computing LCMV solutions for time-frequency windows in a label in source # space for faster computation, use label=None for full solution stcs = tf_lcmv(epochs, forward, noise_covs, tmin, tmax, tstep, win_lengths, freq_bins=freq_bins, subtract_evoked=subtract_evoked, reg=data_reg, label=label) # Plotting source spectrogram for source with maximum activity. # Note that tmin and tmax are set to display a time range that is smaller than # the one for which beamforming estimates were calculated. This ensures that # all time bins shown are a result of smoothing across an identical number of # time windows. plot_source_spectrogram(stcs, freq_bins, tmin=tmin_plot, tmax=tmax_plot, source_index=None, colorbar=True)
# Setting time windows, please note tmin stretches over the baseline, which is # selected to be as long as the longest time window. This enables a smooth and # accurate localization of activity in time tmin = -0.3 # s tmax = 0.5 # s tstep = 0.05 # s # Subtract evoked response prior to computation? subtract_evoked = False # Calculating noise cross-spectral density from empty room noise for each # frequency bin and the corresponding time window length. To calculate noise # from the baseline period in the data, change epochs_noise to epochs noise_csds = [] for freq_bin, win_length, n_fft in zip(freq_bins, win_lengths, n_ffts): noise_csd = compute_epochs_csd(epochs_noise, mode='fourier', fmin=freq_bin[0], fmax=freq_bin[1], fsum=True, tmin=tmin, tmax=tmin + win_length, n_fft=n_fft) noise_csds.append(noise_csd) # Computing DICS solutions for time-frequency windows in a label in source # space for faster computation, use label=None for full solution stcs = tf_dics(epochs, forward, noise_csds, tmin, tmax, tstep, win_lengths, freq_bins=freq_bins, subtract_evoked=subtract_evoked, n_ffts=n_ffts, reg=0.001, label=label) # Plotting source spectrogram for source with maximum activity plot_source_spectrogram(stcs, freq_bins, source_index=None, colorbar=True)
cwt_n_cycles=cwt_n_cycles, reg=0.05, label=label, pick_ori='max-power', inversion='single', depth=1.0, n_jobs=n_jobs) coll_stcs_neg.append(stcs_neg) for fb in range(len(freq_bins)): stcs_neg[fb].save("{}{}_TF_dics_neg_{}-{}_{}-stc.h5".format( save_dir, meg, freq_bins[fb][0], freq_bins[fb][-1], loi)) fig_n = plot_source_spectrogram(stcs_neg, freq_bins, tmin=tmin_plot, tmax=tmax_plot, source_index=None, colorbar=True, cmap='hot_r', vmin=0, vmax=6e-26, show=False) # freq_bins! or error fig_n.savefig("{}{}_neg_{}.png".format(plot_dir, meg, loi)) stcs_pos = tf_dics(epo['positive'], fwd, noise_csds=None, tmin=tmin, tmax=tmax, tstep=tstep, win_lengths=win_lengths, subtract_evoked=False, mode='cwt_morlet', frequencies=frequencies,