def create_mapping((sub, hemi)): print sub, hemi complex_file = '/scr/ilz3/myelinconnect/struct/surf_%s/orig/mid_surface/%s_%s_mid.vtk' simple_file = '/scr/ilz3/myelinconnect/groupavg/indv_space/%s/lowres_%s_d_def.vtk'# version d log_file = '/scr/ilz3/myelinconnect/all_data_on_simple_surf/labels/logs/log_worker_%s.txt'%(str(os.getpid())) seed_file = '/scr/ilz3/myelinconnect/all_data_on_simple_surf/seeds/%s_%s_highres2lowres_seeds.npy' label_file = '/scr/ilz3/myelinconnect/all_data_on_simple_surf/labels/%s_%s_highres2lowres_labels.npy' surf_label_file = '/scr/ilz3/myelinconnect/all_data_on_simple_surf/labels/%s_%s_highres2lowres_labels.vtk' # load the meshes log(log_file, 'Processing %s %s'%(sub, hemi)) log(log_file, '...loading data', logtime=False) complex_v, complex_f, complex_d = read_vtk(complex_file%(hemi, sub, hemi)) simple_v, simple_f, simple_d = read_vtk(simple_file%(sub, hemi)) # find those points on the individuals complex mesh that correspond best # to the simplified group mesh in subject space log(log_file, '...finding unique voronoi seeds') try: voronoi_seed_idx = np.load(seed_file%(sub, hemi)) voronoi_seed_coord = complex_v[voronoi_seed_idx] except IOError: voronoi_seed_idx, inaccuracy = find_voronoi_seeds(simple_v, complex_v) np.save(seed_file%(sub, hemi), voronoi_seed_idx) # find coordinates of those points in the highres mesh voronoi_seed_coord = complex_v[voronoi_seed_idx] # double check differences log(log_file, '...checking unique vs nearest mapping') dist = np.linalg.norm((voronoi_seed_coord - simple_v), axis=1) if ((np.mean(dist)-np.mean(inaccuracy[:,0])>0.1)): log(log_file, 'Unique seeds very far from nearest seeds!') return dist sys.exit("Unique seeds very far from nearest seeds %s %s"%(sub,hemi)) # convert highres mesh into graph containing edge length log(log_file, '...creating graph') complex_graph = graph_from_mesh(complex_v, complex_f, edge_length=True) # find the actual labels log(log_file, '...competetive fast marching') labels = competetive_fast_marching(complex_v, complex_graph, voronoi_seed_idx) # write out labelling file and surface with labels log(log_file, '...saving data') np.save(label_file%(sub, hemi), labels) write_vtk(surf_label_file%(sub, hemi), complex_v, complex_f, data=labels[:,1, np.newaxis]) log(log_file, 'Finished %s %s'%(sub, hemi)) return log_file
nonmask = np.delete(idcs, mask) embed = np.zeros(((lv.shape[0] + rv.shape[0]), 100)) embed[nonmask] = embed_masked # extend mask to nodes that have a t1avg < 1500 full_t1 = np.concatenate((lh_t1, rh_t1)) fullmask = np.unique(np.concatenate((mask, np.where(full_t1 <= 1500)[0]))) fullmask = np.asarray(fullmask, dtype='int64') nonmask_bigmask = np.delete(idcs, fullmask) # mask embedding and t1 masked_t1 = np.delete(full_t1, fullmask) masked_embed = np.delete(embed, fullmask, axis=0) # estimate sigma2_res from noise in T1 Gl = graph_from_mesh(lv, lf) Gr = graph_from_mesh(rv, rf) left_medians = [] for li in range(lv.shape[0]): neigh = Gl.neighbors(li) neigh_t1 = [full_t1[n] for n in neigh if not full_t1[n] == 0] neigh_dist = [np.abs(full_t1[li] - nt) for nt in neigh_t1] left_medians.append(np.median(neigh_dist)) right_medians = [] for ri in range(rv.shape[0]): neigh = [x + lv.shape[0] for x in Gr.neighbors(ri)] neigh_t1 = [full_t1[n] for n in neigh if not full_t1[n] == 0] neigh_dist = [ np.abs(full_t1[ri + lv.shape[0]] - nt) for nt in neigh_t1
for sub in subjects: for hemi in hemis: if os.path.isfile('/scr/ilz3/myelinconnect/all_data_on_simple_surf/labels/%s_%s_highres2lowres_labels.npy'%(sub, hemi)): print 'processing '+sub+' '+hemi # load data complex_v,complex_f, complex_d = read_vtk('/scr/ilz3/myelinconnect/struct/surf_%s/orig/mid_surface/%s_%s_mid.vtk'%(hemi, sub, hemi)) simple_v, simple_f, simple_d = read_vtk('/scr/ilz3/myelinconnect/groupavg/indv_space/%s/lowres_%s_d_def.vtk'%(sub, hemi)) labelling=np.load('/scr/ilz3/myelinconnect/all_data_on_simple_surf/labels/%s_%s_highres2lowres_labels.npy'%(sub, hemi)) seeds=np.load('/scr/ilz3/myelinconnect/all_data_on_simple_surf/seeds/%s_%s_highres2lowres_seeds.npy'%(sub, hemi)) # make an edge label surface and save it G = graph_from_mesh(complex_v, complex_f) edge_labelling = np.zeros_like(labelling[:,1]) for v in range(edge_labelling.shape[0]): if any(labelling[G.neighbors(v),1] != labelling[v,1]): edge_labelling[v] = 1 write_vtk(edge_file%(sub, hemi), complex_v, complex_f, data=edge_labelling[:,np.newaxis]) # make a no label surface and save it if np.where(labelling[:,1]==-1)[0].shape[0] >0: no_labelling = np.zeros_like(labelling[:,1]) for n in list(np.where(labelling[:,1]==-1)[0]): no_labelling[n] = 1 write_vtk(no_file%(sub, hemi), complex_v, complex_f, data=no_labelling[:,np.newaxis])
rv, rf = rsurf[0], rsurf[1] cortex = np.concatenate((lidx, ridx+lv.shape[0])) masked_myelin = np.load(myelin_file) masked_embed = np.load(embed_file) # unmask embedding and myelin full_embed = np.zeros(((lv.shape[0]+rv.shape[0]),300)) full_embed[cortex] = masked_embed full_myelin = np.zeros(lv.shape[0]+rv.shape[0],) full_myelin[cortex] = masked_myelin # estimate sigma2_res from noise in T1 Gl = graph_from_mesh(lv, lf) Gr = graph_from_mesh(rv, rf) left_medians= [] for li in range(lv.shape[0]): neigh = Gl.neighbors(li) neigh_myelin = [full_myelin[n] for n in neigh if not full_myelin[n]==0] neigh_dist = [np.abs(full_myelin[li] - nt) for nt in neigh_myelin] left_medians.append(np.median(neigh_dist)) right_medians = [] for ri in range(rv.shape[0]): neigh = [x + lv.shape[0] for x in Gr.neighbors(ri)] neigh_myelin = [full_myelin[n] for n in neigh if not full_myelin[n]==0] neigh_dist = [np.abs(full_myelin[ri+lv.shape[0]] - nt) for nt in neigh_myelin] right_medians.append(np.median(neigh_dist))