Пример #1
0
def test_3():
	# checks that neighbor_smoothing works
	b = np.array([[np.arange(3), np.arange(3), np.arange(3)], [np.arange(3), np.arange(3), np.arange(3)], [np.arange(3), np.arange(3), np.arange(3)]])
	a = b*-1

	assert(len(a.shape) == 3)
	assert(a.shape == (3, 3, 3))
	a_n = neighbor_smoothing(a, 3)

	assert_almost_equal(a_n, a)

	ones = np.ones((3, 3, 3))

	rachel = np.ones((3, 3, 3))
	rachel[1, 1, 1] = -1
	rachel_n = neighbor_smoothing(rachel, 2)
	assert_array_almost_equal(rachel_n, ones)
Пример #2
0
def t_grouping_neighbor(t_3d,
                        mask,
                        cutoff,
                        neighbors=None,
                        prop=False,
                        abs_on=False,
                        binary=True,
                        off_value=0,
                        masked_value=.5):
    """
	Masks a 3d array, does t_binary_grouping, and does neighboring 

	Parameters
	----------
    t_3d:      t-value of the betas 3d numpy array
    mask:      a 3d numpy array of 0s and 1s that has the same shape as t_3d
    cutoff:    the limit for the false discovery rate
    neighbors: number of neighbors for neighbor smoothing (must have binary be true)

    prop:      logical~ if the cutoff is a proportion or a value
    abs_on:    logical~ if we want to take absolute value of the t input
    binary:    if binary, then off_value is ignored and 0 is used as the 
    			off_value, 1 as the on value
    off_value: the value of those not selected


	Returns
    -------
    output_3d:  a 3d numpy array same size as the t_3d with either:
    			 (1) binary on_off values for inside the mask and "masked_value" 
    			 for values outside mask or (2) t values to the accepted values, 
    			 and "off_values" for lost values, and "masked_value" for values 
    			 outside mask. MOREOVER, it can have had neighbor smoothing applied 
    			 the binary case
    cutoff: the limit for the false discovery rate

	"""
    if neighbors != None and binary == False:
        return False

    t_1d = masking_reshape_start(t_3d, mask)
    t_1d = np.ravel(t_1d)
    zero_one, cutoff = t_binary_grouping(t_1d, cutoff, prop, abs_on)

    if not binary:
        t_1d = t_1d * zero_one + off_value * (1 - zero_one)
    else:
        t_1d = zero_one

    output_3d = masking_reshape_end(t_1d, mask, masked_value)

    if neighbors != None:
        output_3d = neighbor_smoothing(output_3d, neighbors)

    return output_3d, cutoff
Пример #3
0
def t_grouping_neighbor(t_3d, mask, cutoff, neighbors = None,
						prop = False, abs_on = False, binary = True, off_value = 0, masked_value = .5):
	"""
	Masks a 3d array, does t_binary_grouping, and does neighboring 

	Parameters
	----------
    t_3d:      t-value of the betas 3d numpy array
    mask:      a 3d numpy array of 0s and 1s that has the same shape as t_3d
    cutoff:    the limit for the false discovery rate
    neighbors: number of neighbors for neighbor smoothing (must have binary be true)

    prop:      logical~ if the cutoff is a proportion or a value
    abs_on:    logical~ if we want to take absolute value of the t input
    binary:    if binary, then off_value is ignored and 0 is used as the 
    			off_value, 1 as the on value
    off_value: the value of those not selected


	Returns
    -------
    output_3d:  a 3d numpy array same size as the t_3d with either:
    			 (1) binary on_off values for inside the mask and "masked_value" 
    			 for values outside mask or (2) t values to the accepted values, 
    			 and "off_values" for lost values, and "masked_value" for values 
    			 outside mask. MOREOVER, it can have had neighbor smoothing applied 
    			 the binary case
    cutoff: the limit for the false discovery rate

	"""
	if neighbors != None and binary == False:
		return False

	t_1d = masking_reshape_start(t_3d, mask)
	t_1d = np.ravel(t_1d)
	zero_one, cutoff = t_binary_grouping(t_1d, cutoff, prop, abs_on)

	if not binary:
		t_1d = t_1d*zero_one + off_value*(1 - zero_one)
	else:
		t_1d = zero_one

	output_3d = masking_reshape_end(t_1d, mask, masked_value)

	if neighbors != None:
		output_3d = neighbor_smoothing(output_3d, neighbors)

	return output_3d, cutoff
Пример #4
0
# plot this
plt.imshow(present_3d(to_3d), interpolation='nearest', cmap='seismic')
plt.title(str(Q) + " with masked p-values")

plt.savefig(location_of_images + "masked_pval_" + str(Q) + ".png")
plt.figure()
plt.close()
print("# ==== END mask_phase_2_dimension_change plotting ==== #")

# Smoothing/clustering on the masked p-values
print("# ==== BEGIN smoothed masked p-value plotting ==== #")

# Where the neighbor_smoothing function should start
print("# == NEIGHBOR SMOOTHING 5")
smoothed = neighbor_smoothing(to_3d, 5)

plt.imshow(present_3d(smoothed), interpolation='nearest', cmap='seismic')
plt.title(str(Q) + " with neightbor-smoothing factor 5")

plt.savefig(location_of_images + "5neighbor_smooth_pval_" + str(Q) + ".png")
plt.figure()
plt.close()

print("# == NEIGHBOR SMOOTHING 10")
smoothed = neighbor_smoothing(to_3d, 10)
plt.imshow(present_3d(smoothed), interpolation='nearest', cmap='seismic')
plt.title(str(Q) + " with neightbor-smoothing factor 10")
plt.savefig(location_of_images + "10neighbor_smooth_pval_" + str(Q) + ".png")
plt.figure()
plt.close()
Пример #5
0
plt.imshow(present_3d(to_3d),interpolation='nearest', cmap='seismic')
plt.title(str(Q) + " with masked p-values")
#plt.colorbar()
plt.savefig(location_of_images + "masked_pval_" + str(Q) + ".png")
plt.figure()
plt.close()
print("# ==== END mask_phase_2_dimension_change plotting ==== #")

# Smoothing/clustering on the masked p-values
print("# ==== BEGIN smoothed masked p-value plotting ==== #")

#test = to_3d

# Where the neighbor_smoothing function should start
print("# == NEIGHBOR SMOOTHING 5")
smoothed = neighbor_smoothing(to_3d, 5)
#off = np.max(test)
#for i in 1 + np.arange(62):
#	for j in 1 + np.arange(62):
#		for k in 1 + np.arange(32):
			# number of neighbors that need to be positivednm
#			if np.sum(to_3d[(i - 1):(i + 2),(j - 1):(j + 2),(k - 1):(k + 2)] < 0) < 5 and to_3d[i, j, k] < 0:
#				test[i, j, k] = off
#print(to_3d)
#print(test)
plt.imshow(present_3d(smoothed), interpolation='nearest', cmap='seismic')
plt.title(str(Q) + " with neightbor-smoothing factor 5")
#plt.colorbar()
plt.savefig(location_of_images + "5neighbor_smooth_pval_" + str(Q) + ".png")
plt.figure()
plt.close()