def test_with_missing_channels(): """Test _create_info when channels are missing from info.""" cur_system = 'neuromag306' test_data_folder_ft = get_data_paths(cur_system) info = get_raw_info(cur_system) del info['chs'][1:20] info._update_redundant() with pytest.warns(RuntimeWarning): mne.io.read_raw_fieldtrip( os.path.join(test_data_folder_ft, 'raw_v7.mat'), info) mne.read_evoked_fieldtrip( os.path.join(test_data_folder_ft, 'averaged_v7.mat'), info) mne.read_epochs_fieldtrip( os.path.join(test_data_folder_ft, 'epoched_v7.mat'), info)
def test_throw_exception_on_cellarray(version, type): """Test for a meaningful exception when the data is a cell array.""" fname = os.path.join(get_data_paths('cellarray'), '%s_%s.mat' % (type, version)) info = get_raw_info('CNT') with pytest.raises(RuntimeError, match='Loading of data in cell arrays ' 'is not supported'): if type == 'averaged': mne.read_evoked_fieldtrip(fname, info) elif type == 'epoched': mne.read_epochs_fieldtrip(fname, info) elif type == 'raw': mne.io.read_raw_fieldtrip(fname, info)
def autoreject_epochs(ft_file, out_file, log_file): import mne import autoreject import json # Load the file #info = mne.io.read_info(raw_file) epochs = mne.read_epochs_fieldtrip(ft_file, info=None) # Resample the data #epochs.resample(500,npad='auto') # Apply autoreject ar = autoreject.AutoReject() epochs, reject_log = ar.fit_transform(epochs, return_log=True) reject_log = reject_log.bad_epochs reject_log = reject_log.tolist() # Write to disk with open(log_file, 'w') as f: json.dump(reject_log, f) #Save data to file epochs.save(out_file) return
def autoreject_log(ft_file, out_file): import mne import autoreject import json # Load the file #info = mne.io.read_info(raw_file) epochs = mne.read_epochs_fieldtrip(ft_file, info=None) # Resample the data - we're only going to use the thresholds #epochs.resample(400,npad='auto') # Apply autoreject to find bad channels ar = autoreject.AutoReject() ar.fit(epochs) reject_log = ar.get_reject_log(epochs) reject_log = reject_log.bad_epochs reject_log = reject_log.tolist() # Write to disk with open(out_file, 'w') as f: json.dump(reject_log, f) return
def autoreject_threshold(ft_file, out_file, raw_file=0): import sys import mne import autoreject import json PY3 = sys.version_info[0] == 3 if PY3: string_types = str, else: string_types = basestring, if isinstance(raw_file, string_types): info = mne.io.read_info(raw_file) epochs = mne.read_epochs_fieldtrip(ft_file, info) else: epochs = mne.read_epochs_fieldtrip(ft_file, info=None) reject = autoreject.get_rejection_threshold(epochs) with open(out_file, 'w') as f: json.dump(reject, f)
'noise_cov_10_17Hz', verbose=None) original_data = mne.io.read_raw_fif(raw_fname, preload=False) original_info = original_data.info original_info['sfreq'] = 500 #for the first 3 CSP components and the second 3 CSP components (commented) diff = [] CSP = ['1', '2', '3', '4', '5', '6', '97', '98', '99', '100', '101', '102'] for num in CSP: #load csp data for fast from fieldtrip ftname = savepath + subject + '/' + subject + '_fieldtrip_csp_1_6_and_97_102_new_to_mne.mat' fast_epo = mne.read_epochs_fieldtrip(ftname, original_info, data_name='epochs_fast' + num, trialinfo_column=0) fast_epo.save(PATHfrom + 'SUBJECTS/' + subject + '/ICA_nonotch_crop/epochs/' + subject + '_epo_fast.fif', overwrite=True) fast_fname = PATHfrom + 'SUBJECTS/' + subject + '/ICA_nonotch_crop/epochs/' + subject + '_epo_fast.fif' fast_epo = mne.read_epochs(fast_fname, proj=False, verbose=None) #load csp data for slow from fieldtrip slow_epo = mne.read_epochs_fieldtrip(ftname, original_info, data_name='epochs_slow' + num, trialinfo_column=0) slow_epo.save(PATHfrom + 'SUBJECTS/' + subject + '/ICA_nonotch_crop/epochs/' + subject + '_epo_slow.fif', overwrite=True)