fwd, csd, reduce_rank=True, pick_ori='max-power', inversion='matrix', reg=reg[subject]['dics']) # Compute source power stc_baseline, _ = mne.beamformer.apply_dics_csd(csd_baseline, inv) stc_ers, _ = mne.beamformer.apply_dics_csd(csd_ers, inv) stc_baseline.subject = fname.subject_id(subject=subject) stc_ers.subject = fname.subject_id(subject=subject) # Normalize with baseline power. stc_ers /= stc_baseline stc_ers.data = np.log(stc_ers.data) stc_ers.save(fname.stc_dics(subject=subject)) stc_ers.save_as_volume(fname.nii_dics(subject=subject), src=fwd['src']) fig = stc_ers.plot(subject=fname.subject_id(subject=subject), subjects_dir=fname.subjects_dir, src=fwd['src']) with mne.open_report(fname.report(subject=subject)) as report: report.add_figs_to_section(fig, 'DICS Source estimate', 'Source level', replace=True) report.save(fname.report_html(subject=subject), overwrite=True, open_browser=False)
import mne import argparse import numpy as np from config import fname, events_id, subjects_with_extra_stim_artifacts, stim_artifact_sensor, n_jobs # Handle command line arguments parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('subject', metavar='sub###', type=int, help='The subject to process') args = parser.parse_args() subject = args.subject print('Processing subject:', subject) report = mne.open_report(fname.report(subject=subject)) raw = mne.io.read_raw_fif(fname.raw_filt(subject=subject)) ica = mne.preprocessing.read_ica(fname.ica(subject=subject)) # Create short epochs for evoked analysis events = mne.find_events(raw, shortest_event=0.01) epochs = mne.Epochs(raw, events, events_id, tmin=-0.2, tmax=0.5, reject=None, baseline=(-0.2, 0), preload=True) report.add_figs_to_section(epochs.average().plot_joint(times=[0.035, 0.1]), ['Evokeds without cleaning (grads)', 'Evokeds without cleaning (mags)'], 'Sensor level', replace=True) # Apply ICA to remove EOG and ECG artifacts epochs = ica.apply(epochs) # Do a first pass for fixing the stim artifact mne.preprocessing.fix_stim_artifact(epochs) epochs.save(fname.epochs(subject=subject), overwrite=True) # For some subjects, there are more stim artifacts that we need to remove using ICA if subject in subjects_with_extra_stim_artifacts:
############################################################################### # 7) Create HTML report blocks_duration = '<p>Block 1 Duration from %s to %s seconds.<br>'\ 'Block 1 length: %s seconds<p>'\ '<p>Block 2 Duration from %s to %s seconds.<br>'\ 'Block 2 length: %s seconds<p>' \ '<p>Block 2 Duration from %s to %s seconds.<br>' \ 'Block 3 length: %s seconds<p>' \ '<p>Block 2 Duration from %s to %s seconds.<br>' \ 'Block 4 length: %s seconds<p>' \ % (round(b1s, 2), round(b1e, 2), round(b1e - b1s, 2), round(b2s, 2), round(b2e, 2), round(b2e - b2s, 2), round(b3s, 2), round(b3e, 2), round(b3e - b3s, 2), round(b4s, 2), round(b4e, 2), round(b4e - b4s, 2)) with open_report(fname.report(subject=subject)[0]) as report: report.add_htmls_to_section(htmls=blocks_duration, captions='Block durations', section='Filtered data') report.add_figs_to_section(fig, 'Blocks PSD', section='Filtered data', replace=True) report.add_figs_to_section(filt_plot, 'Filtered data', section='Filtered data', replace=True) report.save(fname.report(subject=subject)[1], overwrite=True, open_browser=False)
er_raw = mne.io.read_raw_fif(fname.ernoise, preload=True) raw_picks = mne.pick_types(raw.info, meg=True, eeg=False) er_raw_picks = mne.pick_types(er_raw.info, meg=True, eeg=False) raw._data[raw_picks] += er_raw._data[er_raw_picks, :len(raw.times)] ############################################################################### # Save everything ############################################################################### raw.save(fname.simulated_raw(noise=config.noise, vertex=config.vertex), overwrite=True) ############################################################################### # Plot it! ############################################################################### with mne.open_report(fname.report(noise=config.noise, vertex=config.vertex)) as report: fig = plt.figure() plt.plot(times, generate_signal(times, freq=10)) plt.xlabel('Time (s)') report.add_figs_to_section(fig, 'Signal time course', section='Sensor-level', replace=True) fig = raw.plot() report.add_figs_to_section(fig, 'Simulated raw', section='Sensor-level', replace=True) report.save(fname.report_html(noise=config.noise, vertex=config.vertex), overwrite=True,
# Handle command line arguments parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('subject', metavar='sub###', help='The subject to process') args = parser.parse_args() subject = args.subject print('Processing subject:', subject) # Read the epochs print('Reading epochs...') epochs = mne.read_epochs(fname.epo(subject=subject)) # Suppress warning about wavelet length. warnings.simplefilter('ignore') # Load the report to add figures to report = mne.open_report(fname.report(subject=subject)) # Individual frequencies to estimate the CSD for fmin = freq_bands[0][0] fmax = freq_bands[-1][1] frequencies = np.arange(fmin, fmax + 1, 2) # Compute CSD matrices for each frequency and each condition. for condition in conditions: print('Condition:', condition) # Remove the mean during the time interval for which we compute the CSD epochs_baselined = epochs[condition].apply_baseline((csd_tmin, csd_tmax)) # Compute CSD for the desired time interval csd = csd_morlet(epochs_baselined, frequencies=frequencies,
# output path output_path = fname.output(processing_step='task_blocks', subject=subject, file_type='raw.fif') # sample down and save file raw_bl_filt.save(output_path, overwrite=True) ############################################################################### # 7) Create HTML report blocks_duration = '<p>Block 1 Duration from %s to %s seconds.<br>'\ 'Block 1 length: %s seconds<p>'\ '<p>Block 2 Duration from %s to %s seconds.<br>'\ 'Block 2 length: %s seconds<p>' \ % (round(b1s, 2), round(b1e, 2), round(b1e - b1s, 2), round(b2s, 2), round(b2e, 2), round(b2e - b2s, 2)) with open_report(fname.report(subject=subject)[0]) as report: report.add_htmls_to_section(htmls=blocks_duration, captions='Block durations', section='Filtered data') report.add_figs_to_section(fig, 'Blocks PSD', section='Filtered data', replace=True) report.add_figs_to_section(filt_plot, 'Filtered data', section='Filtered data', replace=True) report.save(fname.report(subject=subject)[1], overwrite=True, open_browser=False)