Beispiel #1
0
    def render_image(self):
        plot = Plot(self.img_plotdata, default_origin="top left")
        img = plot.img_plot("imagedata", colormap=gray)[0]
        plot.title = "%s of %s: " % (self.img_idx + 1,
                                     self.numfiles) + self.titles[self.img_idx]
        plot.aspect_ratio = float(self.sig.data.shape[1]) / float(
            self.sig.data.shape[0])

        #if not self.ShowCC:
        csr = CursorTool(img,
                         drag_button='left',
                         color='white',
                         line_width=2.0)
        self.csr = csr
        csr.current_position = self.left, self.top
        img.overlays.append(csr)

        # attach the rectangle tool
        plot.tools.append(PanTool(plot, drag_button="right"))
        zoom = ZoomTool(plot,
                        tool_mode="box",
                        always_on=False,
                        aspect_ratio=plot.aspect_ratio)
        plot.overlays.append(zoom)
        self.img_plot = plot
        return plot
Beispiel #2
0
 def _cursor_default(self):
     cursor = CursorTool(self.ScanImage,
                         drag_button='left',
                         color='blue',
                         line_width=1.0 )
     cursor._set_current_position('x', (self.x, self.y))
     return cursor
    def __init__(self, plot, pos_signal, drag_signal=None):
        super(CrossHair, self).__init__()

        self._pos_signal = pos_signal
        self._drag_signal = drag_signal
        
        csr = CursorTool(plot,
                         drag_button='left',
                         color='white',
                         line_width=2.0,
                         marker_size=2.0)
        self.cursor = csr
        csr.current_position = 0.0, 0.0
        plot.overlays.append(csr)

        self.is_being_dragged = False
Beispiel #4
0
    def render_image(self):
        plot = Plot(self.img_plotdata,default_origin="top left")
        img=plot.img_plot("imagedata", colormap=gray)[0]
        plot.title="%s of %s: "%(self.img_idx+1,self.numfiles)+self.titles[self.img_idx]
        plot.aspect_ratio=float(self.sig.data.shape[1])/float(self.sig.data.shape[0])

        #if not self.ShowCC:
        csr = CursorTool(img, drag_button='left', color='white',
                         line_width=2.0)
        self.csr=csr
        csr.current_position=self.left, self.top
        img.overlays.append(csr)

        # attach the rectangle tool
        plot.tools.append(PanTool(plot,drag_button="right"))
        zoom = ZoomTool(plot, tool_mode="box", always_on=False, aspect_ratio=plot.aspect_ratio)
        plot.overlays.append(zoom)
        self.img_plot=plot
        return plot
Beispiel #5
0
    def _create_plot_component(self):

        container = OverlayPlotContainer(padding=50,
                                         fill_padding=True,
                                         bgcolor="white",
                                         use_backbuffer=True)
        types = {"line": LinePlot, "scatter": ScatterPlot}

        # Create the initial X-series of data
        if len(self) > 0:  # Only create a plot if we ahve datat
            if self.p_type == "scatter and line":
                lineplot = self._create_plot(p_type=LinePlot)
                #lineplot.selected_color = "none"
                scatter = self._create_plot(p_type=ScatterPlot)
                scatter.bgcolor = "white"
                scatter.index_mapper = lineplot.index_mapper
                scatter.value_mapper = lineplot.value_mapper
                add_default_grids(scatter)
                add_default_axes(scatter)
                container.add(lineplot)
                container.add(scatter)
            else:
                plot = self._create_plot(p_type=types[self.p_type])
                add_default_grids(plot)
                add_default_axes(plot)
                container.add(plot)
                scatter = plot
            scatter.tools.append(PanTool(scatter, drag_button="left"))

            # The ZoomTool tool is stateful and allows drawing a zoom
            # box to select a zoom region.
            zoom = ZoomTool(scatter,
                            tool_mode="box",
                            always_on=True,
                            drag_button="right")
            scatter.overlays.append(zoom)
            csr = CursorTool(scatter, color="black", drag_button="left")
            scatter.overlays.append(csr)

        self.plot = container
        return container
Beispiel #6
0
    def __init__(self):
        #The delegates views don't work unless we caller the superclass __init__
        super(CursorTest, self).__init__()

        container = HPlotContainer(padding=0, spacing=20)
        self.plot = container
        #a subcontainer for the first plot.
        #I'm not sure why this is required. Without it, the layout doesn't work right.
        subcontainer = OverlayPlotContainer(padding=40)
        container.add(subcontainer)

        #make some data
        index = numpy.linspace(-10,10,512)
        value = numpy.sin(index)

        #create a LinePlot instance and add it to the subcontainer
        line = create_line_plot([index, value], add_grid=True,
                                add_axis=True, index_sort='ascending',
                                orientation = 'h')
        subcontainer.add(line)

        #here's our first cursor.
        csr = CursorTool(line,
                        drag_button="left",
                        color='blue')
        self.cursor1 = csr
        #and set it's initial position (in data-space units)
        csr.current_position = 0.0, 0.0

        #this is a rendered component so it goes in the overlays list
        line.overlays.append(csr)

        #some other standard tools
        line.tools.append(PanTool(line, drag_button="right"))
        line.overlays.append(ZoomTool(line))

        #make some 2D data for a colourmap plot
        xy_range = (-5, 5)
        x = numpy.linspace(xy_range[0], xy_range[1] ,100)
        y = numpy.linspace(xy_range[0], xy_range[1] ,100)
        X,Y = numpy.meshgrid(x, y)
        Z = numpy.sin(X)*numpy.arctan2(Y,X)

        #easiest way to get a CMapImagePlot is to use the Plot class
        ds = ArrayPlotData()
        ds.set_data('img', Z)

        img = Plot(ds, padding=40)
        cmapImgPlot = img.img_plot("img",
                     xbounds = xy_range,
                     ybounds = xy_range,
                     colormap = jet)[0]

        container.add(img)

        #now make another cursor
        csr2 = CursorTool(cmapImgPlot,
                           drag_button='left',
                           color='white',
                           line_width=2.0
                           )
        self.cursor2 = csr2

        csr2.current_position = 1.0, 1.5

        cmapImgPlot.overlays.append(csr2)

        #add some standard tools. Note, I'm assigning the PanTool to the
        #right mouse-button to avoid conflicting with the cursors
        cmapImgPlot.tools.append(PanTool(cmapImgPlot, drag_button="right"))
        cmapImgPlot.overlays.append(ZoomTool(cmapImgPlot))
Beispiel #7
0
    def _create_plot_window(self):
        # Create the model
        min_value = 350
        max_value = self.max_data
        image_value_range = DataRange1D(low=min_value, high=max_value)
        self.cmap = jet(range=image_value_range)
        self._update_model()
        datacube = self.colorcube

        # Create the plot
        self.plotdata = ArrayPlotData()
        self.plotdataVoxel = ArrayPlotData()
        self.plotdataSlices = ArrayPlotData()
        self.plotdataVoxelFFT = ArrayPlotData()
        self.plotdataPC = ArrayPlotData()
        self._update_images()

        # Top Left plot
        centerplot = Plot(self.plotdata,
                          resizable='hv',
                          padding=20,
                          title="Slice_X")
        imgplot = centerplot.img_plot("yz",
                                      xbounds=None,
                                      ybounds=None,
                                      colormap=self.cmap)[0]

        centerplot.x_axis.title = "Y"
        centerplot.y_axis.title = "Z"
        self._add_plot_tools(imgplot, "yz")
        self.cursorYZ = CursorTool(imgplot, drag_button='left', color='white')
        self.cursorYZ.current_position = self.slice_y, self.slice_z
        imgplot.overlays.append(self.cursorYZ)
        self.center = imgplot

        # Top Right Plot
        rightplot = Plot(self.plotdata,
                         resizable='hv',
                         padding=20,
                         title="Slice_Y")
        rightplot.x_axis.title = "X"
        rightplot.y_axis.title = "Z"
        imgplot = rightplot.img_plot("xz",
                                     xbounds=None,
                                     ybounds=None,
                                     colormap=self.cmap)[0]

        self._add_plot_tools(imgplot, "xz")
        self.cursorXZ = CursorTool(imgplot, drag_button='left', color='white')
        self.cursorXZ.current_position = self.slice_x, self.slice_z
        imgplot.overlays.append(self.cursorXZ)
        self.right = imgplot

        # Bottom  LeftPlot
        bottomplot = Plot(self.plotdata,
                          resizable='hv',
                          padding=20,
                          title="Slice_Z")
        bottomplot.x_axis.title = "Y"
        bottomplot.y_axis.title = "X"
        imgplot = bottomplot.img_plot("xy",
                                      xbounds=None,
                                      ybounds=None,
                                      colormap=self.cmap)[0]
        """bottomplot.contour_plot("xy", 
                          type="poly",
                          xbounds=None,
                          ybounds=None)[0]"""

        self._add_plot_tools(imgplot, "xy")
        self.cursorXY = CursorTool(imgplot, drag_button='left', color='white')
        self.cursorXY.current_position = self.slice_y, self.slice_x
        imgplot.overlays.append(self.cursorXY)
        self.bottom = imgplot
        """ # Create a colorbar
        cbar_index_mapper = LinearMapper(range=image_value_range)
        self.colorbar = ColorBar(index_mapper=cbar_index_mapper,
                                 plot=centerplot,
                                 padding_top=centerplot.padding_top,
                                 padding_bottom=centerplot.padding_bottom,
                                 padding_right=40,
                                 resizable='v',
                                 width=30, height = 100)"""

        # Create data series to plot
        timeplot = Plot(self.plotdataVoxel, resizable='hv', padding=20)
        timeplot.x_axis.title = "Frames"
        timeplot.plot("TimeVoxel",
                      color='lightblue',
                      line_width=1.0,
                      bgcolor="white",
                      name="Time")[0]
        # for i in range(len(self.tasks)):
        #         timeplot.plot(self.timingNames[i+2],color=tuple(COLOR_PALETTE[i]),
        #         line_width=1.0, bgcolor = "white", border_visible=True, name = self.timingNames[i+2])[0]

        timeplot.legend.visible = True
        timeplot.plot("time",
                      type="scatter",
                      color=tuple(COLOR_PALETTE[2]),
                      line_width=1,
                      bgcolor="white",
                      border_visible=True,
                      name="time")[0]
        self.timePlot = timeplot
        # Create data series to plot
        timeplotBig = Plot(self.plotdataVoxel, resizable='hv', padding=20)
        timeplotBig.x_axis.title = "Frames"
        timeplotBig.plot("TimeVoxel",
                         color='lightblue',
                         line_width=1.5,
                         bgcolor="white",
                         name="Time")[0]
        timeplotBig.legend.visible = True
        timeplotBig.plot("time",
                         type="scatter",
                         color=tuple(COLOR_PALETTE[2]),
                         line_width=1,
                         bgcolor="white",
                         border_visible=True,
                         name="time")[0]
        self.timePlotBig = timeplotBig

        # Create data series to plot
        freqplotBig = Plot(self.plotdataVoxelFFT, resizable='hv', padding=20)
        freqplotBig.x_axis.title = "Frequency (Hz)"
        freqplotBig.plot("FreqVoxel",
                         color='lightblue',
                         line_width=1.5,
                         bgcolor="white",
                         name="Abs(Y)")[0]
        freqplotBig.legend.visible = True
        freqplotBig.plot("peaks",
                         type="scatter",
                         color=tuple(COLOR_PALETTE[2]),
                         line_width=1,
                         bgcolor="white",
                         border_visible=True,
                         name="peaks")[0]
        self.freqPlotBig = freqplotBig

        # Create data series to plot
        PCplotBig = Plot(self.plotdataPC, resizable='hv', padding=20)
        PCplotBig.x_axis.title = "Frames"
        PCplotBig.plot("Principal Component",
                       color='lightblue',
                       line_width=1.5,
                       bgcolor="white",
                       name="Principal Component")[0]
        PCplotBig.legend.visible = True
        PCplotBig.plot("time",
                       type="scatter",
                       color=tuple(COLOR_PALETTE[2]),
                       line_width=1,
                       bgcolor="white",
                       border_visible=True,
                       name="time")[0]
        self.PCplotBig = PCplotBig

        #self.time = time
        # Create a GridContainer to hold all of our plots
        container = GridContainer(padding=10,
                                  fill_padding=True,
                                  bgcolor="white",
                                  use_backbuffer=True,
                                  shape=(2, 2),
                                  spacing=(10, 10))
        containerTime = GridContainer(padding=10,
                                      fill_padding=True,
                                      bgcolor="white",
                                      use_backbuffer=True,
                                      shape=(1, 1),
                                      spacing=(5, 5))

        containerFreq = GridContainer(padding=10,
                                      fill_padding=True,
                                      bgcolor="white",
                                      use_backbuffer=True,
                                      shape=(1, 1),
                                      spacing=(5, 5))
        containerPC = GridContainer(padding=10,
                                    fill_padding=True,
                                    bgcolor="white",
                                    use_backbuffer=True,
                                    shape=(1, 1),
                                    spacing=(5, 5))

        container.add(centerplot)
        container.add(rightplot)
        container.add(bottomplot)
        container.add(timeplot)
        containerTime.add(timeplotBig)
        containerFreq.add(freqplotBig)
        containerPC.add(PCplotBig)
        """container = GridContainer(padding=10, fill_padding=True,
                              bgcolor="white", use_backbuffer=True,
                              shape=(3,3), spacing=(10,10))
       
        for i in range(14,23):
             slicePlot = Plot(self.plotdataSlices, resizable= 'hv', padding=20,title = "slice " + str(i),bgcolor = "white")
             slicePlot.img_plot("slice " + str(i),xbounds= None, ybounds= None, colormap=self.cmap,bgcolor = "white")[0]
             container.add(slicePlot)"""

        self.container = container
        self.nb.DeleteAllPages()
        self.window = Window(self.nb, -1, component=container)
        self.windowTime = Window(self.nb, -1, component=containerTime)
        self.windowFreq = Window(self.nb, -1, component=containerFreq)
        self.windowPC = Window(self.nb, -1, component=containerPC)
        self.sizer.Detach(self.topsizer)
        self.sizer.Detach(self.pnl2)
        self.topsizer.Clear()
        self.topsizer.Add(self.pnl3, 0, wx.ALL, 10)
        self.nb.AddPage(self.window.control, "fMRI Slices")
        self.nb.AddPage(self.windowTime.control, "Time Voxel")
        self.nb.AddPage(self.windowFreq.control, "Frequency Voxel")
        self.nb.AddPage(self.windowPC.control, "Principal Component")
        self.topsizer.Add(self.nb, 1, wx.EXPAND)
        self.sizer.Add(self.topsizer, 1, wx.EXPAND)
        self.sizer.Add(self.pnl2,
                       flag=wx.EXPAND | wx.BOTTOM | wx.TOP,
                       border=10)

        self.SetSizer(self.sizer)
        self.Centre()
        self.Show(True)