Example #1
0
def test_epochs_deconv():
    """Test epochs deconvolution"""
    tmin, tmax = -0.5, 1.5
    event_dict = dict(foo=999)
    events = np.array([np.arange(0, 21000, 1000, int),
                       999 * np.ones(21, int)]).T
    for fi, fname in enumerate(fnames):
        if fi == 0:
            n_jobs = 1
        else:
            n_jobs = 0
        raw = read_raw(fname)
        epochs = Epochs(raw, events, event_dict, tmin, tmax)
        a = raw.info['sample_fields']
        b = epochs.info['data_cols']
        assert_equal(len(a), len(b))
        assert_true(all(aa == bb for aa, bb in zip(a, b)))
        data = epochs.get_data('ps')
        assert_raises(RuntimeError, Epochs, raw, events, 'test', tmin, tmax)
        fit, times = epochs.deconvolve()
        assert_array_equal(data, epochs.get_data('ps'))
        assert_equal(fit.shape, (len(epochs), len(times)))
        fit, times = epochs.deconvolve(spacing=[-0.1, 0.4, 1.0],
                                       bounds=(0, np.inf),
                                       n_jobs=n_jobs)
        assert_equal(fit.shape, (len(epochs), len(times)))
        assert_equal(len(times), 3)
        if fi == 0:
            if _has_joblib():
                assert_raises(ValueError, epochs.deconvolve, n_jobs=-1000)
Example #2
0
def test_epochs_deconv():
    """Test epochs deconvolution"""
    tmin, tmax = -0.5, 1.5
    event_dict = dict(foo=999)
    events = np.array([np.arange(0, 21000, 1000, int),
                       999 * np.ones(21, int)]).T
    for fi, fname in enumerate(fnames):
        if fi == 0:
            n_jobs = 1
        else:
            n_jobs = 0
        raw = read_raw(fname)
        epochs = Epochs(raw, events, event_dict,
                        tmin, tmax)
        a = raw.info['sample_fields']
        b = epochs.info['data_cols']
        assert_equal(len(a), len(b))
        assert_true(all(aa == bb for aa, bb in zip(a, b)))
        data = epochs.get_data('ps')
        assert_raises(RuntimeError, Epochs, raw, events, 'test', tmin, tmax)
        fit, times = epochs.deconvolve()
        assert_array_equal(data, epochs.get_data('ps'))
        assert_equal(fit.shape, (len(epochs), len(times)))
        fit, times = epochs.deconvolve(spacing=[-0.1, 0.4, 1.0],
                                       bounds=(0, np.inf), n_jobs=n_jobs)
        assert_equal(fit.shape, (len(epochs), len(times)))
        assert_equal(len(times), 3)
        if fi == 0:
            if _has_joblib():
                assert_raises(ValueError, epochs.deconvolve, n_jobs=-1000)
Example #3
0
def test_epochs_deconv():
    """Test epochs deconvolution"""
    tmin, tmax = -0.5, 1.5
    event_dict = dict(foo=999, bar=77)
    events_a = np.array([[12000, 77], [1000, 999]])
    for fname in fnames:
        raw = Raw(fname)
        epochs = Epochs([raw] * 2, [events_a] * 2, event_dict,
                        tmin, tmax)
        assert_raises(RuntimeError, Epochs, raw, events_a, 'test', tmin, tmax)
        fit, times = epochs.deconvolve()
        assert_equal(fit.shape, (len(epochs), len(times)))
        fit, times = epochs.deconvolve(spacing=[-0.1, 0.4, 1.0],
                                       bounds=(0, np.inf))
        assert_equal(fit.shape, (len(epochs), len(times)))
        assert_equal(len(times), 3)
    if downsample:
        print('  Downsampling...')
        epochs.resample(fs_out, n_jobs=n_jobs)
    # compute gaze angles (in degrees)
    angles = get_gaze_angle(epochs, screenprops)
    # zscore pupil sizes
    zscore = epochs.pupil_zscores()
    # init some containers
    kernel_fits = list()
    kernel_zscores = list()

    print('  Deconvolving...')
    deconv_kwargs = dict(kernel=kernel, n_jobs=n_jobs, acc=1e-3)
    if deconv_time_pts is not None:
        deconv_kwargs.update(dict(spacing=deconv_time_pts))
    fit, time_pts = epochs.deconvolve(**deconv_kwargs)
    if deconv_time_pts is None:
        deconv_time_pts = time_pts
    assert np.array_equal(deconv_time_pts, time_pts)
    # order sequentially by stimulus ID
    order = np.argsort(stim_nums)
    angles = angles[order]
    zscore = zscore[order]
    fit = fit[order]
    # add this subject's data to global container
    fits.append(fit)
    zscores.append(zscore)
    gaze_angles.append(angles)
    print('  Done: {} sec.'.format(str(round(time.time() - t0, 1))))

# convert to arrays
        band_num = run_inds[ri][:, 1]
        gap_num = 10 * small_mat[:, 1]    # cf. line 251 of vocExperiment_v2.m
        attn_num = 100 * small_mat[:, 0]  # cf. line 250 of vocExperiment_v2.m
        event[:, 1] = band_num + gap_num + attn_num
        events.append(event)

    print('\n  Epoching...')
    epochs = Epochs(raws, events, event_dict, t_min, t_max)

    kernel_fits = list()
    kernel_zscores = list()
    kernel_fits_continuous = list()
    for kk, kernel in enumerate(kernels):
        kname = ['LABSN', 'Wierda'][kk]
        print('  Deconvolving ({} kernel)...'.format(kname))
        fit, time_pts = epochs.deconvolve(kernel=kernel, n_jobs=6)
        zscore = epochs.pupil_zscores()
        if deconv_time_pts is None:
            deconv_time_pts = time_pts
        assert np.array_equal(deconv_time_pts, time_pts)

        # reorder fits to match big_mat (stim# in serial order, voc band, time)
        order = np.array(run_inds)
        band_idx = (order[:, :, 1] - 1).ravel()
        stim_idx = (order[:, :, 0] - 1).ravel()  # convert 1-based to 0-based
        fits_ordered = np.inf * np.ones((len(big_mat), 2,
                                         len(deconv_time_pts)))
        zscores_ordered = np.inf * np.ones((len(big_mat), 2, epochs.n_times))
        fits_ordered[stim_idx, band_idx, :] = fit
        zscores_ordered[stim_idx, band_idx, :] = zscore
        assert not np.any(fits_ordered == np.inf)
Example #6
0
        band_num = run_inds[ri][:, 1]
        gap_num = 10 * small_mat[:, 1]  # cf. line 251 of vocExperiment_v2.m
        attn_num = 100 * small_mat[:, 0]  # cf. line 250 of vocExperiment_v2.m
        event[:, 1] = band_num + gap_num + attn_num
        events.append(event)

    print('\n  Epoching...')
    epochs = Epochs(raws, events, event_dict, t_min, t_max)

    kernel_fits = list()
    kernel_zscores = list()
    kernel_fits_continuous = list()
    for kk, kernel in enumerate(kernels):
        kname = ['LABSN', 'Wierda'][kk]
        print('  Deconvolving ({} kernel)...'.format(kname))
        fit, time_pts = epochs.deconvolve(kernel=kernel, n_jobs=6)
        zscore = epochs.pupil_zscores()
        if deconv_time_pts is None:
            deconv_time_pts = time_pts
        assert np.array_equal(deconv_time_pts, time_pts)

        # reorder fits to match big_mat (stim# in serial order, voc band, time)
        order = np.array(run_inds)
        band_idx = (order[:, :, 1] - 1).ravel()
        stim_idx = (order[:, :, 0] - 1).ravel()  # convert 1-based to 0-based
        fits_ordered = np.inf * np.ones(
            (len(big_mat), 2, len(deconv_time_pts)))
        zscores_ordered = np.inf * np.ones((len(big_mat), 2, epochs.n_times))
        fits_ordered[stim_idx, band_idx, :] = fit
        zscores_ordered[stim_idx, band_idx, :] = zscore
        assert not np.any(fits_ordered == np.inf)