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)
Example #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)
Example #3
0
    # 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()

sys.stdout.write("\n")

# if we want to save all the hrf matrices:
# 1 loops, best of 3: 1min 4s per loop
Example #4
0
    #########################################
    #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

    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)
    hrf_matrix_3 = time_correct(convolve_lambda, shifted_3, num_TR)

    n_vols = data.shape[-1]

    ##########################################
    # Create PCA features for our regression #
    ##########################################
    mask = nib.load(path_to_data + i + '/anatomy/inplane001_brain_mask.nii.gz')
    mask_data = mask.get_data()
    mask_data = make_mask(np.ones(data.shape[:-1]), mask_data, fit=True)
    mask_data = mask_data != 0
    mask_data = mask_data.astype(int)
    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()
    
sys.stdout.write("\n")

# if we want to save all the hrf matrices:
# 1 loops, best of 3: 1min 4s per loop

    
    
    
    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)
    hrf_matrix_3=time_correct(convolve_lambda,shifted_3,num_TR)

    n_vols = data.shape[-1]    


    mask = nib.load(path_to_data+i+'/anatomy/inplane001_brain_mask.nii.gz')
    mask_data = mask.get_data()
    mask_data = make_mask(np.ones(data.shape[:-1]), mask_data, fit=True)
    mask_data = mask_data!=0
    mask_data = mask_data.astype(int)

    ###PCA SHIT###