def test_time_shift_4():
    # this isn't a good check, but increases coverage
    cond_all=2*np.arange(1,101)

    from time_shift import make_shift_matrix,time_correct

    delta_y=2*(np.arange(34))/34


    shifted=make_shift_matrix(cond_all,delta_y)



    from event_related_fMRI_functions import hrf_single, np_convolve_30_cuts


    def make_convolve_lambda(hrf_function,TR,num_TRs):
        convolve_lambda=lambda x: np_convolve_30_cuts(x,np.ones(x.shape[0]),hrf_function,TR,np.linspace(0,(num_TRs-1)*TR,num_TRs),15)[0]
        return convolve_lambda

    convolve_lambda=make_convolve_lambda(hrf_single,2,239)

    hrf_matrix=time_correct(convolve_lambda,shifted,239)

    assert(hrf_matrix[0,0]==0)
Esempio n. 2
0
def test_time_shift_4():
    # this isn't a good check, but increases coverage
    cond_all=2*np.arange(1,101)

    from time_shift import make_shift_matrix,time_correct

    delta_y=2*(np.arange(34))/34


    shifted=make_shift_matrix(cond_all,delta_y)



    from event_related_fMRI_functions import hrf_single, np_convolve_30_cuts


    def make_convolve_lambda(hrf_function,TR,num_TRs):
        convolve_lambda=lambda x: np_convolve_30_cuts(x,np.ones(x.shape[0]),hrf_function,TR,np.linspace(0,(num_TRs-1)*TR,num_TRs),15)[0]
        return convolve_lambda

    convolve_lambda=make_convolve_lambda(hrf_single,2,239)

    hrf_matrix=time_correct(convolve_lambda,shifted,239)

    assert(hrf_matrix[0,0]==0)
def times_time_shift_2():
    # time_shift_cond
    assert(np.all(np.arange(5)-1==time_shift_cond(np.arange(5),1) ))

    # make_shift_matrix
    assert(np.all(make_shift_matrix(np.arange(5),np.arange(2))==
        np.array([0,1,2,3,4, 
                 -1,0,1,2,3]).reshape((2,-1)).T))
Esempio n. 4
0
def times_time_shift_2():
    # time_shift_cond
    assert (np.all(np.arange(5) - 1 == time_shift_cond(np.arange(5), 1)))

    # make_shift_matrix
    assert (np.all(
        make_shift_matrix(np.arange(5), np.arange(2)) == np.array(
            [0, 1, 2, 3, 4, -1, 0, 1, 2, 3]).reshape((2, -1)).T))
Esempio n. 5
0
    cond3 = np.loadtxt(path_to_data + i +
                       "/model/model001/onsets/task001_run001/cond003.txt")

    TR = 2
    tr_times = np.arange(0, 30, TR)
    hrf_at_trs = np.array([hrf_single(x) for x in tr_times])

    # creating the .txt file for the events2neural function
    cond_all = np.row_stack((cond1, cond2, cond3))
    cond_all = sorted(cond_all, key=lambda x: x[0])

    cond_all = np.array(cond_all)[:, 0]

    delta_y = 2 * (np.arange(34)) / 34

    shifted = make_shift_matrix(cond_all, delta_y)

    def make_convolve_lambda(hrf_function, TR, num_TRs):
        convolve_lambda = lambda x: np_convolve_30_cuts(
            x, np.ones(x.shape[0]), hrf_function, TR,
            np.linspace(0, (num_TRs - 1) * TR, num_TRs), 15)[0]

        return convolve_lambda

    convolve_lambda = make_convolve_lambda(hrf_single, TR, num_TR)

    hrf_matrix = time_correct(convolve_lambda, shifted, num_TR)

    np.savetxt("../data/hrf/" + i + "_hrf.txt", hrf_matrix)

    sys.stdout.write("-")
Esempio n. 6
0
    cond3 = np.loadtxt(path_to_data + i +
                       "/model/model001/onsets/task001_run001/cond003.txt")

    TR = 2
    tr_times = np.arange(0, 30, TR)
    hrf_at_trs = np.array([hrf_single(x) for x in tr_times])

    # creating the .txt file for the events2neural function
    cond_all = np.row_stack((cond1, cond2, cond3))
    cond_all = sorted(cond_all, key=lambda x: x[0])

    cond_all = np.array(cond_all)[:, 0]

    delta_y = 2 * (np.arange(34)) / 34

    shifted_all = make_shift_matrix(cond_all, delta_y)
    shifted_1 = make_shift_matrix(cond1[:, 0], delta_y)
    shifted_2 = make_shift_matrix(cond2[:, 0], delta_y)
    shifted_3 = make_shift_matrix(cond3[:, 0], delta_y)

    #########################################
    #Create convovled HRF for each condition#
    #########################################


    def make_convolve_lambda(hrf_function, TR, num_TRs):
        convolve_lambda = lambda x: np_convolve_30_cuts(
            x, np.ones(x.shape[0]), hrf_function, TR,
            np.linspace(0, (num_TRs - 1) * TR, num_TRs), 15)

        return convolve_lambda
def test_time_shift_4():
    happy2=make_shift_matrix(np.arange(100),np.array([1,3,5]))

    assert(np.all(happy2[:,0]== -1+np.arange(100)))

    assert(np.all(happy2[:,2]== -5+np.arange(100)))
    cond3=np.loadtxt(path_to_data+ i+ "/model/model001/onsets/task001_run001/cond003.txt")
    
    TR = 2
    tr_times = np.arange(0, 30, TR)
    hrf_at_trs = np.array([hrf_single(x) for x in tr_times])

    # creating the .txt file for the events2neural function
    cond_all=np.row_stack((cond1,cond2,cond3))
    cond_all=sorted(cond_all,key= lambda x:x[0])

    cond_all=np.array(cond_all)[:,0]
    
    delta_y=2*(np.arange(34))/34


    shifted=make_shift_matrix(cond_all,delta_y)
    
    def make_convolve_lambda(hrf_function,TR,num_TRs):
        convolve_lambda=lambda x: np_convolve_30_cuts(x,np.ones(x.shape[0]),hrf_function,TR,np.linspace(0,(num_TRs-1)*TR,num_TRs),15)[0]
        
        return convolve_lambda
        
    convolve_lambda=make_convolve_lambda(hrf_single,TR,num_TR)
    
    hrf_matrix=time_correct(convolve_lambda,shifted,num_TR)
    
    np.savetxt("../data/hrf/"+i+"_hrf.txt",hrf_matrix)
    
    sys.stdout.write("-")
    sys.stdout.flush()
    
    cond2=np.loadtxt(path_to_data+ i+ "/model/model001/onsets/task001_run001/cond002.txt")
    cond3=np.loadtxt(path_to_data+ i+ "/model/model001/onsets/task001_run001/cond003.txt")

    TR = 2
    tr_times = np.arange(0, 30, TR)
    hrf_at_trs = np.array([hrf_single(x) for x in tr_times])

    # creating the .txt file for the events2neural function
    cond_all=np.row_stack((cond1,cond2,cond3))
    cond_all=sorted(cond_all,key= lambda x:x[0])

    cond_all=np.array(cond_all)[:,0]

    delta_y=2*(np.arange(34))/34

    shifted_all=make_shift_matrix(cond_all,delta_y)
    shifted_1= make_shift_matrix(cond1[:,0],delta_y)
    shifted_2= make_shift_matrix(cond2[:,0],delta_y)
    shifted_3= make_shift_matrix(cond3[:,0],delta_y)


    def make_convolve_lambda(hrf_function,TR,num_TRs):
        convolve_lambda=lambda x: np_convolve_30_cuts(x,np.ones(x.shape[0]),hrf_function,TR,np.linspace(0,(num_TRs-1)*TR,num_TRs),15)
    
        return convolve_lambda
    
    convolve_lambda=make_convolve_lambda(hrf_single,TR,num_TR)

    hrf_matrix_all=time_correct(convolve_lambda,shifted_all,num_TR)
    hrf_matrix_1=time_correct(convolve_lambda,shifted_1,num_TR)
    hrf_matrix_2=time_correct(convolve_lambda,shifted_2,num_TR)
Esempio n. 10
0
def test_time_shift_4():
    happy2 = make_shift_matrix(np.arange(100), np.array([1, 3, 5]))

    assert (np.all(happy2[:, 0] == -1 + np.arange(100)))

    assert (np.all(happy2[:, 2] == -5 + np.arange(100)))