def show(): #brains=[(1,1),(1,2),(2,1),(3,1),(3,2)] brains=[(1,1),(2,1),(3,1)] ids=tl.emi_atlas() #print ids.keys() for (b,s) in brains: ids2 = pbc.load_pickle(path+'/Relabelling_8_sc1_'+str(b)+'_'+str(s)+'.pkl') #'/Relabelling_8_sc1_'+str(b)+'_'+str(s)+'.pkl' print b,s, ids2.keys() tracks = pbc.load_approximate_tracks(path,b,s) for i in ids: if i >0: r=fos.ren() color=np.array(ids[i]['color']) indices=ids2[i]['indices'] bundle=[tracks[ind] for ind in indices] fos.add(r,fos.line(bundle,color,opacity=0.9)) print 'Bundle_name',i,ids[i]['bundle_name'] fos.show(r,title=ids[i]['bundle_name'][0])
def print_all_overlaps(): brainscan_keys = [(1,1),(1,2),(2,1),(3,1),(3,2)] refdic = pbc.load_pickle('/home/ian/tractarian/refdic.pkl') for bs in brainscan_keys: refs=refdic[bs]['template_indices'] print 'Overlaps for brainscan', bs print measure_internal_overlaps(refs)
def make_ref_dic(): ''' Creates a dictionary containing reference fibres, names, and template values for the original 20 tracts in the training dataset ''' path='/home/eg01/Data/PBC/pbc2009icdm' #name_list=['Unassigned', 'Arcuate L', 'Cingulum L','Corticospinal R', 'Forceps Major','Fornix','Inferior Occipitofrontal Fasciculus L','Superior Longitudinal Fasciculus L','Uncinate R'] name_list=['Not Assigned']+[ids[i]['bundle_name'][0] for i in range(1,9)] #name_list=['Not Assigned']+[ids[i]['bundle_name'][0] for i in range(1,21)] #value_list=[0,41,35,9,5,6,31,41,48] #value_list= [[0]]+[ids[i]['value'] for i in range(1,21)] value_list= [[0]]+[ids[i]['value'] for i in range(1,9)] #corr = pbc.load_pickle(path+'/corr_20.pkl') corr = pbc.load_pickle(path+'/corr_8_sc1.pkl') #brainscan_keys = [(1,1),(1,2),(2,1),(3,1),(3,2)] brainscan_keys = [(1,1),(2,1),(3,1)] refdic={} #for (i, (b,s)) in enumerate([(1,1)]): for (i, (b,s)) in enumerate(brainscan_keys): refdic[(b,s)] = {} refdic[(b,s)]['reference_indices']=[[]]+[list(set(c)) for c in corr[i]] refdic['names'] = name_list refdic['template_values'] = value_list template,tcs,tes,tracks = load_template_tes_and_tracks(path,b,s) #refdic[(b,s)]['reference_tracks'] =[[]]+ [[tracks[r] for r in l] for l in refdic[(b,s)]['reference_indices'][1:]] for (j,l) in enumerate(refdic[(b,s)]['reference_indices']): if j==0: refdic[(b,s)]['reference_tracks'] = [[]] else: refdic[(b,s)]['reference_tracks'].append( [tracks[t] for t in l]) for (j,values) in enumerate(value_list): if j==0: refdic[(b,s)]['template_tracks'] =[[]] refdic[(b,s)]['template_indices'] = [[]] else: all_template_tracks = [] all_template_indices = [] for value in values: #template_tracks, template_indices = tracks_and_indices_for_a_value_in_template(template,value,tes,tracks) template_tracks, template_indices = for_a_value_in_template(template,value,tes,tracks) all_template_tracks += template_tracks all_template_indices += template_indices refdic[(b,s)]['template_tracks'] += [all_template_tracks] refdic[(b,s)]['template_indices'] += [all_template_indices] pbc.save_pickle(path+'/refdic_8_sc1.pkl',refdic)
def relabel_them_all(no): path='/home/eg01/Data/PBC/pbc2009icdm' refdic = pbc.load_pickle('/home/ian/tractarian/refdic.pkl') brains = [(1,1),(1,2),(2,1),(3,1),(3,2)] for (b,s) in [brains[no]]: print b,s tA= refdic[(b,s)]['template_tracks'] iA= refdic[(b,s)]['template_indices'] tR = [] iR = [] cR=[] for bundle in range(1,21): tmp=refdic[(b,s)]['reference_tracks'][bundle] tR+=tmp iR+=refdic[(b,s)]['reference_indices'][bundle] #print len(tmp),np.repeat(bundle,len(tmp)).astype(int) cR+=list(np.repeat(bundle,len(tmp)).astype(int)) relabelling = {} for bundle in range(1,21): print 'Relabelling', bundle #print len(tR),len(iR),len(cR) relabelling[bundle] = map_bundle_to_refs(tA[bundle], iA[bundle], tR, iR, cR) IDS=ids for bundle1 in range(1,21): print 'Remapping', for bundle2 in range(1,21): try: IDS[bundle2]['indices']+=relabelling[bundle1][bundle2] except : IDS[bundle2]['indices']=relabelling[bundle1][bundle2] print 'Saving',b,s pbc.save_pickle(path+'/Relabelling_'+str(b)+'_'+str(s)+'.pkl',IDS)
def print_results(): #brains=[(1,1),(1,2),(2,1),(3,1),(3,2)] brains=[(1,1),(2,1),(3,1)] for (b,s) in brains: fname=path+'/eg309_brain'+str(b)+'_scan'+str(s)+'_ch1.txt' f=open(fname,'wt') subm=np.zeros((250000,2)).astype(int) ids = pbc.load_pickle(path+'/Relabelling_'+str(b)+'_'+str(s)+'.pkl') for i in ids: indices=ids[i]['indices'] for ind in indices: subm[ind,0]=ind+1 subm[ind,1]=i for i in range(subm.shape[0]): print >> f, '%d\t%d' % (i,subm[i,1]) f.close()
import pbc from dipy.viz import fos path='/home/eg309/Data/' tracks1zshift=pbc.load_pickle(path+'t1zs.pkl') tracks2zshift=pbc.load_pickle(path+'t2zs.pkl') tracks3zshift=pbc.load_pickle(path+'t3zs.pkl') track2track=pbc.load_pickle(path+'t2t.pkl') track2track2=pbc.load_pickle(path+'t2t2.pkl') r=fos.ren() fos.add(r,fos.line(tracks1zshift,fos.red,opacity=0.02)) fos.add(r,fos.line(tracks2zshift,fos.cyan,opacity=0.02)) fos.add(r,fos.line(tracks3zshift,fos.blue,opacity=0.02)) print 'Show track to track correspondence br1 br2' for i in track2track: fos.add(r,fos.line(tracks1zshift[i[1]],fos.yellow,opacity=0.5,linewidth=3)) fos.label(r,str(i[0]),tracks1zshift[i[1]][0],(4,4,4),fos.white) fos.add(r,fos.line(tracks2zshift[i[2]],fos.yellow,opacity=0.5,linewidth=3)) fos.label(r,str(i[0]),tracks2zshift[i[2]][0],(4,4,4),fos.white) print 'Show track to track correspondence br1_FACT and br2_RK2' for i in track2track2: fos.add(r,fos.line(tracks3zshift[i[2]],fos.yellow,opacity=0.5,linewidth=3)) fos.label(r,str(i[0]),tracks3zshift[i[2]][0],(4,4,4),fos.white)