def test_read_evoked(): """Test reading evokeds.""" for data_type in tconf.task_types: all_annots = list() for run_index in tconf.run_inds[:2]: annots = hcp.read_annot( data_type=data_type, run_index=run_index, **hcp_params) all_annots.append(annots) evokeds = hcp.read_evokeds(data_type=data_type, kind='average', **hcp_params) n_average = sum(ee.kind == 'average' for ee in evokeds) assert_equal(n_average, len(evokeds)) n_chans = 248 if data_type == 'task_motor': n_chans += 4 n_chans -= len(set(sum( [an['channels']['all'] for an in all_annots], []))) assert_equal(n_chans, len(evokeds[0].ch_names)) assert_true( _check_bounds(evokeds[0].times, tconf.epochs_bounds[data_type]) )
def official_ERF(): hcp_evokeds = hcp.read_evokeds(onset='stim', **hcp_params) for ev in hcp_evokeds: if not ev.comment == 'Wrkmem_LM-TIM-face_BT-diff_MODE-mag': continue # Once more we add and interpolate missing channels evoked_hcp = preproc.interpolate_missing(ev, **hcp_params) return evoked_hcp
def test_map_ch_coords_to_mne(): """Test mapping of channel coords to MNE.""" data_type = 'task_working_memory' hcp_evokeds = hcp.read_evokeds(onset='stim', data_type=data_type, **hcp_params) for evoked in hcp_evokeds: if evoked.comment == 'Wrkmem_LM-TIM-face_BT-diff_MODE-mag': break old_coord = evoked.info['chs'][0]['loc'] map_ch_coords_to_mne(evoked) new_coord = evoked.info['chs'][0]['loc'] assert_true((old_coord != new_coord).any())
def test_interpolate_missing(): """Test interpolation of missing channels.""" data_type = 'task_working_memory' raw = hcp.read_raw(data_type='task_working_memory', run_index=0, **hcp_params) raw.load_data() n_chan = len(raw.ch_names) raw.drop_channels(['A1']) assert_equal(len(raw.ch_names), n_chan - 1) raw = interpolate_missing(raw, data_type=data_type, **hcp_params) assert_equal(len(raw.ch_names), n_chan) evoked = hcp.read_evokeds(data_type=data_type, **hcp_params)[0] assert_equal(len(evoked.ch_names), 243) evoked_int = interpolate_missing(evoked, data_type=data_type, **hcp_params) assert_equal(len(evoked_int.ch_names), 248)
subject = '100307' # our test subject task = 'task_working_memory' meg_sub_fol = op.join(MEG_DIR, subject) fwd_fname = op.join(meg_sub_fol, '{}-fwd.fif'.format(subject)) inv_fname = op.join(meg_sub_fol, '{}-inv.fif'.format(subject)) noise_cov_fname = op.join(meg_sub_fol, '{}-noise-cov.fif'.format(subject, task)) stc_fname = op.join(meg_sub_fol, '{}-{}.stc'.format(subject, task)) n_jobs = 4 run_index = 0 ############################################################################## # We're reading the evoked data. # These are the same as in :ref:`tut_plot_evoked` hcp_evokeds = hcp.read_evokeds(onset='stim', subject=subject, data_type=task, HCP_DIR=HCP_DIR) for evoked in hcp_evokeds: if not evoked.comment == 'Wrkmem_LM-TIM-face_BT-diff_MODE-mag': continue ############################################################################## # We'll now use a convenience function to get our forward and source models # instead of computing them by hand. # src_outputs = hcp.anatomy.compute_forward_stack( # subject=subject, subjects_dir=subjects_dir, # HCP_DIR=HCP_DIR, recordings_path=recordings_path, # # speed up computations here. Setting `add_dist` to True may improve the # # accuracy. # src_params=dict(add_dist=False), # info_from=dict(data_type=task, run_index=run_index))
############################################################################## # we assume our data is inside a designated folder under $HOME storage_dir = op.expanduser('~/mne-hcp-data') hcp_path = op.join(storage_dir, 'HCP') recordings_path = op.join(storage_dir, 'hcp-meg') subjects_dir = op.join(storage_dir, 'hcp-subjects') subject = '105923' # our test subject data_type = 'task_working_memory' run_index = 0 ############################################################################## # We're reading the evoked data. # These are the same as in :ref:`tut_plot_evoked` hcp_evokeds = hcp.read_evokeds(onset='stim', subject=subject, data_type=data_type, hcp_path=hcp_path) for evoked in hcp_evokeds: if not evoked.comment == 'Wrkmem_LM-TIM-face_BT-diff_MODE-mag': continue ############################################################################## # We'll now use a convenience function to get our forward and source models # instead of computing them by hand. src_outputs = hcp.anatomy.compute_forward_stack( subject=subject, subjects_dir=subjects_dir, hcp_path=hcp_path, recordings_path=recordings_path, # speed up computations here. Setting `add_dist` to True may improve the # accuracy. src_params=dict(add_dist=False), info_from=dict(data_type=data_type, run_index=run_index))
mne.set_log_level('WARNING') ############################################################################## # we assume our data is inside a designated folder under $HOME # and set the IO params storage_dir = op.expanduser('~') hcp_params = dict(hcp_path=op.join(storage_dir, 'mne-hcp-data', 'HCP'), subject='105923', data_type='task_working_memory') ############################################################################## # we take the some evoked and create an interpolated copy evoked = hcp.read_evokeds(**hcp_params)[0] # The HCP pipelines don't interpolate missing channels print('%i channels out of 248 expected' % len(evoked.ch_names)) evoked_interpolated = preproc.interpolate_missing(evoked, **hcp_params) ############################################################################## # Let's visualize what has changed! # we calculate the difference ... bads = set(evoked_interpolated.ch_names) - set(evoked.ch_names) print(bads) # ... and mark the respective channels as bad ... evoked_interpolated.info['bads'] += list(bads)
evoked.apply_baseline() evoked = preproc.interpolate_missing(evoked, **hcp_params) evokeds_from_epochs_hcp.append(evoked) ############################################################################## # Finally we can read the actual official ERF file # # These are obtained from the 'eravg' pipelines. # We read the matlab file, MNE-HCP is doing some conversions, and then we # search our condition of interest. Here we're looking at the image as onset. # and we want the average, not the standard deviation. evoked_hcp = None hcp_evokeds = hcp.read_evokeds(onset='stim', **hcp_params) for ev in hcp_evokeds: if not ev.comment == 'Wrkmem_LM-TIM-face_BT-diff_MODE-mag': continue # Once more we add and interpolate missing channels evoked_hcp = preproc.interpolate_missing(ev, **hcp_params) ############################################################################## # Time to compare the outputs # evoked = mne.combine_evoked(evokeds, weights='equal') evoked_from_epochs_hcp = mne.combine_evoked(