def isolated(XYZ, k=18): """ Outputs an index I of isolated points from their integer coordinates, XYZ (3, n), and under k-connectivity, k = 6, 18 or 24. """ A, B, D = FG.graph_3d_grid(XYZ.transpose(),k) # Number of vertices V = max(A) + 1 # Labels of connected components label = FG.graph_cc(A,B,D,V) # Isolated points ncc = label.max() + 1 p = XYZ.shape[1] size = np.zeros(ncc, float) ones = np.ones((p, 1), float) add_lines(ones, size.reshape(ncc, 1), label) return np.where(size[label] == 1)[0]
def test_onesample_graph(self): data, vardata, XYZ = make_data() A, B, D = fg.graph_3d_grid(XYZ.transpose()) V = max(A) + 1 E = len(A) edges = np.concatenate((A.reshape(E, 1), B.reshape(E, 1)), axis=1) weights = D G = fg.WeightedGraph(V, edges, weights) # rfx calibration P = PT.permutation_test_onesample_graph(data, G, ndraws=ndraws) c = [(P.random_Tvalues[P.ndraws*(0.95)],None)] r = np.ones(data.shape[1],int) r[data.shape[1]/2:] *= 10 #p_values, cluster_results, region_results = P.calibrate(nperms=100, clusters=c, regions=[r]) # mfx calibration P = PT.permutation_test_onesample_graph(data, G, vardata=vardata, stat_id="student_mfx", ndraws=ndraws) p_values, cluster_results, region_results = P.calibrate(nperms=nperms, clusters=c, regions=[r])
def extract_clusters_from_thresh(T,XYZ,th,k=18): """ Extract clusters from statistical map above specified threshold In: T (p) statistical map XYZ (3,p) voxels coordinates th <float> threshold k <int> the number of neighbours considered. (6,18 or 26) Out: labels (p) cluster labels """ labels = -np.ones(len(T),int) I = np.where(T >= th)[0] if len(I)>0: SupraThreshXYZ = XYZ[:, I] # Compute graph associated to suprathresh_coords A, B, D = graph_3d_grid(SupraThreshXYZ.transpose(),k) # Number of vertices V = max(A) + 1 # Labels of connected components CC_label = graph_cc(A,B,D,V) labels[I] = CC_label return labels