Пример #1
0
def read_raw_data(run_index, hcp_params, lfreq=0.5, hfreq=60):
    raw = hcp.read_raw(run_index=run_index, **hcp_params)
    raw.load_data()
    # apply ref channel correction and drop ref channels
    # preproc.apply_ref_correction(raw)

    annots = hcp.read_annot(run_index=run_index, **hcp_params)
    # construct MNE annotations
    bad_seg = (annots['segments']['all']) / raw.info['sfreq']
    annotations = mne.Annotations(
        bad_seg[:, 0], (bad_seg[:, 1] - bad_seg[:, 0]),
        description='bad')

    raw.annotations = annotations
    raw.info['bads'].extend(annots['channels']['all'])
    raw.pick_types(meg=True, ref_meg=False)

    raw.filter(lfreq, None, method='iir',
               iir_params=dict(order=4, ftype='butter'), n_jobs=1)
    raw.filter(None, hfreq, method='iir',
               iir_params=dict(order=4, ftype='butter'), n_jobs=1)

    # read ICA and remove EOG ECG
    # note that the HCP ICA assumes that bad channels have already been removed
    ica_mat = hcp.read_ica(run_index=run_index, **hcp_params)

    # We will select the brain ICs only
    exclude = annots['ica']['ecg_eog_ic']
    preproc.apply_ica_hcp(raw, ica_mat=ica_mat, exclude=exclude)
    return raw
def test_apply_ica():
    """Test ICA application."""
    raw = hcp.read_raw(data_type='rest', verbose='error', **hcp_params)
    annots = hcp.read_annot(data_type='rest', **hcp_params)
    # construct MNE annotations
    bad_seg = (annots['segments']['all']) / raw.info['sfreq']
    annotations = mne.Annotations(bad_seg[:, 0],
                                  (bad_seg[:, 1] - bad_seg[:, 0]),
                                  description='bad')

    raw.annotations = annotations
    raw.info['bads'].extend(annots['channels']['all'])
    ica_mat = hcp.read_ica(data_type='rest', **hcp_params)
    exclude = [
        ii for ii in range(annots['ica']['total_ic_number'][0])
        if ii not in annots['ica']['brain_ic_vs']
    ]
    assert_raises(RuntimeError,
                  apply_ica_hcp,
                  raw,
                  ica_mat=ica_mat,
                  exclude=exclude)
    # XXX right now this is just a smoke test, should really check some
    # values...
    with warnings.catch_warnings(record=True):
        raw.crop(0, 1).load_data()
    apply_ica_hcp(raw, ica_mat=ica_mat, exclude=exclude)
Пример #3
0
def test_apply_ica():
    """Test ICA application."""
    raw = hcp.read_raw(data_type='rest', verbose='error', **hcp_params)
    annots = hcp.read_annot(data_type='rest', **hcp_params)
    # construct MNE annotations
    bad_seg = (annots['segments']['all']) / raw.info['sfreq']
    annotations = mne.Annotations(
        bad_seg[:, 0], (bad_seg[:, 1] - bad_seg[:, 0]), description='bad')

    raw.annotations = annotations
    raw.info['bads'].extend(annots['channels']['all'])
    ica_mat = hcp.read_ica(data_type='rest', **hcp_params)
    exclude = [ii for ii in range(annots['ica']['total_ic_number'][0])
               if ii not in annots['ica']['brain_ic_vs']]
    assert_raises(RuntimeError, apply_ica_hcp, raw, ica_mat=ica_mat,
                  exclude=exclude)
    # XXX right now this is just a smoke test, should really check some
    # values...
    with warnings.catch_warnings(record=True):
        raw.crop(0, 1).load_data()
    apply_ica_hcp(raw, ica_mat=ica_mat, exclude=exclude)
Пример #4
0
        bad_seg[:, 0], (bad_seg[:, 1] - bad_seg[:, 0]),
        description='bad')

    raw.annotations = annotations
    raw.info['bads'].extend(annots['channels']['all'])
    raw.pick_types(meg=True, ref_meg=False)

    #  Note: MNE complains on Python 2.7
    raw.filter(0.50, None, method='iir',
               iir_params=dict(order=4, ftype='butter'), n_jobs=1)
    raw.filter(None, 60, method='iir',
               iir_params=dict(order=4, ftype='butter'), n_jobs=1)

    # read ICA and remove EOG ECG
    # note that the HCP ICA assumes that bad channels have already been removed
    ica_mat = hcp.read_ica(run_index=run_index, **hcp_params)

    # We will select the brain ICs only
    exclude = annots['ica']['ecg_eog_ic']
    preproc.apply_ica_hcp(raw, ica_mat=ica_mat, exclude=exclude)

    # now we can epoch
    events = np.sort(events, 0)
    epochs = mne.Epochs(raw, events=events[events[:, 2] == 1],
                        event_id=event_id, tmin=tmin, tmax=tmax,
                        reject=None, baseline=baseline, decim=decim,
                        preload=True)

    evoked = epochs.average()
    # now we need to add back out channels for comparison across runs.
    evoked = preproc.interpolate_missing(evoked, **hcp_params)
Пример #5
0
def reprocess_the_data_from_scratch(all_events, event_id, tmin, tmax, baseline,
                                    decim):
    # now we can go ahead
    evokeds = list()
    all_epochs = list()
    for run_index, events in zip([0, 1], all_events):

        raw = hcp.read_raw(run_index=run_index, **hcp_params)
        raw.load_data()
        # apply ref channel correction and drop ref channels
        # preproc.apply_ref_correction(raw)

        annots = hcp.read_annot(run_index=run_index, **hcp_params)
        # construct MNE annotations
        bad_seg = (annots['segments']['all']) / raw.info['sfreq']
        annotations = mne.Annotations(bad_seg[:, 0],
                                      (bad_seg[:, 1] - bad_seg[:, 0]),
                                      description='bad')

        raw.annotations = annotations
        raw.info['bads'].extend(annots['channels']['all'])
        raw.pick_types(meg=True, ref_meg=False)

        #  Note: MNE complains on Python 2.7
        raw.filter(0.50,
                   None,
                   method='iir',
                   iir_params=dict(order=4, ftype='butter'),
                   n_jobs=1)
        raw.filter(None,
                   60,
                   method='iir',
                   iir_params=dict(order=4, ftype='butter'),
                   n_jobs=1)

        # read ICA and remove EOG ECG
        # note that the HCP ICA assumes that bad channels have already been removed
        ica_mat = hcp.read_ica(run_index=run_index, **hcp_params)

        # We will select the brain ICs only
        exclude = annots['ica']['ecg_eog_ic']
        preproc.apply_ica_hcp(raw, ica_mat=ica_mat, exclude=exclude)

        # now we can epoch
        events = np.sort(events, 0)
        epochs = mne.Epochs(raw,
                            events=events[events[:, 2] == 1],
                            event_id=event_id,
                            tmin=tmin,
                            tmax=tmax,
                            reject=None,
                            baseline=baseline,
                            decim=decim,
                            preload=True)

        all_epochs.append(epochs)
        evoked = epochs.average()
        # now we need to add back out channels for comparison across runs.
        evoked = preproc.interpolate_missing(evoked, **hcp_params)
        evokeds.append(evoked)
    return all_epochs, evokeds
Пример #6
0
        bad_seg[:, 0], (bad_seg[:, 1] - bad_seg[:, 0]),
        description='bad')

    raw.annotations = annotations
    raw.info['bads'].extend(annots['channels']['all'])
    raw.pick_types(meg=True, ref_meg=False)

    #  Note: MNE complains on Python 2.7
    raw.filter(0.50, None, method='iir',
               iir_params=dict(order=4, ftype='butter'), n_jobs=1)
    raw.filter(None, 60, method='iir',
               iir_params=dict(order=4, ftype='butter'), n_jobs=1)

    # read ICA and remove EOG ECG
    # note that the HCP ICA assumes that bad channels have already been removed
    ica_mat = hcp.read_ica(run_index=run_index, **hcp_params)

    # We will select the brain ICs only
    exclude = annots['ica']['ecg_eog_ic']
    preproc.apply_ica_hcp(raw, ica_mat=ica_mat, exclude=exclude)

    # now we can epoch
    events = np.sort(events, 0)
    epochs = mne.Epochs(raw, events=events[events[:, 2] == 1],
                        event_id=event_id, tmin=tmin, tmax=tmax,
                        reject=None, baseline=baseline, decim=decim,
                        preload=True)

    evoked = epochs.average()
    # now we need to add back out channels for comparison across runs.
    evoked = preproc.interpolate_missing(evoked, **hcp_params)