示例#1
0
def addNecessaryChanlsForEvoked(oEvoked: mne.Evoked):

    temp = oEvoked.times.reshape(1, -1)
    realTime_data = temp
    #    realTime_data = oEpoch.times.reshape(1,1,-1)
    info_realTime = create_info(['realTime'], oEvoked.info['sfreq'], ['stim'])

    realTime_raw = mne.EvokedArray(realTime_data, info_realTime)

    oEvoked.add_channels([realTime_raw], force_update_info=True)

    return oEvoked
示例#2
0
def test_plot_mne_evoked():
    "Test plotting evoked from the mne sample dataset"
    data_path = mne.datasets.sample.data_path()
    evoked_path = os.path.join(data_path, 'MEG', 'sample',
                               'sample_audvis-ave.fif')
    evoked = Evoked(evoked_path, setno="Left Auditory")
    p = plot.Array(evoked)
    p.close()
示例#3
0
def test_logging():
    """Test logging (to file)
    """
    with open(fname_log, 'r') as old_log_file:
        old_lines = clean_lines(old_log_file.readlines())
    with open(fname_log_2, 'r') as old_log_file_2:
        old_lines_2 = clean_lines(old_log_file_2.readlines())

    if op.isfile(test_name):
        os.remove(test_name)
    # test it one way (printing default off)
    set_log_file(test_name)
    set_log_level('WARNING')
    # should NOT print
    evoked = Evoked(fname_evoked, condition=1)
    with open(test_name) as fid:
        assert_true(fid.readlines() == [])
    # should NOT print
    evoked = Evoked(fname_evoked, condition=1, verbose=False)
    with open(test_name) as fid:
        assert_true(fid.readlines() == [])
    # should NOT print
    evoked = Evoked(fname_evoked, condition=1, verbose='WARNING')
    with open(test_name) as fid:
        assert_true(fid.readlines() == [])
    # SHOULD print
    evoked = Evoked(fname_evoked, condition=1, verbose=True)
    with open(test_name, 'r') as new_log_file:
        new_lines = clean_lines(new_log_file.readlines())
    assert_equal(new_lines, old_lines)
    set_log_file(None)  # Need to do this to close the old file
    os.remove(test_name)

    # now go the other way (printing default on)
    set_log_file(test_name)
    set_log_level('INFO')
    # should NOT print
    evoked = Evoked(fname_evoked, condition=1, verbose='WARNING')
    with open(test_name) as fid:
        assert_true(fid.readlines() == [])
    # should NOT print
    evoked = Evoked(fname_evoked, condition=1, verbose=False)
    with open(test_name) as fid:
        assert_true(fid.readlines() == [])
    # SHOULD print
    evoked = Evoked(fname_evoked, condition=1)
    with open(test_name, 'r') as new_log_file:
        new_lines = clean_lines(new_log_file.readlines())
    with open(fname_log, 'r') as old_log_file:
        assert_equal(new_lines, old_lines)
    # check to make sure appending works (and as default, raises a warning)
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter('always')
        set_log_file(test_name, overwrite=False)
        assert len(w) == 0
        set_log_file(test_name)
        assert len(w) == 1
    evoked = Evoked(fname_evoked, condition=1)
    with open(test_name, 'r') as new_log_file:
        new_lines = clean_lines(new_log_file.readlines())
    assert_equal(new_lines, old_lines_2)

    # make sure overwriting works
    set_log_file(test_name, overwrite=True)
    # this line needs to be called to actually do some logging
    evoked = Evoked(fname_evoked, condition=1)
    del evoked
    with open(test_name, 'r') as new_log_file:
        new_lines = clean_lines(new_log_file.readlines())
    assert_equal(new_lines, old_lines)
示例#4
0

def time_label(t):
    return "time=%0.2f ms" % (1e3 * t)


for subject in subjects:
    print(subject)
    meg_dir = '/Users/ea84/Dropbox/shepard_sourceloc/%s/' % (subject)
    os.environ[
        "SUBJECTS_DIR"] = '/Volumes/Server/MORPHLAB/Users/Ellie/Shepard/mri/'
    evoked_fname = meg_dir + subject + '_shepard-evoked-ave.fif'
    inv_fname = meg_dir + subject + '_shepard-inv.fif'
    stc_fname = meg_dir + subject + '_shepard_evoked'

    evoked = Evoked(evoked_fname)
    inverse_operator = read_inverse_operator(inv_fname)
    stc_evoked = apply_inverse(evoked,
                               inverse_operator,
                               lambda2,
                               method='dSPM')
    stc_evoked.save(stc_fname)

    brain = Brain(subject, 'split', 'partially_inflated', size=(800, 400))
    for hemi in ['lh', 'rh']:
        stc = read_stc(stc_fname + '-%s.stc' % hemi)
        data = stc['data']
        times = np.arange(data.shape[1]) * stc['tstep'] + stc['tmin']
        brain.add_data(data,
                       colormap='RdBu',
                       vertices=stc['vertices'],
示例#5
0
    raw_input(
        'NOTE: Save as subj_rejfile.pickled. \nPress enter when you are done rejecting epochs in the GUI...'
    )
    rejfile = eelbrain.load.unpickle(ica_rej_fname)

# create a mask to reject the bad epochs
rejs = rejfile['accept'].x

# mask epochs and info
epochs = epochs[rejs]
trial_info = trial_info[rejs]

# if evoked is made, load
# else make evoked to check for auditory response
if op.isfile(evoked_fname):
    evoked = Evoked(evoked_fname)
else:
    evoked = epochs.average()
    evoked.save(evoked_fname)
    # check for M100
    evoked.plot()

# set metadata: allows you to specify more complex info about events,
# can use pandas-style queries to access subsets of data
epochs.metadata = trial_info
epochs.save(epochs_fname)

# SANITY CHECK!!:
assert (len(epochs.events) == len(trial_info))

#-------------------------------------------------------------------------------