Пример #1
0
    def test_redraw_on_color_mapper_update(self):
        # regression check for https://github.com/enthought/chaco/issues/220
        npoints = 200

        xs = numpy.linspace(-2 * numpy.pi, +2 * numpy.pi, npoints)
        ys = numpy.linspace(-1.5 * numpy.pi, +1.5 * numpy.pi, npoints)
        x, y = numpy.meshgrid(xs, ys)
        z = y * x

        index = GridDataSource(xdata=xs, ydata=ys)
        index_mapper = GridMapper(range=DataRange2D(index))

        color_source = ImageData(data=z, value_depth=1)
        color_mapper = Spectral(DataRange1D(color_source))

        cmap_plot = CMapImagePlot(
            index=index,
            index_mapper=index_mapper,
            value=color_source,
            value_mapper=color_mapper,
        )
        cmap_plot._window = window = mock.Mock(spec=AbstractWindow)

        #when
        cmap_plot.color_mapper.updated = True

        # Then
        window.redraw.assert_called_once_with()
Пример #2
0
    def setUp(self):

        # Set up plot component containing
        xs = np.arange(0, 5)
        ys = np.arange(0, 5)

        # Add some fake 2D data for the box's component
        index = GridDataSource(xdata=xs,
                               ydata=ys,
                               sort_order=('ascending', 'ascending'))
        index_mapper = GridMapper(range=DataRange2D(index))

        color_source = ImageData(data=np.ones(shape=(5, 5)), depth=1)

        self.plot = CMapImagePlot(
            index=index,
            index_mapper=index_mapper,
            value=color_source,
        )

        self.databox = DataBox(
            component=self.plot,
            data_position=[0, 0],
        )

        self.plot.overlays.append(self.databox)
Пример #3
0
    def create_plot(self):

        # Create the mapper, etc
        self._image_index = GridDataSource(array([]),
                                           array([]),
                                           sort_order=("ascending",
                                                       "ascending"))
        image_index_range = DataRange2D(self._image_index)
        # self._image_index.on_trait_change(self._metadata_changed,
        #                                   "metadata_changed")

        self._image_value = ImageData(data=array([]), value_depth=1)
        image_value_range = DataRange1D(self._image_value)

        # Create the colormapped scalar plot
        self.plot = CMapImagePlot(
            index=self._image_index,
            index_mapper=GridMapper(range=image_index_range),
            value=self._image_value,
            value_mapper=self._cmap(image_value_range))

        # Add a left axis to the plot
        left = PlotAxis(orientation='left',
                        title="y",
                        mapper=self.plot.index_mapper._ymapper,
                        component=self.plot)
        self.plot.overlays.append(left)

        # Add a bottom axis to the plot
        bottom = PlotAxis(orientation='bottom',
                          title="x",
                          mapper=self.plot.index_mapper._xmapper,
                          component=self.plot)
        self.plot.overlays.append(bottom)

        # Add some tools to the plot
        self.plot.tools.append(PanTool(self.plot, constrain_key="shift"))
        self.plot.overlays.append(
            ZoomTool(component=self.plot, tool_mode="box", always_on=False))

        # Create a colorbar
        cbar_index_mapper = LinearMapper(range=image_value_range)
        self.colorbar = ColorBar(index_mapper=cbar_index_mapper,
                                 plot=self.plot,
                                 padding_top=self.plot.padding_top,
                                 padding_bottom=self.plot.padding_bottom,
                                 padding_right=40,
                                 resizable='v',
                                 width=10)

        # Create a container and add components
        self.container = HPlotContainer(padding=40,
                                        fill_padding=True,
                                        bgcolor="white",
                                        use_backbuffer=False)
        self.container.add(self.colorbar)
        self.container.add(self.plot)
Пример #4
0
class GridMapperTestCase(unittest.TestCase):
    def setUp(self):
        self.x_ary = array([5.0, 6.0, 7.0, 8.0, 9.0, 10.0])
        self.y_ary = array([1.0, 1.0, 2.0, 2.0, 3.0, 3.0])
        ds = GridDataSource(xdata=self.x_ary, ydata=self.y_ary)
        r = DataRange2D(ds)
        self.mapper = GridMapper(range=r)

    def test_basic(self):
        self.mapper.x_low_pos = 50
        self.mapper.x_high_pos = 100
        self.mapper.y_low_pos = 0
        self.mapper.y_high_pos = 10
        result = self.mapper.map_screen(transpose((self.x_ary, self.y_ary)))
        assert_equal(result, [(50, 0), (60, 0), (70, 5), (80, 5), (90, 10),
                              (100, 10)])

    def test_map_screen_scalar(self):
        self.mapper.x_low_pos = 50
        self.mapper.x_high_pos = 100
        self.mapper.y_low_pos = 0
        self.mapper.y_high_pos = 10
        result = self.mapper.map_screen(transpose((6.0, 1.0)))
        assert_equal(result, [[60, 0]])

    def test_map_data(self):
        self.mapper.x_low_pos = 50
        self.mapper.x_high_pos = 100
        self.mapper.y_low_pos = 0
        self.mapper.y_high_pos = 10
        screen_ary = array([(50, 0), (60, 0), (70, 5), (80, 5), (90, 10),
                            (100, 10)])
        result = self.mapper.map_data(screen_ary)
        assert_equal(result, transpose((self.x_ary, self.y_ary)))

    def test_map_data_scalar(self):
        self.mapper.x_low_pos = 50
        self.mapper.x_high_pos = 100
        self.mapper.y_low_pos = 0
        self.mapper.y_high_pos = 10
        screen_ary = (60, 0)
        result = self.mapper.map_data(screen_ary)
        assert_equal(result, [[6.0, 1.0]])
Пример #5
0
class GridMapperTestCase(unittest.TestCase):

    def setUp(self):
        self.x_ary = array([5.0, 6.0, 7.0, 8.0, 9.0, 10.0])
        self.y_ary = array([1.0, 1.0, 2.0, 2.0, 3.0, 3.0])
        ds = GridDataSource(xdata=self.x_ary, ydata=self.y_ary)
        r = DataRange2D(ds)
        self.mapper = GridMapper(range=r)

    def test_basic(self):
        self.mapper.x_low_pos=50
        self.mapper.x_high_pos=100
        self.mapper.y_low_pos=0
        self.mapper.y_high_pos=10
        result = self.mapper.map_screen(transpose((self.x_ary, self.y_ary)))
        assert_equal(result, [(50,0), (60,0), (70,5),
                              (80,5), (90,10), (100,10)])

    def test_map_screen_scalar(self):
        self.mapper.x_low_pos=50
        self.mapper.x_high_pos=100
        self.mapper.y_low_pos=0
        self.mapper.y_high_pos=10
        result = self.mapper.map_screen(transpose((6.0, 1.0)))
        assert_equal(result, [[60, 0]])

    def test_map_data(self):
        self.mapper.x_low_pos=50
        self.mapper.x_high_pos=100
        self.mapper.y_low_pos=0
        self.mapper.y_high_pos=10
        screen_ary = array([(50,0), (60,0), (70,5), (80,5), (90,10), (100,10)])
        result = self.mapper.map_data(screen_ary)
        assert_equal(result, transpose((self.x_ary, self.y_ary)))

    def test_map_data_scalar(self):
        self.mapper.x_low_pos=50
        self.mapper.x_high_pos=100
        self.mapper.y_low_pos=0
        self.mapper.y_high_pos=10
        screen_ary = (60, 0)
        result = self.mapper.map_data(screen_ary)
        assert_equal(result, [[6.0, 1.0]])
Пример #6
0
 def test_basic(self):
     x_ary = array([5.0, 6.0, 7.0, 8.0, 9.0, 10.0])
     y_ary = array([1.0, 1.0, 2.0, 2.0, 3.0, 3.0])
     ds = GridDataSource(xdata=x_ary, ydata=y_ary)
     r = DataRange2D(ds)
     mapper = GridMapper(range=r)
     mapper.x_low_pos = 50
     mapper.x_high_pos = 100
     mapper.y_low_pos = 0
     mapper.y_high_pos = 10
     result = mapper.map_screen(transpose((x_ary, y_ary)))
     assert_equal(result, [(50, 0), (60, 0), (70, 5), (80, 5), (90, 10),
                           (100, 10)])
Пример #7
0
def empty_image():
    """ Returns empty image plot """
    from chaco.api import ImageData, GridDataSource, GridMapper, DataRange2D, ImagePlot
    image_source = ImageData.fromfile(config.IMG_NOCOMPLEX_PATH)

    w, h = image_source.get_width(), image_source.get_height()
    index = GridDataSource(np.arange(w), np.arange(h))
    index_mapper = GridMapper(
        range=DataRange2D(low=(0, 0), high=(w - 1, h - 1)))

    image_plot = ImagePlot(index=index,
                           value=image_source,
                           index_mapper=index_mapper,
                           origin='top left')

    return image_plot
Пример #8
0
    def _corr_plot_default(self):
        diag = self.covar.diagonal()
        corr = self.covar / np.sqrt(np.outer(diag, diag))
        N = len(diag)
        value_range = DataRange1D(low=-1, high=1)
        color_mapper = cmap(range=value_range)
        index = GridDataSource()
        value = ImageData()
        mapper = GridMapper(range=DataRange2D(index),
                            y_low_pos=1.0,
                            y_high_pos=0.0)
        index.set_data(xdata=np.arange(-0.5, N), ydata=np.arange(-0.5, N))
        value.set_data(np.flipud(corr))
        self.corr_data = value
        cmap_plot = CMapImagePlot(index=index,
                                  index_mapper=mapper,
                                  value=value,
                                  value_mapper=color_mapper,
                                  padding=(40, 40, 100, 40))

        yaxis = PlotAxis(
            cmap_plot,
            orientation='left',
            tick_interval=1,
            tick_label_formatter=lambda x: self.header[int(N - 1 - x)],
            tick_generator=ShowAllTickGenerator(positions=np.arange(N)))
        xaxis = PlotAxis(
            cmap_plot,
            orientation='top',
            tick_interval=1,
            tick_label_formatter=lambda x: self.header[int(x)],
            tick_label_alignment='edge',
            tick_generator=ShowAllTickGenerator(positions=np.arange(N)))
        cmap_plot.overlays.append(yaxis)
        cmap_plot.overlays.append(xaxis)
        colorbar = ColorBar(
            index_mapper=LinearMapper(range=cmap_plot.value_range),
            plot=cmap_plot,
            orientation='v',
            resizable='v',
            width=10,
            padding=(40, 5, 100, 40))
        container = HPlotContainer(bgcolor='transparent')
        container.add(cmap_plot)
        container.add(colorbar)
        return container
Пример #9
0
 def test_basic(self):
     x_ary = array([5.0, 6.0, 7.0, 8.0, 9.0, 10.0])
     y_ary = array([1.0, 1.0, 2.0, 2.0, 3.0, 3.0])
     ds = GridDataSource(xdata=x_ary, ydata=y_ary)
     r = DataRange2D(ds)
     mapper = GridMapper(range=r)
     mapper.x_low_pos=50
     mapper.x_high_pos=100
     mapper.y_low_pos=0
     mapper.y_high_pos=10
     result = mapper.map_screen(transpose((x_ary, y_ary)))
     assert_equal(result, [(50,0), (60,0), (70,5),
                           (80,5), (90,10), (100,10)])
Пример #10
0
    def image_histogram_plot_component(self):
        xs = np.arange(0, len(self.im))
        ys = np.arange(0, len(self.im[0]))

        index = GridDataSource(xdata=xs,
                               ydata=ys,
                               sort_order=('ascending', 'ascending'))

        index_mapper = GridMapper(range=DataRange2D(index))

        color_source = ImageData(data=np.flipud(self.im), value_depth=1)
        reversed_grays = reverse(Greys)
        color_mapper = reversed_grays(DataRange1D(color_source))

        plot = CMapImagePlot(
            index=index,
            index_mapper=index_mapper,
            value=color_source,
            value_mapper=color_mapper,
        )

        #: Add overlay for zoom
        data_box_overlay = MyDataBox(
            component=plot,
            data_position=[0, 0],
            data_bounds=self.data_bounds,
        )

        move_tool = MoveTool(component=data_box_overlay)
        resize_tool = ResizeTool(component=data_box_overlay)
        data_box_overlay.tools.append(move_tool)
        data_box_overlay.tools.append(resize_tool)

        data_box_overlay.on_trait_change(self.update_position, 'position')
        data_box_overlay.on_trait_change(self.update_data_bounds, 'bounds')

        #: Add to plot
        plot.overlays.append(data_box_overlay)

        return plot
Пример #11
0
    def image_histogram_plot_component(self):
        xs = np.arange(0, len(self.im))
        ys = np.arange(0, len(self.im[0]))

        index = GridDataSource(xdata=xs,
                               ydata=ys,
                               sort_order=('ascending', 'ascending'))

        index_mapper = GridMapper(range=DataRange2D(index))

        color_source = ImageData(data=self.im, value_depth=1)
        reversed_grays = reverse(Greys)
        color_mapper = reversed_grays(DataRange1D(color_source))

        plot = CMapImagePlot(
            index=index,
            index_mapper=index_mapper,
            value=color_source,
            value_mapper=color_mapper,
            orientation='h',
            origin='top left',
        )

        self.data_box_overlay = DataBox(
            component=plot,
            data_position=[0, 0],
            data_bounds=[self.my_data_bounds, self.my_data_bounds],
        )

        move_tool = MoveTool(component=self.data_box_overlay)
        self.data_box_overlay.tools.append(move_tool)

        self.data_box_overlay.on_trait_change(self.update_my_position,
                                              'position')

        #: Add to plot
        plot.overlays.append(self.data_box_overlay)

        return plot
Пример #12
0
def get_image_index_and_mapper(image):
    h, w = image.shape[:2]
    index = GridDataSource(np.arange(h+1), np.arange(w+1))
    index_mapper = GridMapper(range=DataRange2D(low=(0, 0), high=(h, w)))
    return index, index_mapper
    def create_plot(self):

        # Create the mapper, etc
        self._image_index = GridDataSource(array([]),
                                          array([]),
                                          sort_order=("ascending","ascending"))
        image_index_range = DataRange2D(self._image_index)
        self._image_index.on_trait_change(self._metadata_changed,
                                          "metadata_changed")

        self._image_value = ImageData(data=array([]), value_depth=1)
        image_value_range = DataRange1D(self._image_value)



        # Create the contour plots
        self.polyplot = ContourPolyPlot(index=self._image_index,
                                        value=self._image_value,
                                        index_mapper=GridMapper(range=
                                            image_index_range),
                                        color_mapper=\
                                            self._cmap(image_value_range),
                                        levels=self.num_levels)

        self.lineplot = ContourLinePlot(index=self._image_index,
                                        value=self._image_value,
                                        index_mapper=GridMapper(range=
                                            self.polyplot.index_mapper.range),
                                        levels=self.num_levels)


        # Add a left axis to the plot
        left = PlotAxis(orientation='left',
                        title= "y",
                        mapper=self.polyplot.index_mapper._ymapper,
                        component=self.polyplot)
        self.polyplot.overlays.append(left)

        # Add a bottom axis to the plot
        bottom = PlotAxis(orientation='bottom',
                          title= "x",
                          mapper=self.polyplot.index_mapper._xmapper,
                          component=self.polyplot)
        self.polyplot.overlays.append(bottom)


        # Add some tools to the plot
        self.polyplot.tools.append(PanTool(self.polyplot,
                                           constrain_key="shift"))
        self.polyplot.overlays.append(ZoomTool(component=self.polyplot,
                                            tool_mode="box", always_on=False))
        self.polyplot.overlays.append(LineInspector(component=self.polyplot,
                                               axis='index_x',
                                               inspect_mode="indexed",
                                               write_metadata=True,
                                               is_listener=True,
                                               color="white"))
        self.polyplot.overlays.append(LineInspector(component=self.polyplot,
                                               axis='index_y',
                                               inspect_mode="indexed",
                                               write_metadata=True,
                                               color="white",
                                               is_listener=True))

        # Add these two plots to one container
        contour_container = OverlayPlotContainer(padding=20,
                                                 use_backbuffer=True,
                                                 unified_draw=True)
        contour_container.add(self.polyplot)
        contour_container.add(self.lineplot)


        # Create a colorbar
        cbar_index_mapper = LinearMapper(range=image_value_range)
        self.colorbar = ColorBar(index_mapper=cbar_index_mapper,
                                 plot=self.polyplot,
                                 padding_top=self.polyplot.padding_top,
                                 padding_bottom=self.polyplot.padding_bottom,
                                 padding_right=40,
                                 resizable='v',
                                 width=30)

        self.pd = ArrayPlotData(line_index = array([]),
                                line_value = array([]),
                                scatter_index = array([]),
                                scatter_value = array([]),
                                scatter_color = array([]))

        self.cross_plot = Plot(self.pd, resizable="h")
        self.cross_plot.height = 100
        self.cross_plot.padding = 20
        self.cross_plot.plot(("line_index", "line_value"),
                             line_style="dot")
        self.cross_plot.plot(("scatter_index","scatter_value","scatter_color"),
                             type="cmap_scatter",
                             name="dot",
                             color_mapper=self._cmap(image_value_range),
                             marker="circle",
                             marker_size=8)

        self.cross_plot.index_range = self.polyplot.index_range.x_range

        self.pd.set_data("line_index2", array([]))
        self.pd.set_data("line_value2", array([]))
        self.pd.set_data("scatter_index2", array([]))
        self.pd.set_data("scatter_value2", array([]))
        self.pd.set_data("scatter_color2", array([]))

        self.cross_plot2 = Plot(self.pd, width = 140, orientation="v", resizable="v", padding=20, padding_bottom=160)
        self.cross_plot2.plot(("line_index2", "line_value2"),
                             line_style="dot")
        self.cross_plot2.plot(("scatter_index2","scatter_value2","scatter_color2"),
                             type="cmap_scatter",
                             name="dot",
                             color_mapper=self._cmap(image_value_range),
                             marker="circle",
                             marker_size=8)

        self.cross_plot2.index_range = self.polyplot.index_range.y_range



        # Create a container and add components
        self.container = HPlotContainer(padding=40, fill_padding=True,
                                        bgcolor = "white", use_backbuffer=False)
        inner_cont = VPlotContainer(padding=0, use_backbuffer=True)
        inner_cont.add(self.cross_plot)
        inner_cont.add(contour_container)
        self.container.add(self.colorbar)
        self.container.add(inner_cont)
        self.container.add(self.cross_plot2)
Пример #14
0
 def setUp(self):
     self.x_ary = array([5.0, 6.0, 7.0, 8.0, 9.0, 10.0])
     self.y_ary = array([1.0, 1.0, 2.0, 2.0, 3.0, 3.0])
     ds = GridDataSource(xdata=self.x_ary, ydata=self.y_ary)
     r = DataRange2D(ds)
     self.mapper = GridMapper(range=r)
    def __init__(self, x, y, z):
        super(ImagePlot, self).__init__()
        self.pd_all = ArrayPlotData(imagedata=z)
        #self.pd_horiz = ArrayPlotData(x=x, horiz=z[4, :])
        #self.pd_vert = ArrayPlotData(y=y, vert=z[:,5])

        self._imag_index = GridDataSource(xdata=x,
                                          ydata=y,
                                          sort_order=("ascending",
                                                      "ascending"))
        index_mapper = GridMapper(range=DataRange2D(self._imag_index))
        self._imag_index.on_trait_change(self._metadata_changed,
                                         "metadata_changed")
        self._image_value = ImageData(data=z, value_depth=1)
        color_mapper = jet(DataRange1D(self._image_value))

        self.color_plot = CMapImagePlot(index=self._imag_index,
                                        index_mapper=index_mapper,
                                        value=self._image_value,
                                        value_mapper=color_mapper,
                                        padding=20,
                                        use_backbuffer=True,
                                        unified_draw=True)

        #Add axes to image plot
        left = PlotAxis(orientation='left',
                        title="Frequency (GHz)",
                        mapper=self.color_plot.index_mapper._ymapper,
                        component=self.color_plot)

        self.color_plot.overlays.append(left)

        bottom = PlotAxis(orientation='bottom',
                          title="Time (us)",
                          mapper=self.color_plot.index_mapper._xmapper,
                          component=self.color_plot)
        self.color_plot.overlays.append(bottom)

        self.color_plot.tools.append(
            PanTool(self.color_plot, constrain_key="shift"))
        self.color_plot.overlays.append(
            ZoomTool(component=self.color_plot,
                     tool_mode="box",
                     always_on=False))

        #Add line inspector tool for horizontal and vertical
        self.color_plot.overlays.append(
            LineInspector(component=self.color_plot,
                          axis='index_x',
                          inspect_mode="indexed",
                          write_metadata=True,
                          is_listener=True,
                          color="white"))

        self.color_plot.overlays.append(
            LineInspector(component=self.color_plot,
                          axis='index_y',
                          inspect_mode="indexed",
                          write_metadata=True,
                          color="white",
                          is_listener=True))

        myrange = DataRange1D(low=amin(z), high=amax(z))
        cmap = jet
        self.colormap = cmap(myrange)

        # Create a colorbar
        cbar_index_mapper = LinearMapper(range=myrange)
        self.colorbar = ColorBar(index_mapper=cbar_index_mapper,
                                 plot=self.color_plot,
                                 padding_top=self.color_plot.padding_top,
                                 padding_bottom=self.color_plot.padding_bottom,
                                 padding_right=40,
                                 resizable='v',
                                 width=30)  #, ytitle="Magvec (mV)")

        #create horizontal line plot
        self.horiz_cross_plot = Plot(self.pd_horiz, resizable="h")
        self.horiz_cross_plot.height = 100
        self.horiz_cross_plot.padding = 20
        self.horiz_cross_plot.plot(("x", "horiz"))  #,
        #line_style="dot")
        #        self.cross_plot.plot(("scatter_index","scatter_value","scatter_color"),
        #                             type="cmap_scatter",
        #                             name="dot",
        #                             color_mapper=self._cmap(image_value_range),
        #                             marker="circle",
        #                             marker_size=8)

        self.horiz_cross_plot.index_range = self.color_plot.index_range.x_range

        #create vertical line plot
        self.vert_cross_plot = Plot(self.pd_vert,
                                    width=140,
                                    orientation="v",
                                    resizable="v",
                                    padding=20,
                                    padding_bottom=160)
        self.vert_cross_plot.plot(("y", "vert"))  #,
        #                             line_style="dot")
        # self.vert_cross_plot.xtitle="Magvec (mV)"
        #       self.vertica_cross_plot.plot(("vertical_scatter_index",
        #                              "vertical_scatter_value",
        #                              "vertical_scatter_color"),
        #                            type="cmap_scatter",
        #                            name="dot",
        #                            color_mapper=self._cmap(image_value_range),
        #                            marker="circle",
        #                           marker_size=8)

        self.vert_cross_plot.index_range = self.color_plot.index_range.y_range

        # Create a container and add components
        self.container = HPlotContainer(padding=40,
                                        fill_padding=True,
                                        bgcolor="white",
                                        use_backbuffer=False)
        inner_cont = VPlotContainer(padding=0, use_backbuffer=True)
        inner_cont.add(self.horiz_cross_plot)
        inner_cont.add(self.color_plot)
        self.container.add(self.colorbar)
        self.container.add(inner_cont)
        self.container.add(self.vert_cross_plot)
Пример #16
0
 def setUp(self):
     self.x_ary = array([5.0, 6.0, 7.0, 8.0, 9.0, 10.0])
     self.y_ary = array([1.0, 1.0, 2.0, 2.0, 3.0, 3.0])
     ds = GridDataSource(xdata=self.x_ary, ydata=self.y_ary)
     r = DataRange2D(ds)
     self.mapper = GridMapper(range=r)