Beispiel #1
0
def get_temp_filter(x, marker, win, idx, N_train=10000):
    trials = meet.epochEEG(x, marker, win)
    noise = meet.epochEEG(x, np.random.choice(idx, replace=True,
                size=N_train), win)
    temp_filter, temp_eigvals = meet.spatfilt.CSP(
            trials,
            noise,
            center=False)
    return temp_filter, temp_eigvals
Beispiel #2
0
def bootstrap_SNR(x, marker, win, bootstrap_idx, N_rep=1000):
    trials = meet.epochEEG(x, marker, win)
    signal_rms = np.sqrt(scipy.stats.trim_mean(trials**2,
        proportiontocut=0.2, axis=None))
    SNNR = np.empty(N_rep, float)
    ###########################
    # bootstrap the noise rms #
    ##########################
    for i in range(N_rep):
        noise_marker = np.random.choice(bootstrap_idx, size=len(marker),
                replace=True)
        noise_trials = meet.epochEEG(x, noise_marker, win)
        noise_rms = np.sqrt(scipy.stats.trim_mean(noise_trials**2,
            proportiontocut=0.2, axis=None))
        SNNR[i] = signal_rms/noise_rms
    return SNNR
Beispiel #3
0
def moving_rms(x, marker, trial_win, rms_win):
    moving_rms = np.array([
        np.sqrt(scipy.stats.trim_mean(
            meet.epochEEG(x, marker + tau -
                rms_win[0] - (rms_win[1] - rms_win[0])//2, rms_win)**2,
            proportiontocut=0.2,
            axis=None))
        for tau in range(trial_win[0], trial_win[1], 1)])
    return moving_rms
Beispiel #4
0
stim_data_sigma = meet.iir.butterworth(stim_data,
                                       fs=(400, 800),
                                       fp=(450, 750),
                                       s_rate=srate)

# get the trials
if subject.endswith('_old'):
    trial_win_ms = [-10, 60]
else:
    trial_win_ms = [-60, 160]

trial_win = np.round(np.array(trial_win_ms) / 1000. * srate).astype(int)
trial_t = (np.arange(trial_win[0], trial_win[1], 1) / float(srate) * 1000)

# for high-pass
trials_hp = meet.epochEEG(stim_data_hp, marker, trial_win)
# for sigma
trials_sigma = meet.epochEEG(stim_data_sigma, marker, trial_win)


# create a custom sampling scheme for the S transform
def custom_sampling_meg(N):
    if subject.endswith('_old'):
        S_frange = [5, 2500]
        S_fnum = 25
    else:
        S_frange = [5, 5000]
        S_fnum = 30
    S_Nperperiod = 4
    wanted_freqs = np.exp(
        np.linspace(np.log(S_frange[0]), np.log(S_frange[1]), S_fnum))
Beispiel #5
0
interpolate_win = np.round(np.array(interpolate_win_ms) / 1000. *
                           srate).astype(int)
stim_data = meet.interpolateEEG(stim_data, marker, interpolate_win)

# apply 450Hz-750 Hz band-pass filter
stim_data_sigma = meet.iir.butterworth(stim_data,
                                       fs=(400, 800),
                                       fp=(450, 750),
                                       s_rate=srate)

# get the trials
trial_win_ms = [-60, 160]
trial_win = np.round(np.array(trial_win_ms) / 1000. * srate).astype(int)
trial_t = (np.arange(trial_win[0], trial_win[1], 1) / float(srate) * 1000)

trials_sigma = meet.epochEEG(stim_data_sigma, marker, trial_win)

# get the burst win
burst_win_ms = [15, 35]
burst_win = np.round(np.array(burst_win_ms) / 1000. * srate).astype(int)
burst_t = (np.arange(burst_win[0], burst_win[1], 1) / float(srate) * 1000)
burst_sigma = meet.epochEEG(stim_data_sigma, marker, burst_win)

# get the noise win
noise_win_ms = [-35, -15]
noise_win = np.round(np.array(noise_win_ms) / 1000. * srate).astype(int)
noise_t = (np.arange(noise_win[0], noise_win[1], 1) / float(srate) * 1000)
noise_sigma = meet.epochEEG(stim_data_sigma, marker, noise_win)

burst_rms = np.sqrt((burst_sigma**2).mean(0))
noise_rms = np.sqrt((noise_sigma**2).mean(0))
Beispiel #6
0
# get the trials
trial_win_ms = [-60,160]
trial_win = np.round(np.array(trial_win_ms)/1000.*srate
        ).astype(int)
trial_t = (np.arange(trial_win[0], trial_win[1], 1)/
        float(srate)*1000)

marker = marker[
        np.all([
    (marker+trial_win[0])>=0,
    (marker+trial_win[1])<stim_data_sigma.shape[-1]
    ], 0)
        ]

trials_hp = meet.epochEEG(stim_data_hp, marker,
        trial_win)
#remove the mean in the time window -30 to 0
trials_hp -= trials_hp[(trial_t>=-30) & (trial_t<0)].mean(0)

trials_sigma = meet.epochEEG(stim_data_sigma, marker,
        trial_win)

# get the temporal windows for the burst and periburst intervals
peristim_win1_ms = [5, 15]
peristim_win2_ms = [30, 40]
stim_win_ms = [15, 30]

peristim_win1 = np.round(np.array(peristim_win1_ms)/1000.*srate
        ).astype(int)
peristim_win2 = np.round(np.array(peristim_win2_ms)/1000.*srate
        ).astype(int)
Beispiel #7
0
# apply 450Hz-750 Hz band-pass filter
stim_data_sigma = meet.stim_data = meet.iir.butterworth(stim_data,
                                                        fs=(400, 800),
                                                        fp=(450, 750),
                                                        s_rate=srate)

# calculate Hilbert transform
stim_data_sigma_hilbert = scipy.signal.hilbert(stim_data_sigma)

# get the trials
trial_win_ms = [-60, 160]
trial_win = np.round(np.array(trial_win_ms) / 1000. * srate).astype(int)
trial_t = (np.arange(trial_win[0], trial_win[1], 1) / float(srate) * 1000)

# for high-pass
trials_sigma = meet.epochEEG(stim_data_sigma_hilbert, marker, trial_win)

burst_mask = np.all([trial_t >= 15, trial_t <= 30], 0)
noise_mask = np.all([trial_t >= 55, trial_t <= 70], 0)

# remove outlier trials
burst_rms = np.sqrt(np.mean(trials_sigma.real[burst_mask]**2, 0))
burst_rms_q25 = scipy.stats.scoreatpercentile(burst_rms, 25)
burst_rms_q50 = np.median(burst_rms)
burst_rms_q75 = scipy.stats.scoreatpercentile(burst_rms, 75)
burst_iqr = burst_rms_q75 - burst_rms_q25

noise_rms = np.sqrt(np.mean(trials_sigma.real[noise_mask]**2, 0))
noise_rms_q25 = scipy.stats.scoreatpercentile(noise_rms, 25)
noise_rms_q50 = np.median(noise_rms)
noise_rms_q75 = scipy.stats.scoreatpercentile(noise_rms, 75)