Example #1
0
 def initialize_overlay_plots(self, data_list, ax_lims, **img_kw):
     self.unload_overlay_plots(draw=False)
     # these are the new extents for each plot (sag, cor, axial)
     plot_extents = limits_to_extents(ax_lims)
     self.over_plots = [f.spawn_image(p, extent=e, **img_kw)
                        for  f, p, e in zip(self.figs, data_list,
                                            plot_extents)]
Example #2
0
    def initialize_plots(self, data_list, loc, ax_lims, **img_kw):
        """Initialize the main plots of each orthogonal plane with the
        images given in data_list.

        Parameters
        ----------
        data_list : list-like
            a list of images for the sagittal, coronal, and axial planes
        extents : list-like
            a list of extent pairs, ie: [(xmin,xmax), (ymin,ymax), (zmin,zmax)]
        loc : list-like
            the (x,y,z) position at the intersection of the planes
        img_kw : optional
            any AxesImage image properties
        """
        
        self.unload_main_plots(draw=False)
        self.unload_overlay_plots(draw=False)
        # these are the new extents for each plot (sag, cor, axial)
        self._full_fov_lims = ax_lims
        plot_extents = limits_to_extents(ax_lims)
        x,y,z = loc
        self._xyz_position[:] = x,y,z
        self.emit_states(SAG,COR,AXI)
        fig_locs = [ (x,y), (y,z), (x,z) ]
        for n, fig in enumerate(self.figs):
            fig.set_limits(plot_extents[n])
        self.main_plots = [f.spawn_image(p, loc=l, extent=e, **img_kw)
                           for  f, p, l, e in zip(self.figs, data_list,
                                                  fig_locs, plot_extents)]
        self.draw()
Example #3
0
    def _define_grids(self):
        dx, dy, dz = self.grid_spacing
        xbox, ybox, zbox = map( lambda x: np.array(x).reshape(2,2),
                                vu.limits_to_extents(self._nominal_bbox) )
        
        # xbox is [ <ylims> , <zlims> ], so xgrid is [ypts.T, zpts.T]
        xr = np.diff(xbox)[:,0]
        xspacing = np.array([dy, dz])
        self.xshape = (xr / xspacing).astype('i')
        aff = ni_api.AffineTransform.from_start_step('ij', 'xy',
                                                     xbox[:,0], xspacing)
        self.xgrid = ni_api.ArrayCoordMap(aff, self.xshape).values

        # ybox is [ <xlims>, <zlims> ], so ygrid is [xpts.T, zpts.T]
        yr = np.diff(ybox)[:,0]
        yspacing = np.array([dx, dz])
        self.yshape = (yr / yspacing).astype('i')
        aff = ni_api.AffineTransform.from_start_step('ij', 'xy',
                                                     ybox[:,0], yspacing)
        self.ygrid = ni_api.ArrayCoordMap(aff, self.yshape).values

        # zbox is [ <xlims>, <ylims> ], so zgrid is [xpts.T, ypts.T]
        zr = np.diff(zbox)[:,0]
        zspacing = np.array([dx, dy])
        self.zshape = (zr / zspacing).astype('i')
        aff = ni_api.AffineTransform.from_start_step('ij', 'xy',
                                                     zbox[:,0], zspacing)
        self.zgrid = ni_api.ArrayCoordMap(aff, self.zshape).values

        bb_min = [b[0] for b in self._nominal_bbox]
        lx = self.yshape[0]
        ly = self.xshape[0]
        lz = self.yshape[1]
        bb_max = [bb_min[0] + dx*lx, bb_min[1] + dy*ly, bb_min[2] + dz*lz]
        self.bbox = zip(bb_min, bb_max)
Example #4
0
    def set_limits(self, limits):
        """Set the axes limits on each SliceFigure.

        Paramters
        ---------
        limits : iterable
            the min/max limits (in mm units) for each SliceFigure in
            sagittal, coronal, axial order
        """
        extents = limits_to_extents(limits)
        for fig, lim in zip(self.figs, extents):
            fig.set_limits(lim)
Example #5
0
def quick_ortho_plot(x,y,z, bbox=[], loc=None, title='', norm=None):
    import matplotlib.pyplot as pp
    import xipy.volume_utils as vu
    from xipy.vis.single_slice_plot import SliceFigure
    # find or make the x, y, z plane extents
    if bbox:
        extents = vu.limits_to_extents(bbox)
    else:
        extents = [ reduce(lambda x,y: x+y, zip([0,0],p.shape[:2][::-1]))
                    for p in (x, y, z) ]
        
    if norm is None and len(x.shape) < 3:
        mx = max([ x.max(), y.max(), z.max() ])
        mn = min([ x.min(), y.min(), z.min() ])
        norm = pp.normalize(mn, mx)
    fig = pp.figure()

    loc = list(loc)
    zloc = loc[0],loc[1] if loc else None
    ax_z = fig.add_subplot(131)
    sf_z = SliceFigure(fig, extents[2])
    img_z = sf_z.spawn_image(z, extent=extents[2], loc=zloc,
                             interpolation='nearest', norm=norm)
    ax_z.set_title('plot z')

    yloc = loc[0],loc[2] if loc else None
    ax_y = fig.add_subplot(132)
    sf_y = SliceFigure(fig, extents[1])
    img_y = sf_y.spawn_image(y, extent=extents[1], loc=yloc,
                             interpolation='nearest', norm=norm)
    ax_y.set_title('plot y')

    xloc = loc[1],loc[2] if loc else None
    ax_x = fig.add_subplot(133)
    sf_x = SliceFigure(fig, extents[0])
    img_x = sf_x.spawn_image(x, extent=extents[0], loc=xloc,
                             interpolation='nearest', norm=norm)
    ax_x.set_title('plot x')
    if title:
        fig.text(.5, .05, title, ha='center')
    pp.colorbar(img_x.img)
    pp.show()
    return fig
Example #6
0
    def __init__(self, parent=None, **kwargs):
        figsize = kwargs.pop('figsize', (3,3))
        dpi = kwargs.pop('dpi', 100)
        if 'limits' in kwargs:
            self._full_fov_lims = kwargs.pop('limits')
        extents = limits_to_extents(self._full_fov_lims)
        QtGui.QWidget.__init__(self, parent)
        # set up the Sag, Cor, Axi SliceFigures
        self.horizontalLayout = QtGui.QHBoxLayout(self)
        self.horizontalLayout.setObjectName("FigureLayout")


        # set axial figure
        fig = Figure(figsize=figsize, dpi=dpi)
        fig.canvas = Canvas(fig)
        Canvas.setSizePolicy(fig.canvas, QtGui.QSizePolicy.Expanding,
                             QtGui.QSizePolicy.Expanding)
        Canvas.updateGeometry(fig.canvas)
        fig.canvas.setParent(self)
        self.axi_fig = ssp.SliceFigure(fig, extents[AXI], blit=BLITTING)
        self.axi_fig.ax.set_xlabel('left to right', fontsize=8)
        self.axi_fig.ax.set_ylabel('posterior to anterior', fontsize=8)
        self.horizontalLayout.addWidget(fig.canvas)
        # set coronal figure
        fig = Figure(figsize=figsize, dpi=dpi)
        fig.canvas = Canvas(fig)
        Canvas.setSizePolicy(fig.canvas, QtGui.QSizePolicy.Expanding,
                             QtGui.QSizePolicy.Expanding)
        Canvas.updateGeometry(fig.canvas)
        fig.canvas.setParent(self)
        self.cor_fig = ssp.SliceFigure(fig, extents[COR], blit=BLITTING)
        self.cor_fig.ax.set_xlabel('left to right', fontsize=8)
        self.cor_fig.ax.set_ylabel('inferior to superior', fontsize=8)
        self.horizontalLayout.addWidget(fig.canvas)        
        # set sagittal figure
        fig = Figure(figsize=figsize, dpi=dpi)
        fig.canvas = Canvas(fig)
        Canvas.setSizePolicy(fig.canvas, QtGui.QSizePolicy.Expanding,
                             QtGui.QSizePolicy.Expanding)
        Canvas.updateGeometry(fig.canvas)
        fig.canvas.setParent(self)
        self.sag_fig = ssp.SliceFigure(fig, extents[SAG], blit=BLITTING)
        self.sag_fig.ax.set_xlabel('posterior to anterior', fontsize=8)
        self.sag_fig.ax.set_ylabel('inferior to superior', fontsize=8)        
        self.horizontalLayout.addWidget(fig.canvas)
        
        # put down figures in x, y, z order
        self.figs = [self.sag_fig, self.cor_fig, self.axi_fig]
        self.canvas_lookup = dict( ((f.canvas, f) for f in self.figs) )
        self._mouse_dragging = False
        # this should be something like a signal too, which can emit status
        self._xyz_position = [0,0,0]
        self._connect_events()

        self.setParent(parent)
        QtGui.QWidget.setSizePolicy(self, QtGui.QSizePolicy.Expanding,
                                    QtGui.QSizePolicy.Expanding)
        QtGui.QWidget.updateGeometry(self)
        self._main_plotted = False
        self.main_plots = []
        self._over_plotted = False
        self.over_plots = []