def import_evokes(evokes_fname): import importlib import mne mu.add_mmvt_code_root_to_path() from src.preproc import meg importlib.reload(meg) opt_trans_files = glob.glob( op.join(mu.get_parent_fol(evokes_fname), '*.fif')) trans_files = meg.filter_trans_files(opt_trans_files) trans_file = mu.select_one_file(trans_files, template='*.fif', files_desc='MRI-Head transformation') args = mu.get_remote_subject_info_args() evokes = mne.read_evokeds(evokes_fname) events_keys = [ev.comment for ev in evokes] meg.read_sensors_layout(mu.get_user(), args, info=evokes[0].info, trans_file=trans_file) meg.save_evokes_to_mmvt(evokes, events_keys, mu.get_user()) _addon().import_meg_sensors() _addon().add_data_to_meg_sensors() # _addon().load_all_panels() _addon().show_meg_sensors()
def read_sensors_layout_args(mri_subject, args): return meg.read_sensors_layout(mri_subject, args, pick_meg=False, pick_eeg=True, overwrite_sensors=args.overwrite_sensors, raw_template=args.raw_template, trans_file=args.trans_fname, info_fname=args.info_fname, read_info_file=args.read_info_file, raw_fname=args.raw_fname)
def read_sensors_layout(mri_subject, args=None, overwrite_sensors=False, raw_template='', trans_file='', info_fname='', info=None, read_info_file=True, raw_fname=''): return meg.read_sensors_layout(mri_subject, args, overwrite_sensors=overwrite_sensors, pick_meg=False, pick_eeg=True, trans_file=trans_file, info=info, info_fname=info_fname, read_info_file=read_info_file, raw_template=raw_template, raw_fname=raw_fname)
def read_eeg_sensors_layout(subject, mri_subject, args): return meg.read_sensors_layout(subject, mri_subject, args, pick_meg=False, pick_eeg=True)
def analyze_meg(subject, seizure_time, seizure_len): raw, evoked = None, None meg_raw_fnames = [ op.join(MEG_ROOT, 'nmr01209_6213848_07', 'nmr01209_6213848_07_Resting_eeg_meg_ica-raw.fif'), op.join(MEG_DIR, subject, 'nmr01209_6213848_07_Resting_eeg_meg_ica-raw.fif') ] meg_raw_fname = [f for f in meg_raw_fnames if op.isfile(f)][0] # empty_room_fname = '/space/megraid/77/MEG/noise/no_name/' meg_raw_fname_seizure = op.join(MEG_DIR, subject, '{}_meg_seizure-raw.fif'.format(subject)) meg_evoked_fname = op.join(MEG_DIR, subject, '{}_meg_seizure-ave.fif'.format(subject)) eeg_evoked_fname = op.join(MEG_DIR, subject, '{}_eeg_seizure-ave.fif'.format(subject)) meeg_evoked_fname = op.join(MEG_DIR, subject, '{}_meeg_seizure-ave.fif'.format(subject)) if not op.isfile(meg_raw_fname_seizure): raw = mne.io.read_raw_fif(meg_raw_fname) raw.set_eeg_reference('average', projection=True) # set EEG average reference raw = raw.crop(seizure_time - 2, seizure_time + seizure_len) raw.save(meg_raw_fname_seizure) # raw.plot(block=True) # raw.plot(butterfly=True, group_by='position') meg.read_sensors_layout(subject, info=raw.info, overwrite_sensors=False) eeg.read_sensors_layout(subject, info=raw.info, overwrite_sensors=False) if not op.isfile(meg_evoked_fname) or not op.isfile( eeg_evoked_fname) or not op.isfile(meeg_evoked_fname): if raw is None: raw = mne.io.read_raw_fif(meg_raw_fname_seizure) evoked = mne.EvokedArray(raw.get_data(), raw.info, comment='seizure') meeg_evoked = evoked.pick_types(meg=True, eeg=True) mne.write_evokeds(meeg_evoked_fname, meeg_evoked) eeg_evoked = evoked.pick_types(meg=False, eeg=True) mne.write_evokeds(eeg_evoked_fname, eeg_evoked) meg.save_evokes_to_mmvt(eeg_evoked, [1], subject, modality='eeg') meg_evoked = evoked.pick_types(meg=True, eeg=False) mne.write_evokeds(meg_evoked_fname, meg_evoked) meg.save_evokes_to_mmvt(evoked, [1], subject, modality='meg') meg.create_helmet_mesh(subject, overwrite_faces_verts=True) eeg.create_helmet_mesh(subject, overwrite_faces_verts=True) overwrite_source_bem = False args = meg.read_cmd_args( dict( subject=subject, function= 'make_forward_solution,calc_inverse_operator,calc_stc,calc_labels_avg_per_condition', atlas='electrodes_labels', evo_fname=meeg_evoked_fname, # recreate_src_spacing='ico5', # fwd_recreate_source_space=overwrite_source_bem, # recreate_bem_solution=overwrite_source_bem, contrast='seizure', task='seizure', raw_fname=meg_raw_fname_seizure, use_empty_room_for_noise_cov=True, empty_fname='empty_room_raw.fif', # overwrite_fwd=True overwrite_stc=False, overwrite_labels_data=True, # pick_meg=True, pick_eeg=False, # fwd_usingMEG=True, fwd_usingEEG=False, )) meg.call_main(args)
def read_eeg_sensors_layout(mri_subject, args): return meg.read_sensors_layout(mri_subject, args, pick_meg=False, pick_eeg=True, overwrite_sensors=args.overwrite_sensors)