Ejemplo n.º 1
0
def display(data=None, orient='LPS', overlay=None, colormap=cm.gray, pixdim=None):
    "mri=img.decimate(nim, 5)"
    "ex. slice.plot(mri)"

    import sys
    print sys.argv
    if data == None:
        try:
            fn=sys.argv[1]
            from mri import img
            data = img.read(fn)
        except AttributeError:
            print 'not passing data arg'
            print('lets plot random data')
            from numpy import random
            data = random.randn(10,10,10)

    try:
        data.qform
        print 'think its a nifti volume'
        nim = data
        mrdata = nim.data
        print shape(mrdata)
        pixdim = nim.voxdim[::-1]

    except AttributeError:
        if pixdim != None:
            print 'using user supplied pixeldimensions', pixdim
        else:
            print 'probably not a nifti volume. using voxel units instead of actual distance units'
            pixdim = [1.0,1.0,1.0]; #unitless
        mrdata = data

    fig = figure()
    subplots_adjust(left=.15, bottom=.15,right=1, top=.95,wspace=.25, hspace=.35)

    ax1 = fig.add_subplot(221);#axis('off')
    #colorbar(fig,ax=ax1)
    xlabel('Anterior (A->P 1st Dim)');ylabel('Right (R->L 2nd Dim)')
    ax2 = fig.add_subplot(222);#axis('off')
    xlabel('Inferior (I->S Dim)');ylabel('Anterior (A->P 1st Dim)')
    ax3 = fig.add_subplot(223);#axis('off')
    xlabel('Infererior (I->S 3rd dim)');ylabel('Right (R->L 2nd Dim)')
    coord = fig.add_subplot(224);axis('off')
    tracker = IndexTracker(mrdata, ax1, ax2, ax3, colormap, pixdim, overlay, coord)
    fig.canvas.mpl_connect('scroll_event', tracker.onscroll)
    cid = connect('button_press_event', tracker.click)

    show()


    return tracker
Ejemplo n.º 2
0
    def __init__(self, data=None, orient="LPS", overlay=None, colormap=cm.gray, pixdim=None):

        ##
        import sys

        print sys.argv
        if data == None:
            try:
                fn = sys.argv[1]
                from mri import img

                data = img.read(fn)
            except AttributeError:
                print "not passing data arg"
                pass

        try:
            data.qform
            print "think its a nifti volume"
            nim = data
            mrdata = nim.data
            print shape(mrdata)
            pixdim = nim.voxdim[::-1]

        except AttributeError:
            if pixdim != None:
                print "using user supplied pixeldimensions", pixdim
            else:
                print "probably not a nifti volume. using voxel units instead of actual distance units"
                pixdim = [1.0, 1.0, 1.0]
                # unitless
            mrdata = data
        ##

        self.win = gtk.Window()
        # win.connect("destroy", lambda x: gtk.main_quit())
        self.win.connect("delete-event", self.hideinsteadofdelete)
        self.win.set_default_size(600, 600)
        self.win.set_title("Embedding in GTK")

        vbox = gtk.VBox()
        self.win.add(vbox)

        fig = figure()  # figsize=(5,4), dpi=100)
        # subplots_adjust(left=.15, bottom=.15,right=1, top=.95,wspace=.25, hspace=.35)
        # a = fig.add_subplot(111)
        # t = arange(0.0,3.0,0.01)
        # s = sin(2*pi*t)
        # a.plot(t,s)
        # a.plot(data)

        ax1 = fig.add_subplot(221)
        # axis('off')
        # colorbar(fig,ax=ax1)
        xlabel("Anterior (A->P 1st Dim)")
        ylabel("Right (R->L 2nd Dim)")
        ax2 = fig.add_subplot(222)
        # axis('off')
        xlabel("Inferior (I->S Dim)")
        ylabel("Anterior (A->P 1st Dim)")
        ax3 = fig.add_subplot(223)
        # axis('off')
        xlabel("Infererior (I->S 3rd dim)")
        ylabel("Right (R->L 2nd Dim)")
        coord = fig.add_subplot(224)
        axis("off")
        tracker = IndexTracker(mrdata, ax1, ax2, ax3, colormap, pixdim, overlay, coord)
        # fig.canvas.mpl_connect('scroll_event', tracker.onscroll)
        cid = connect("button_press_event", tracker.click)

        print ("something")

        sw = gtk.ScrolledWindow()
        vbox.pack_start(sw)
        # self.win.add (sw)
        ## A scrolled window border goes outside the scrollbars and viewport
        sw.set_border_width(10)
        # policy: ALWAYS, AUTOMATIC, NEVER
        sw.set_policy(hscrollbar_policy=gtk.POLICY_AUTOMATIC, vscrollbar_policy=gtk.POLICY_ALWAYS)

        canvas = FigureCanvas(fig)  # a gtk.DrawingArea
        ##vbox.pack_start(canvas)
        canvas.set_size_request(300, 200)
        sw.add_with_viewport(canvas)
        canvas.draw()

        # manager = get_current_fig_manager()
        ## you can also access the window or vbox attributes this way
        # toolbar = manager.toolbar

        ##vbox.pack_start(canvas)
        # toolbar = NavigationToolbar(canvas, self.win)
        ##vbox.pack_start(toolbar, False, False)
        # show()
        # print tracker
        #
        # fig.show()
        self.win.show_all()