def test_2():
	x = np.arange(100)
	x2 = 50 - x
	mask = np.zeros((5,5,4))
	mask[:, 1:4, 1:3] = 1
	x3 = x.reshape((5, 5, 4))
	output3 = t_grouping_neighbor(x3, mask, 50, neighbors = 1,
						prop = False, abs_on = False, binary = True , off_value = 0,masked_value = .5)

	assert(np.sum(output3[0]) == 50)


	mask[:, 1:4, 1:3] = 1
	x4 = x2.reshape((5, 5, 4))
	output4 = t_grouping_neighbor(x4, mask, .5, neighbors = 2,
						prop = True, abs_on = True, binary = True , off_value = 0, masked_value = .5)

	assert(np.sum(output4[0]) == 50)

	# Test for when neighbors != None and binary == False
	output5 = t_grouping_neighbor(x4, mask, .5, neighbors = 2,
						prop = True, abs_on = True, binary = False, off_value = 0, masked_value = .5)
	assert(output5 == False)

	# Test for when binary == False
	output6 = t_grouping_neighbor(x4, mask, .5, neighbors = None,
						prop = True, abs_on = True, binary = False, off_value = 0, masked_value = .5)
	assert(np.sum(output6[0]) == 66)
def test_2():
    x = np.arange(100)
    x2 = 50 - x
    mask = np.zeros((5, 5, 4))
    mask[:, 1:4, 1:3] = 1
    x3 = x.reshape((5, 5, 4))
    output3 = t_grouping_neighbor(x3,
                                  mask,
                                  50,
                                  neighbors=1,
                                  prop=False,
                                  abs_on=False,
                                  binary=True,
                                  off_value=0,
                                  masked_value=.5)

    assert (np.sum(output3[0]) == 50)

    mask[:, 1:4, 1:3] = 1
    x4 = x2.reshape((5, 5, 4))
    output4 = t_grouping_neighbor(x4,
                                  mask,
                                  .5,
                                  neighbors=2,
                                  prop=True,
                                  abs_on=True,
                                  binary=True,
                                  off_value=0,
                                  masked_value=.5)

    assert (np.sum(output4[0]) == 50)

    # Test for when neighbors != None and binary == False
    output5 = t_grouping_neighbor(x4,
                                  mask,
                                  .5,
                                  neighbors=2,
                                  prop=True,
                                  abs_on=True,
                                  binary=False,
                                  off_value=0,
                                  masked_value=.5)
    assert (output5 == False)

    # Test for when binary == False
    output6 = t_grouping_neighbor(x4,
                                  mask,
                                  .5,
                                  neighbors=None,
                                  prop=True,
                                  abs_on=True,
                                  binary=False,
                                  off_value=0,
                                  masked_value=.5)
    assert (np.sum(output6[0]) == 66)
Example #3
0
    bh_final = neighbor_smoothing_binary(bh_3d_1_good, neighbors)

    bh_mean[..., i] = bh_3d_1_good

    #####################################
    # Run t_grouping for each subject   #
    #####################################
    t_3d = np.load("../data/t_stat/" + name + "_tstat.npy")

    #mask = fitted_mask
    t_group = t_grouping_neighbor(t_3d,
                                  mask,
                                  prop_t,
                                  neighbors=neighbors,
                                  prop=True,
                                  abs_on=True,
                                  binary=True,
                                  off_value=0,
                                  masked_value=.5)[0]

    t_mean[..., i] = t_group

    ######################################
    # Run beta grouping for each subject #
    ######################################
    beta_3d = np.load("../data/betas/" + name + "_beta.npy")
    beta_group = t_grouping_neighbor(beta_3d,
                                     mask,
                                     prop_beta,
                                     neighbors=neighbors,
Example #4
0
########## Final Output    ##########
#####################################

#Create final output.
total=np.zeros((3*64,3*64))

ward = label
t_final = data_new

prop_t = 0.15

rachels_ones = np.ones((64, 64, 34))
fitted_mask = make_mask(rachels_ones, mask_data, fit = True)
fitted_mask[fitted_mask > 0] = 1
neighbors=1
t_cluster = t_grouping_neighbor(t_stat, fitted_mask, prop_t, neighbors = neighbors, prop = True, abs_on = True, binary = True, off_value = 0, masked_value = .5)[0]
t_cluster = t_cluster[...,19:22]


t_final_abs_max = np.max(abs(t_final))



for i in range(ward.shape[-1]):
    total[(i*64):((i+1)*64),0:64]=ward[...,i]*1/5 - 2/5 # centering around 0
    
for i in range(t_final.shape[-1]):
    total[(i*64):((i+1)*64),64:128]=t_final[...,i]*1/t_final_abs_max # centering around 0
    
for i in range(t_cluster.shape[-1]):
    total[(i*64):((i+1)*64),128:192]=t_cluster[...,i] -1/2 # centering around 0
##############

toolbar_width=len(prod2)
sys.stdout.write("T - Analysis:       ")
sys.stdout.write("[%s]" % (" " * toolbar_width))
sys.stdout.flush()
sys.stdout.write("\b" * (toolbar_width+1)) # return to start of line, after '['
    




t_val=[] #values c*5 + d - 1
count_c=0
for c,d in itertools.product(range(5),range(5)):
	second=t_grouping_neighbor(t_3d, mask, prod2[c], neighbors= neighbors2[d],
					prop=True,abs_on=True, binary=True ,off_value=0,masked_value=.5)[0]
	t_val.append(second)

	if count_c==c and d==4:
		sys.stdout.write("-")
		sys.stdout.flush()
		count_c+=1
sys.stdout.write("\n")


#------------------#
# Image comparison #
#------------------#


present_t = np.ones((5*64,5*64))
Example #6
0
total = np.zeros((3 * 64, 3 * 64))

ward = label
t_final = data_new

prop_t = 0.15

rachels_ones = np.ones((64, 64, 34))
fitted_mask = make_mask(rachels_ones, mask_data, fit=True)
fitted_mask[fitted_mask > 0] = 1
neighbors = 1
t_cluster = t_grouping_neighbor(t_stat,
                                fitted_mask,
                                prop_t,
                                neighbors=neighbors,
                                prop=True,
                                abs_on=True,
                                binary=True,
                                off_value=0,
                                masked_value=.5)[0]
t_cluster = t_cluster[..., 19:22]

t_final_abs_max = np.max(abs(t_final))

for i in range(ward.shape[-1]):
    total[(i * 64):((i + 1) * 64),
          0:64] = ward[..., i] * 1 / 5 - 2 / 5  # centering around 0

for i in range(t_final.shape[-1]):
    total[(i * 64):((i + 1) * 64),
          64:128] = t_final[..., i] * 1 / t_final_abs_max  # centering around 0
Example #7
0
mask = make_mask(inner_ones, mask, True)

mask[mask > 0] = 1

t_vals = t

t_vals_3d = t_vals.reshape(data.shape[:-1])

pro = [.25, .1, .1, .05, .025]
folks = [1, 1, 5, 5, 10]

plt.close()
for i in np.arange(5):
    start, cutoff = t_grouping_neighbor(t_vals_3d,
                                        mask,
                                        pro[i],
                                        prop=True,
                                        neighbors=folks[i],
                                        abs_on=True)
    plt.imshow(present_3d(2 * start - 1),
               interpolation='nearest',
               cmap="seismic")
    plt.title("T statistics " + str(pro[i]) + " proportion \n (cutoff=" +
              str(cutoff) + ") , neighbors: " + str(folks[i]))
    plt.colorbar()
    plt.savefig(location_of_images + str(pro[i]) + "_" + str(folks[i]) +
                "_t.png")
    plt.close()

##################
# Beta           #
##################
mask= make_mask(inner_ones,mask,True)

mask[mask>0]=1


t_vals=t


t_vals_3d=t_vals.reshape(data.shape[:-1])

pro=[.25,.1,.1,.05,.025]
folks=[1,1,5,5,10]

plt.close()
for i in np.arange(5):
	start,cutoff=t_grouping_neighbor(t_vals_3d,mask,pro[i],prop=True,neighbors= folks[i],abs_on=True)
	plt.imshow(present_3d(2*start-1),interpolation='nearest',cmap="seismic")
	plt.title("T statistics " +str(pro[i])+" proportion \n (cutoff=" + str(cutoff)+") , neighbors: " + str(folks[i]))
	plt.colorbar()
	plt.savefig(location_of_images+str(pro[i])+"_" + str(folks[i])+"_t.png")
	plt.close()


##################
# Beta           #
##################
b1 = B[1]
#cutoff = .6
b1_vals_3d=b1.reshape(data.shape[:-1])
pro=[.25,.1,.1,.05,.025]
folks=[1,1,5,5,10]
toolbar_width = len(prod2)
sys.stdout.write("T - Analysis:       ")
sys.stdout.write("[%s]" % (" " * toolbar_width))
sys.stdout.flush()
sys.stdout.write("\b" *
                 (toolbar_width + 1))  # return to start of line, after '['

t_val = []  #values c*5 + d - 1
count_c = 0
for c, d in itertools.product(range(5), range(5)):
    second = t_grouping_neighbor(t_3d,
                                 mask,
                                 prod2[c],
                                 neighbors=neighbors2[d],
                                 prop=True,
                                 abs_on=True,
                                 binary=True,
                                 off_value=0,
                                 masked_value=.5)[0]
    t_val.append(second)

    if count_c == c and d == 4:
        sys.stdout.write("-")
        sys.stdout.flush()
        count_c += 1
sys.stdout.write("\n")

#------------------#
# Image comparison #
#------------------#
	bh_first = bh_procedure(p_bh, q)
	bh_3d    = masking_reshape_end(bh_first, mask, off_value = .5)
	bh_3d[bh_3d < .5] = 0
	bh_3d_1_good = 1 - bh_3d

	bh_final  = neighbor_smoothing_binary(bh_3d_1_good, neighbors)

	bh_mean[..., i] = bh_3d_1_good

	#####################################
	# Run t_grouping for each subject   #
	#####################################
	t_3d = np.load("../data/t_stat/" + name + "_tstat.npy")

	#mask = fitted_mask
	t_group = t_grouping_neighbor(t_3d, mask, prop_t, neighbors = neighbors,
					prop = True, abs_on = True, binary = True, off_value = 0, masked_value = .5)[0]

	t_mean[..., i] = t_group

	######################################
	# Run beta grouping for each subject #
	######################################
	beta_3d = np.load("../data/betas/" + name + "_beta.npy")
	beta_group = t_grouping_neighbor(beta_3d, mask, prop_beta, neighbors = neighbors,
						prop = True, abs_on = True, binary = True, off_value = 0, masked_value = .5)[0]

	beta_mean[..., i] = beta_group

	sys.stdout.write("-")
	sys.stdout.flush()