def save_fa_overlay(faDir, ccDir, figDir, slist, orientationList): brainFiles = [fn.split('_')[0] for fn in os.listdir(ccDir)] f = plt.figure(); for bfn in brainFiles: vcc = ConnectedComponent(fn=ccDir+bfn+'_concomp.npy') fax = fa.FAXML(faDir+bfn+'_fa.xml') fas = fa.FAData(faDir+bfn+'_fa.raw',fax.getShape()) cc3d = vcc.get_3d_cc(fax.getShape()) for view,s,xyz in zip(np.arange(len(slist)),slist,orientationList): show_overlay(fas.data,cc3d,np.Inf,s,xyz,.5) plt.savefig(figDir+bfn+'_ccfaOverlay_view'+repr(view)+'.pdf',) plt.clf() plt.close(f)
def main(): parser = argparse.ArgumentParser(description='Draw the FA map of a brain.') parser.add_argument('faxmlfile', action="store") parser.add_argument('farawfile', action="store") parser.add_argument('--dimensions', action="store", default="xy", help="xy, xz, or yz") parser.add_argument('--zero_threshold', action="store", type=float, default=0.2) parser.add_argument('slice', action="store") result = parser.parse_args() # Read the XML file and then the data try: fax = fa.FAXML(result.faxmlfile) fas = fa.FAData(result.farawfile, fax.getShape()) except: print "Failed to parse FA files at: ", result.faxmlfile, result.faxmlfile assert 0 # cut out the specified slice if result.dimensions == "xy": graphdata = fas.data[:, :, result.slice] elif result.dimensions == "yz": graphdata = fas.data[result.slice, :, :] elif result.dimensions == "xz": graphdata = fas.data[:, result.slice, :] else: print "Choose xy, xz, or yz as dimension or leave blank for xy default" vec_func1 = np.vectorize(lambda x: 0.0 if math.isnan(x) else x) vec_func2 = np.vectorize( lambda x: int(math.fabs(x) / result.zero_threshold)) fgraphdata = vec_func1(graphdata) igraphdata = vec_func2(fgraphdata) matplotlib.pyplot.pcolor(igraphdata) matplotlib.pyplot.show()
def save_overlay(faDir, mprDir, ccDir, figDir, slist, orientationList): brainFiles = [fn.split('_')[0] for fn in os.listdir(ccDir)] f = plt.figure(figsize=(14,9)); for bfn in brainFiles: vcc = ConnectedComponent(fn=ccDir+bfn+'_concomp.npy') fax = fa.FAXML(faDir+bfn+'_fa.xml') fas = fa.FAData(faDir+bfn+'_fa.raw',fax.getShape()) mpx = mprage.MPRAGEXML(mprDir+'mprage_'+bfn+'_ss_crop.xml') mpd = mprage.MPRAGEData(mprDir+'mprage_'+bfn+'_ss_crop.raw',mpx.getShape()) cc3d = vcc.get_3d_cc(fax.getShape()) for view,s,xyz in zip(np.arange(len(slist)),slist,orientationList): plt.clf() plt.subplot(221); plt.title('FA Overlay') show_overlay(fas.data,cc3d,np.Inf,s,xyz,.5) plt.subplot(222); plt.title('FA Original; '+bfn+', '+xyz+'-slice '+repr(s)) plt.imshow(get_slice(fas.data,s,xyz),cmap=plt.cm.gray) plt.colorbar() plt.subplot(223); plt.title('MPRAGE Overlay') show_overlay(mpd.data,cc3d,np.Inf,s,xyz,.5) plt.subplot(224); plt.title('MPRAGE Original') plt.imshow(get_slice(mpd.data,s,xyz),cmap=plt.cm.gray) plt.colorbar() #plt.tight_layout() plt.savefig(figDir+bfn+'_ccfaOverlay_view'+repr(view)+'.pdf') plt.close(f)
def show_figure(bfn): faDir = "/mnt/braingraph1data/projects/will/mar12data/fa/" ccDir = '/data/biggraphs/connectedcomp/' global xyz global sl global sslice fafn = faDir + bfn + "_fa" faXML = fa.FAXML(fafn + '.xml') faData = fa.FAData(fafn + '.raw', faXML.getShape()) vcc = lcc.ConnectedComponent(fn=ccDir + bfn + '_concomp.npy') cc3d = vcc.get_3d_cc(faXML.getShape()) sl = 100 xyz = 'xy' fig = figure() ax = subplot(111) subplots_adjust(left=0.25, bottom=0.25) def draw_brain(sl, xyz): ax = subplot(111) ax.clear() lcc.show_overlay(faData.data, cc3d, ncc=15, s=sl, xyz=xyz) draw() draw_brain(sl, xyz) axcolor = 'lightgoldenrodyellow' axslice = axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor) sslice = Slider(axslice, 'Slice', 0, cc3d.shape[0] - 1, valinit=sl) def update_slice(val): global xyz global sl sl = val draw_brain(sl, xyz) sslice.on_changed(update_slice) rax = axes([0.025, 0.5, 0.15, 0.15], axisbg=axcolor) radio = RadioButtons(rax, ('xy', 'xz', 'yz'), active=0) def xyzproj(newxyz): print newxyz global xyz global sl global sslice xyz = newxyz dimDict = {'xy': 2, 'xz': 1, 'yz': 0} sl = int(cc3d.shape[dimDict[xyz]] / 2) sslice.valmax = cc3d.shape[dimDict[xyz]] sslice.set_val(sl) draw() draw_brain(sl, xyz) radio.on_clicked(xyzproj) show()