Пример #1
0
def test_retrieve():
    """Test retrieval functionality."""
    raw = _generate_raw(n_chan=1, iaf=11.25)
    raw.add_events(np.array([[1, 0, 255], [10, 0, 255]]))
    epochs = mne.Epochs(raw, mne.find_events(raw), tmin=0.0, preload=True)

    # TODO: test multiple time windows
    # TODO: test items
    # TODO: test different summary functions
    # TODO: test scale_times

    windows = dict(onset=(-50, 50))

    df1 = retrieve(epochs, windows)
    df2 = pd.DataFrame({'channel': {0: '0', 1: 'STI 014', 2: '0', 3: 'STI 014'},  # noqa: E501
                        'condition': {0: '255', 1: '255', 2: '255', 3: '255'},  # noqa: E501
                        'epoch': {0: 0, 1: 0, 2: 1, 3: 1},
                        'mean': {0: 4.4267676108015275,
                         1: 39.23076923076923,
                         2: -9.852708759493767,
                         3: 19.615384615384617},
                        'win': {0: '-50..50', 1: '-50..50', 2: '-50..50', 3: '-50..50'},  # noqa: E501
                        'wname': {0: 'onset', 1: 'onset', 2: 'onset', 3: 'onset'}})  # noqa: E501

    assert_true(np.all(df1.eq(df2)))
Пример #2
0
        tmin=-0.2,
        tmax=1.2,  # epochs go from -200 to +1200ms
        detrend=1,  # linear detrending
        baseline=None,  # No baselining
        reject=peak_to_peak,  # peak-to-peak rejections
        flat=flatline,  # flatline rejection
        on_missing=
        'ignore',  # ignore missing events -- not all ratings-cond combos occu (BT: the standard is to give Error)
        preload=True)
    epochs.drop_bad()
    # absolute threshold rejection
    bad_epoch_mask = abs_threshold(epochs.pick_types(eeg=True), threshold)
    epochs.drop(bad_epoch_mask, reason="absolute threshold")

    df = retrieve(
        epochs, wins,
        items=epochs.events[:, 1])  #BT: items are in the event structure
    df.to_csv(csvout)

    for c in codes:
        erp = epochs[c].average()
        ssavg[c].append(erp)

#BT: because he kept getting errors
    for c in codes_with_ratings:
        try:
            erp = epochs[c].average()
            ssavg[c].append(erp)
        except KeyError:  # this combination doesn't occur
            pass
Пример #3
0
                        baseline=None, # No baselining
                        reject=peak_to_peak, # peak-to-peak rejections
                        flat=flatline, # flatline rejection
                        on_missing='ignore', # ignore missing events
                        preload=True)

    epochs[c].drop_bad()
    bad_epoch_mask = abs_threshold(epochs[c].pick_types(eeg=True), threshold)
    epochs[c].drop(bad_epoch_mask,reason="absolute threshold")


#epochs = mne.concatenate_epochs([epochs[c] for c in epochs])

lang_erp = epochs['language']['lang/target'].average()
music_erp = epochs["music"]['music/target'].average()

lang_minus_music = mne.combine_evoked([lang_erp,music_erp], [1, -1])


# windows of interest for statistics
# units are *milliseconds* relative to time-locking event
wins = dict(baseline=(-200,0),
            P100=(50,150),
            N200=(150,250),
            N400=(300,500))


for c in epochs:
    df = retrieve(epochs[c], wins)
    df.to_csv("{}.csv".format(c))
Пример #4
0
        raw,
        events=events,
        event_id=codes,
        tmin=-0.2,
        tmax=1.2,  # epochs go from -200 to +1200ms
        detrend=1,  # linear detrending
        baseline=None,  # No baselining
        reject=peak_to_peak,  # peak-to-peak rejections
        flat=flatline,  # flatline rejection
        preload=True)
    epochs.drop_bad()
    # absolute threshold rejection
    bad_epoch_mask = abs_threshold(epochs.pick_types(eeg=True), threshold)
    epochs.drop(bad_epoch_mask, reason="absolute threshold")

    df = retrieve(epochs, wins)
    df.to_csv(csvout)

    for c in codes:
        erp = epochs[c].average()
        ssavg[c].append(erp)

# visualizing grand averages
# non-overlapping 83% CIs of the ind. measures correspond to the 95% CI
# of the difference
mne.viz.plot_compare_evokeds(ssavg, picks=[15], invert_y=True, ci=.83)

# we can also look at different combinations of conditions and the
# the resulting difference waves
longfit = mne.grand_average(ssavg['long/fit'])
longfit.plot_joint()
            preload=True,
            flat=flatline,
            reject=peak_to_peak,
            reject_by_annotation=
            False,  #If True (default), epochs overlapping with segments whose description begins with 'bad' are rejected.
            picks=ch_picks_epoch)
        epochs = mne.epochs.combine_event_ids(
            epochs, ['abs-min-yes-x', 'abs-max-yes-x'], {'abs-yes-x': 233243})
        epochs = mne.epochs.combine_event_ids(epochs,
                                              ['abs-min-no-x', 'abs-max-no-x'],
                                              {'abs-no-x': 238248})

        #save epochs to file
        epochs.save(evoked_out)
        #retrieve time windows of interest
        df = retrieve(epochs, wins, items=epochs.events[:, 1])
        df.to_csv(csvout)
    else:
        print('epoch file "{}" exists, reading...'.format(evoked_out))
        try:
            epochs = mne.read_epochs(evoked_out)
            print('Successfully read the file, yay!')
        except FileNotFoundError:
            raise FileNotFoundError(
                "I can't find this damn file {}".format(evoked_out))
        except:
            raise IOError("Problem reading the file: {}".format(evoked_out))
    print(epochs)

    for c in newcodes:
        erp = epochs[c].average()