How to use the cython.cy_numstats.resid_covars function in Cython

To help you get started, we’ve selected a few Cython examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github trislett / TFCE_mediation / STEP_1_vertex_tfce_multiple_regression.py View on Github external
num_vertex_lh = data_lh.shape[0]
data_rh = data_rh[bin_mask_rh]
num_vertex_rh = data_rh.shape[0]
num_vertex = num_vertex_lh + num_vertex_rh
all_vertex = data_full_lh.shape[0]

if opts.input: 
#load variables
	arg_predictor = opts.input[0]
	arg_covars = opts.input[1]
	pred_x = np.genfromtxt(arg_predictor, delimiter=',')
	covars = np.genfromtxt(arg_covars, delimiter=',')
#step1
	x_covars = np.column_stack([np.ones(n),covars])
	y_lh = resid_covars(x_covars,data_lh)
	y_rh = resid_covars(x_covars,data_rh)
	merge_y=np.hstack((y_lh,y_rh))
	del y_lh
	del y_rh
if opts.regressors:
	arg_predictor = opts.regressors[0]
	pred_x = np.genfromtxt(arg_predictor, delimiter=',')
	merge_y=np.hstack((data_lh.T,data_rh.T))

#save variables
if not os.path.exists("python_temp_%s" % (surface)):
	os.mkdir("python_temp_%s" % (surface))

np.save("python_temp_%s/pred_x" % (surface),pred_x)
np.save("python_temp_%s/num_subjects" % (surface),n)
np.save("python_temp_%s/all_vertex" % (surface),all_vertex)
np.save("python_temp_%s/num_vertex" % (surface),num_vertex)
github trislett / TFCE_mediation / STEP_1_vertex_tfce_mediation.py View on Github external
np.save("python_temp_med_%s/pred_x" % surface,pred_x)
np.save("python_temp_med_%s/covars" % surface,covars)
np.save("python_temp_med_%s/depend_y" % surface,depend_y)
np.save("python_temp_med_%s/num_subjects" % surface,n)
np.save("python_temp_med_%s/num_vertex" % surface,num_vertex)
np.save("python_temp_med_%s/num_vertex_lh" % (surface),num_vertex_lh)
np.save("python_temp_med_%s/num_vertex_rh" % (surface),num_vertex_rh)
np.save("python_temp_med_%s/all_vertex" % (surface),all_vertex)
np.save("python_temp_med_%s/bin_mask_lh" % (surface),bin_mask_lh)
np.save("python_temp_med_%s/bin_mask_rh" % (surface),bin_mask_rh)
np.save("python_temp_med_%s/adjac_lh" % (surface),adjac_lh)
np.save("python_temp_med_%s/adjac_rh" % (surface),adjac_rh)

#step1
x_covars = np.column_stack([np.ones(n),covars])
y_lh = resid_covars(x_covars,data_lh)
y_rh = resid_covars(x_covars,data_rh)
del data_lh
del data_rh
merge_y = np.hstack((y_lh,y_rh))
np.save("python_temp_med_%s/merge_y" % (surface),merge_y.astype(np.float32, order = "C"))
del y_lh
del y_rh

#step2 mediation
SobelZ = calc_sobelz(medtype, pred_x, depend_y, merge_y, n, num_vertex)

#write TFCE images
if not os.path.exists("output_med_%s" % surface):
	os.mkdir("output_med_%s" % surface)
os.chdir("output_med_%s" % surface)
github trislett / TFCE_mediation / STEP_1_vertex_tfce_mediation.py View on Github external
np.save("python_temp_med_%s/covars" % surface,covars)
np.save("python_temp_med_%s/depend_y" % surface,depend_y)
np.save("python_temp_med_%s/num_subjects" % surface,n)
np.save("python_temp_med_%s/num_vertex" % surface,num_vertex)
np.save("python_temp_med_%s/num_vertex_lh" % (surface),num_vertex_lh)
np.save("python_temp_med_%s/num_vertex_rh" % (surface),num_vertex_rh)
np.save("python_temp_med_%s/all_vertex" % (surface),all_vertex)
np.save("python_temp_med_%s/bin_mask_lh" % (surface),bin_mask_lh)
np.save("python_temp_med_%s/bin_mask_rh" % (surface),bin_mask_rh)
np.save("python_temp_med_%s/adjac_lh" % (surface),adjac_lh)
np.save("python_temp_med_%s/adjac_rh" % (surface),adjac_rh)

#step1
x_covars = np.column_stack([np.ones(n),covars])
y_lh = resid_covars(x_covars,data_lh)
y_rh = resid_covars(x_covars,data_rh)
del data_lh
del data_rh
merge_y = np.hstack((y_lh,y_rh))
np.save("python_temp_med_%s/merge_y" % (surface),merge_y.astype(np.float32, order = "C"))
del y_lh
del y_rh

#step2 mediation
SobelZ = calc_sobelz(medtype, pred_x, depend_y, merge_y, n, num_vertex)

#write TFCE images
if not os.path.exists("output_med_%s" % surface):
	os.mkdir("output_med_%s" % surface)
os.chdir("output_med_%s" % surface)

write_vertStat_img('SobelZ_%s' % (medtype),SobelZ[:num_vertex_lh],outdata_mask_lh, affine_mask_lh, surface, 'lh', bin_mask_lh, calcTFCE_lh, all_vertex)
github trislett / TFCE_mediation / STEP_1_multiple_regression_vertexTFCE.py View on Github external
num_vertex_lh = data_lh.shape[0]
data_rh = data_rh[bin_mask_rh]
num_vertex_rh = data_rh.shape[0]
num_vertex = num_vertex_lh + num_vertex_rh
all_vertex = data_full_lh.shape[0]

if opts.input: 
#load variables
	arg_predictor = opts.input[0]
	arg_covars = opts.input[1]
	pred_x = np.genfromtxt(arg_predictor, delimiter=',')
	covars = np.genfromtxt(arg_covars, delimiter=',')
#step1
	x_covars = np.column_stack([np.ones(n),covars])
	y_lh = resid_covars(x_covars,data_lh)
	y_rh = resid_covars(x_covars,data_rh)
	merge_y=np.hstack((y_lh,y_rh))
	del y_lh
	del y_rh
if opts.regressors:
	arg_predictor = opts.regressors[0]
	pred_x = np.genfromtxt(arg_predictor, delimiter=',')
	merge_y=np.hstack((data_lh.T,data_rh.T))

#save variables
if not os.path.exists("python_temp_%s" % (surface)):
	os.mkdir("python_temp_%s" % (surface))

np.save("python_temp_%s/pred_x" % (surface),pred_x)
np.save("python_temp_%s/num_subjects" % (surface),n)
np.save("python_temp_%s/all_vertex" % (surface),all_vertex)
np.save("python_temp_%s/num_vertex" % (surface),num_vertex)
github trislett / TFCE_mediation / STEP_1_voxel_tfce_mediation.py View on Github external
header_mask = np.load('python_temp/header_mask.npy')
affine_mask = np.load('python_temp/affine_mask.npy')
data_mask = np.load('python_temp/data_mask.npy')
data_index = data_mask>0.99
num_voxel = np.load('python_temp/num_voxel.npy')
pred_x = np.genfromtxt(arg_predictor, delimiter=",")
covars = np.genfromtxt(arg_covars, delimiter=",")
depend_y = np.genfromtxt(arg_depend, delimiter=",")

#TFCE
adjac = create_adjac_voxel(data_index,data_mask,num_voxel,dirtype=opts.tfce[2])
calcTFCE = Surf(float(opts.tfce[0]), float(opts.tfce[1]), adjac) # i.e. default: H=2, E=2, 26 neighbour connectivity

#step1
x_covars = np.column_stack([np.ones(n),covars])
y = resid_covars(x_covars,raw_nonzero)

#save
np.save('python_temp/pred_x',pred_x)
np.save('python_temp/covars',covars)
np.save('python_temp/depend_y',depend_y)
np.save('python_temp/adjac',adjac)
np.save('python_temp/medtype',medtype)
np.save('python_temp/optstfce', opts.tfce)
np.save('python_temp/raw_nonzero_corr',y.T.astype(np.float32, order = "C"))

#step2 mediation
SobelZ = calc_sobelz(medtype, pred_x, depend_y, y, n, num_voxel)

#write TFCE images
if not os.path.exists("output_med_%s" % medtype):
	os.mkdir("output_med_%s" % medtype)
github trislett / TFCE_mediation / STEP_1_vertex_tfce_multiple_regression.py View on Github external
data_lh = data_lh[bin_mask_lh]
num_vertex_lh = data_lh.shape[0]
data_rh = data_rh[bin_mask_rh]
num_vertex_rh = data_rh.shape[0]
num_vertex = num_vertex_lh + num_vertex_rh
all_vertex = data_full_lh.shape[0]

if opts.input: 
#load variables
	arg_predictor = opts.input[0]
	arg_covars = opts.input[1]
	pred_x = np.genfromtxt(arg_predictor, delimiter=',')
	covars = np.genfromtxt(arg_covars, delimiter=',')
#step1
	x_covars = np.column_stack([np.ones(n),covars])
	y_lh = resid_covars(x_covars,data_lh)
	y_rh = resid_covars(x_covars,data_rh)
	merge_y=np.hstack((y_lh,y_rh))
	del y_lh
	del y_rh
if opts.regressors:
	arg_predictor = opts.regressors[0]
	pred_x = np.genfromtxt(arg_predictor, delimiter=',')
	merge_y=np.hstack((data_lh.T,data_rh.T))

#save variables
if not os.path.exists("python_temp_%s" % (surface)):
	os.mkdir("python_temp_%s" % (surface))

np.save("python_temp_%s/pred_x" % (surface),pred_x)
np.save("python_temp_%s/num_subjects" % (surface),n)
np.save("python_temp_%s/all_vertex" % (surface),all_vertex)
github trislett / TFCE_mediation / STEP_1_mediation_vertexTFCE.py View on Github external
np.save("python_temp_med_%s/covars" % surface,covars)
np.save("python_temp_med_%s/depend_y" % surface,depend_y)
np.save("python_temp_med_%s/num_subjects" % surface,n)
np.save("python_temp_med_%s/num_vertex" % surface,num_vertex)
np.save("python_temp_med_%s/num_vertex_lh" % (surface),num_vertex_lh)
np.save("python_temp_med_%s/num_vertex_rh" % (surface),num_vertex_rh)
np.save("python_temp_med_%s/all_vertex" % (surface),all_vertex)
np.save("python_temp_med_%s/bin_mask_lh" % (surface),bin_mask_lh)
np.save("python_temp_med_%s/bin_mask_rh" % (surface),bin_mask_rh)
np.save("python_temp_med_%s/adjac_lh" % (surface),adjac_lh)
np.save("python_temp_med_%s/adjac_rh" % (surface),adjac_rh)

#step1
x_covars = np.column_stack([np.ones(n),covars])
y_lh = resid_covars(x_covars,data_lh)
y_rh = resid_covars(x_covars,data_rh)
del data_lh
del data_rh
merge_y = np.hstack((y_lh,y_rh))
np.save("python_temp_med_%s/merge_y" % (surface),merge_y.astype(np.float32, order = "C"))
del y_lh
del y_rh

#step2 mediation
SobelZ = calc_sobelz(medtype, pred_x, depend_y, merge_y, n, num_vertex)

#write TFCE images
if not os.path.exists("output_med_%s" % surface):
	os.mkdir("output_med_%s" % surface)
os.chdir("output_med_%s" % surface)

write_vertStat_img('SobelZ_%s' % (medtype),SobelZ[:num_vertex_lh],outdata_mask_lh, affine_mask_lh, surface, 'lh', bin_mask_lh, calcTFCE_lh, all_vertex)
github trislett / TFCE_mediation / STEP_1_voxel_tfce_multiple_regression.py View on Github external
if opts.input:
	pred_x = np.genfromtxt(opts.input[0], delimiter=',')
	covars = np.genfromtxt(opts.input[1], delimiter=',')
	x_covars = np.column_stack([np.ones(n),covars])
	y = resid_covars(x_covars,raw_nonzero)
	np.save('python_temp/covars',covars)
if opts.regressors:
	pred_x = np.genfromtxt(opts.regressors[0], delimiter=',')
	y = raw_nonzero.T
if opts.onesample:
	pred_x=np.ones(n)
	pred_x[:int(n/2)]=-1
	if opts.onesample[0] != 'none':
		covars = np.genfromtxt(opts.onesample[0], delimiter=',')
		x_covars = np.column_stack([np.ones(n),covars])
		y = resid_covars(x_covars,raw_nonzero)
		np.save('python_temp/covars',covars)
	else:
		y = raw_nonzero.T

ancova=0
if opts.ftest: 
	ancova=1

#TFCE
adjac = create_adjac_voxel(data_index,data_mask,num_voxel,dirtype=opts.tfce[2])
calcTFCE = Surf(float(opts.tfce[0]), float(opts.tfce[1]), adjac) # H=2, E=2, 26 neighbour connectivity

#save
np.save('python_temp/adjac',adjac)
np.save('python_temp/pred_x',pred_x)
np.save('python_temp/ancova', ancova)
github trislett / TFCE_mediation / STEP_1_mediation_vertexTFCE.py View on Github external
np.save("python_temp_med_%s/pred_x" % surface,pred_x)
np.save("python_temp_med_%s/covars" % surface,covars)
np.save("python_temp_med_%s/depend_y" % surface,depend_y)
np.save("python_temp_med_%s/num_subjects" % surface,n)
np.save("python_temp_med_%s/num_vertex" % surface,num_vertex)
np.save("python_temp_med_%s/num_vertex_lh" % (surface),num_vertex_lh)
np.save("python_temp_med_%s/num_vertex_rh" % (surface),num_vertex_rh)
np.save("python_temp_med_%s/all_vertex" % (surface),all_vertex)
np.save("python_temp_med_%s/bin_mask_lh" % (surface),bin_mask_lh)
np.save("python_temp_med_%s/bin_mask_rh" % (surface),bin_mask_rh)
np.save("python_temp_med_%s/adjac_lh" % (surface),adjac_lh)
np.save("python_temp_med_%s/adjac_rh" % (surface),adjac_rh)

#step1
x_covars = np.column_stack([np.ones(n),covars])
y_lh = resid_covars(x_covars,data_lh)
y_rh = resid_covars(x_covars,data_rh)
del data_lh
del data_rh
merge_y = np.hstack((y_lh,y_rh))
np.save("python_temp_med_%s/merge_y" % (surface),merge_y.astype(np.float32, order = "C"))
del y_lh
del y_rh

#step2 mediation
SobelZ = calc_sobelz(medtype, pred_x, depend_y, merge_y, n, num_vertex)

#write TFCE images
if not os.path.exists("output_med_%s" % surface):
	os.mkdir("output_med_%s" % surface)
os.chdir("output_med_%s" % surface)
github trislett / TFCE_mediation / STEP_1_multiple_regression_vertexTFCE.py View on Github external
data_lh = data_lh[bin_mask_lh]
num_vertex_lh = data_lh.shape[0]
data_rh = data_rh[bin_mask_rh]
num_vertex_rh = data_rh.shape[0]
num_vertex = num_vertex_lh + num_vertex_rh
all_vertex = data_full_lh.shape[0]

if opts.input: 
#load variables
	arg_predictor = opts.input[0]
	arg_covars = opts.input[1]
	pred_x = np.genfromtxt(arg_predictor, delimiter=',')
	covars = np.genfromtxt(arg_covars, delimiter=',')
#step1
	x_covars = np.column_stack([np.ones(n),covars])
	y_lh = resid_covars(x_covars,data_lh)
	y_rh = resid_covars(x_covars,data_rh)
	merge_y=np.hstack((y_lh,y_rh))
	del y_lh
	del y_rh
if opts.regressors:
	arg_predictor = opts.regressors[0]
	pred_x = np.genfromtxt(arg_predictor, delimiter=',')
	merge_y=np.hstack((data_lh.T,data_rh.T))

#save variables
if not os.path.exists("python_temp_%s" % (surface)):
	os.mkdir("python_temp_%s" % (surface))

np.save("python_temp_%s/pred_x" % (surface),pred_x)
np.save("python_temp_%s/num_subjects" % (surface),n)
np.save("python_temp_%s/all_vertex" % (surface),all_vertex)