Esempio n. 1
0
 def recalculate(self):
     if self.func is not None and self.data_range is not None:
         newarray = self.func(self.data_range.x_range.low,
                              self.data_range.x_range.high,
                              self.data_range.y_range.low,
                              self.data_range.y_range.high)
         ImageData.set_data(self, newarray)
     else:
         self._data = array([], dtype=float)
 def set_pict(self):
     pd = self.plot_data
     if not pd:
         return
     try:
         imgd = ImageData.fromfile(self.pict)._data[::-1]
     except:
         imgd = ImageData()
         imgd.set_data(255 * ones((2, 2, 3), dtype='uint8'))
         imgd = imgd._data
     pd.set_data("image", imgd)
 def recalculate(self):
     if self.func is not None and self.data_range is not None:
         newarray = self.func(
             self.data_range.x_range.low,
             self.data_range.x_range.high,
             self.data_range.y_range.low,
             self.data_range.y_range.high,
         )
         ImageData.set_data(self, newarray)
     else:
         self._data = array([], dtype=float)
Esempio n. 4
0
 def set_pict(self):
     pd = self.plot_data
     if not pd:
         return
     try:
         imgd = ImageData.fromfile(self.pict)._data[::-1]
     except:
         imgd = ImageData()
         imgd.set_data(255*ones((2,2,3),dtype='uint8'))
         imgd = imgd._data
     pd.set_data("image",imgd)
Esempio n. 5
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)
Esempio n. 6
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()
 def _load(self):
     try:
         image = ImageData.fromfile(self._load_file)
         self.pd.set_data('imagedata', image._data)
         self.plot.title = "YO DOGG: %s" % os.path.basename(self._load_file)
         self.plot.request_redraw()
     except Exception, exc:
         print "YO DOGG: %s" % exc
Esempio n. 8
0
def rendered_image_result(image, filename=None, **plot_kwargs):
    data_source = ImageData(data=image)
    index, index_mapper = get_image_index_and_mapper(image)
    renderer = ImagePlot(value=data_source, index=index,
                         index_mapper=index_mapper,
                         **plot_kwargs)
    orientation = plot_kwargs.get('orientation', 'h')
    return image_from_renderer(renderer, orientation)
Esempio n. 9
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
Esempio n. 10
0
def do_imread(*data, **kwargs):
    """ Returns image file as array. """

    # Check to see if the data given is either a file path or a file object
    if isinstance(data[0], six.string_types) or isinstance(data[0], io.IOBase):
        return ImageData.fromfile(data[0])
    else:
        raise ValueError("do_imread takes a string filename")
Esempio n. 11
0
def do_imread(*data, **kwargs):
    """ Returns image file as array. """

    # Check to see if the data given is either a file path or a file object
    if isinstance(data[0], basestring) or isinstance(data[0], file):
        return ImageData.fromfile(data[0])
    else:
        raise ValueError("do_imread takes a string filename")
Esempio n. 12
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)
Esempio n. 13
0
    def _load(self):
        # Load the image with the user supplied filename
        image = ImageData.fromfile(self._load_file)

        # Update the plot data. NB we must extract _data from the image
        # for the time being, until ImageData is made more friendly
        self.pd.set_data("imagedata", image._data)

        # Set the title and redraw
        self.plot.title = os.path.basename(self._load_file)
        self.plot.request_redraw()
Esempio n. 14
0
    def _load(self):
        # Load the image with the user supplied filename
        image = ImageData.fromfile(self._load_file)

        # Update the plot data. NB we must extract _data from the image
        # for the time being, until ImageData is made more friendly
        self.pd.set_data("imagedata", image._data)

        # Set the title and redraw
        self.plot.title = os.path.basename(self._load_file)
        self.plot.request_redraw()
Esempio n. 15
0
def image_from_renderer(renderer, orientation):
    data = renderer.value
    # Set bounding box size and origin to align rendered image with array
    renderer.bounds = (data.get_width() + 1, data.get_height() + 1)
    if orientation == 'v':
        renderer.bounds = renderer.bounds[::-1]
    renderer.position = 0, 0

    with temp_image_file() as filename:
        save_renderer_result(renderer, filename)
        rendered_image = ImageData.fromfile(filename).data[TRIM_RENDERED]
    return rendered_image
Esempio n. 16
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
Esempio n. 17
0
    def __init__(self, **kw):
        super(WorldMapPlot, self).__init__(**kw)

        self._download_map_image()
        image = ImageData.fromfile(self.image_path)

        # For now, the locations are hardcoded, though this can be changed
        # eassily to take command line args, read from a file, or by other
        # means
        austin_loc = (30.16, -97.44)

        locations_x = numpy.array([austin_loc[1]])
        locations_y = numpy.array([austin_loc[0]])

        # transform each of the locations to the image data space, including
        # moving the origin from bottom left to top left
        locations_x = (locations_x + 180) * image.data.shape[1] / 360
        locations_y = (locations_y * -1 + 90) * image.data.shape[0] / 180

        # Create the plott data, adding the image and the locations
        plot_data = ArrayPlotData()
        plot_data.set_data("imagedata", image._data)
        plot_data.set_data("locations_x", locations_x)
        plot_data.set_data("locations_y", locations_y)

        # Create the plot with the origin as top left, which matches
        # how the image data is aligned
        self.plot = Plot(plot_data, default_origin="top left")
        self.plot.img_plot('imagedata')

        # Plot the locations as a scatter plot to be overlayed on top
        # of the map
        loc_plot = self.plot.plot(('locations_x', 'locations_y'),
                                  type='scatter',
                                  size=3,
                                  color='yellow',
                                  marker='dot')[0]

        loc_plot.x_mapper.range.high = image.data.shape[1]
        loc_plot.x_mapper.range.low = 0
        loc_plot.y_mapper.range.high = image.data.shape[0]
        loc_plot.y_mapper.range.low = -0

        # set up any tools, in this case just the zoom tool
        zoom = ZoomTool(component=self.plot, tool_mode="box", always_on=False)
        self.plot.overlays.append(zoom)
Esempio n. 18
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
Esempio n. 19
0
    def __init__(self, **kw):
        super(WorldMapPlot, self).__init__(**kw)

        self._download_map_image()
        image = ImageData.fromfile(self.image_path)

        # For now, the locations are hardcoded, though this can be changed
        # eassily to take command line args, read from a file, or by other
        # means
        austin_loc = (30.16, -97.44)

        locations_x = numpy.array([austin_loc[1]])
        locations_y = numpy.array([austin_loc[0]])

        # transform each of the locations to the image data space, including
        # moving the origin from bottom left to top left
        locations_x = (locations_x + 180) * image.data.shape[1]/360
        locations_y = (locations_y*-1 + 90) * image.data.shape[0]/180

        # Create the plott data, adding the image and the locations
        plot_data = ArrayPlotData()
        plot_data.set_data("imagedata", image._data)
        plot_data.set_data("locations_x", locations_x)
        plot_data.set_data("locations_y", locations_y)

        # Create the plot with the origin as top left, which matches
        # how the image data is aligned
        self.plot = Plot(plot_data, default_origin="top left")
        self.plot.img_plot('imagedata')

        # Plot the locations as a scatter plot to be overlayed on top
        # of the map
        loc_plot = self.plot.plot(('locations_x',  'locations_y'),
                                    type='scatter', size=3, color='yellow',
                                    marker='dot')[0]

        loc_plot.x_mapper.range.high = image.data.shape[1]
        loc_plot.x_mapper.range.low = 0
        loc_plot.y_mapper.range.high = image.data.shape[0]
        loc_plot.y_mapper.range.low = -0

        # set up any tools, in this case just the zoom tool
        zoom = ZoomTool(component=self.plot, tool_mode="box", always_on=False)
        self.plot.overlays.append(zoom)
Esempio n. 20
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
Esempio n. 21
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
Esempio n. 22
0
    def test_array_bounds_transposed(self):
        myarray = arange(15).reshape(5, 3, 1)
        data_source = ImageData(data=myarray, transposed=True)

        self.assertEqual(((0, 5), (0, 3)), data_source.get_array_bounds())
Esempio n. 23
0
    def __init__(self):
        self.plotData = ArrayPlotData()
        self.backImg = Plot(self.plotData, default_origin="top left")
        self.backImg.x_axis = None
        self.backImg.y_axis = None
        self.backImg.padding = (3, 3, 3, 3)
        image = ImageData.fromfile("world.png")
        self.plotData.set_data("imagedata", image._data)
        self.backImg.img_plot("imagedata")

        self.image = True
        self.imageVisible = True

        #        self._refresh_fired()

        # TMP
        x = []
        y = []
        c = []

        feed = parse(
            "http://geofon.gfz-potsdam.de/eqinfo/list.php?datemin=&datemax=&latmin=&latmax=&lonmin=&lonmax=&magmin=5.&nmax=100&fmt=rss"
        )
        self.entries = feed["entries"]
        clen = len(self.entries)

        for i, entry in enumerate(self.entries):
            edate, etime, elat, elon, edep, eunit, estatus = entry["summary"].split()
            x.append(((float(elon) + 180) / 360) * 5400.0)
            y.append(2700 - ((float(elat) + 90) / 180) * 2700.0)
            c.append(clen - i)

        self.plotData.set_data("X", x)
        self.plotData.set_data("Y", y)
        self.plotData.set_data("C", c)

        self.backImg.plot(
            ("X", "Y", "C"),
            type="cmap_scatter",
            color_mapper=jet,
            marker="circle",
            index_sort="ascending",
            color="orange",
            marker_size=10,
            bgcolor="white",
            name="earthquakes",
        )
        my_plot = self.backImg.plots["earthquakes"][0]
        my_plot.tools.append(ScatterInspector(my_plot, selection_mode="toggle", persistent_hover=False))
        my_plot.overlays.append(
            ScatterInspectorOverlay(
                my_plot,
                hover_color="transparent",
                hover_marker_size=10,
                hover_outline_color="purple",
                hover_line_width=2,
                selection_marker_size=8,
                selection_color="lawngreen",
            )
        )
        zoom = ZoomTool(component=my_plot, tool_mode="box", always_on=False)
        my_plot.overlays.append(zoom)

        pan = PanTool(my_plot)
        my_plot.tools.append(pan)

        self.index_datasource = my_plot.index
        self.index_datasource.on_trait_change(self._metadata_handler, "metadata_changed")
        self.map = Basemap()
Esempio n. 24
0
    def test_get_height_transposed(self):
        myarray = arange(15).reshape(5, 3, 1)
        data_source = ImageData(data=myarray, transposed=True)

        self.assertEqual(3, data_source.get_height())
Esempio n. 25
0
 def setUp(self):
     self.myarray = arange(15).reshape(5, 3, 1)
     self.data_source = ImageData(data=self.myarray)
    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)
Esempio n. 27
0
 def test_data_size_no_data(self):
     data_source = ImageData()
     self.assertEqual(0, data_source.get_size())
Esempio n. 28
0
    def test_get_data_no_data(self):
        data_source = ImageData()

        self.assertIsNone(data_source.get_data())
Esempio n. 29
0
    def test_get_data_mask_no_data(self):
        data_source = ImageData()

        # XXX this is probably not the right thing
        with self.assertRaises(NotImplementedError):
            data, mask = data_source.get_data_mask()
Esempio n. 30
0
 def test_data_size_no_data(self):
     data_source = ImageData()
     self.assertEqual(0, data_source.get_size())
Esempio n. 31
0
 def setUp(self):
     self.myarray = arange(15).reshape(5, 3, 1)
     self.data_source = ImageData(data=self.myarray)
Esempio n. 32
0
    def test_get_data_no_data(self):
        data_source = ImageData()

        self.assertIsNone(data_source.get_data())
Esempio n. 33
0
  def _myTIC_default( self ):

    # create an interesting scalar field for the image plot
    # Eggholder function
    limitF = 500.0
    xA = linspace(-limitF, limitF, 600)
    yA = linspace(-limitF, limitF, 600)
    ( xMG,yMG ) = meshgrid( xA,yA )
    zMG = -(yMG + 47) * sin( sqrt(abs(yMG + xMG/2 + 47 )))
    zMG = zMG - xMG * sin( sqrt(abs(xMG - (yMG + 47))))

    # Create an ArrayPlotData object and give it this data
    myAPD = ArrayPlotData()
    myAPD.set_data( "Z", zMG )
    myAPD.set_data( "X",xA )
    myAPD.set_data( "Y",yA )

    # Create the plot
    self.myTP = Plot( myAPD )

    # contains a dict of default colormaps and their functions. We have to
    # pass the colormapper the data range of interest to set up the private
    # attributes
    default_colormaps.color_map_name_dict

    # the colormap method needs the range of the image data that we want to
    # plot. We first put the image data (zMG) into an ImageData object. We
    # then use DataRange1D on the ImageData instance to produce a DataRange1D
    # instance describing the ImageData data. Finally, we feed the DataRange1D
    # instance into the colormapper to produce a working colormapper.
    myID = ImageData( )
    myID.set_data( zMG )
    self.myDR1D = DataRange1D( myID )

    # pick an unmodified (i.e. unreversed, no ranges) colormap and build
    # the colormap functions
    myColorMapperFn = default_colormaps.color_map_name_dict[self.colormapNameTE]
    myColorMapper = myColorMapperFn( self.myDR1D )

    # add the image plot to this plot object
    # specify the colormap explicitly
    self.myTP.img_plot(
        "Z",
        xbounds = (xA[0],xA[-1]),
        ybounds = (yA[0],yA[-1]),
        colormap = myColorMapper,
    )

    # add the title and padding around the plot
    self.myTP.title = "Eggholder Function"
    self.myTP.padding = 50

    # grids, fonts, etc
    self.myTP.x_axis.title = "X"
    self.myTP.y_axis.title = "Y"

    # generate a ColorBar. pulls its colormapper from the myTP Plot object
    self.myTCB = ColorBar(
      plot = self.myTP,
      index_mapper = LinearMapper( range = self.myTP.color_mapper.range ),
      orientation = 'v',
      resizable = 'v',
      width = 40,
      padding = 30,
    )

    # set the padding of the ColorBar to match the padding of the plot
    self.myTCB.padding_top = self.myTP.padding_top
    self.myTCB.padding_bottom = self.myTP.padding_bottom

    # build up a single container for the colorbar and the image
    myHPC = HPlotContainer( use_backbuffer = True )
    myHPC.add( self.myTP )
    myHPC.add( self.myTCB )

    return( myHPC )
Esempio n. 34
0
    def test_get_data_mask_no_data(self):
        data_source = ImageData()

        # XXX this is probably not the right thing
        with self.assertRaises(NotImplementedError):
            data, mask = data_source.get_data_mask()
Esempio n. 35
0
 def test_bounds_empty(self):
     data_source = ImageData()
     bounds = data_source.get_bounds()
     self.assertEqual(bounds, (0, 0))
Esempio n. 36
0
    def test_fromfile_png_rgba(self):
        # basic smoke test - assume that kiva.image does the right thing
        path = os.path.join(data_dir, 'PngSuite', 'basi6a08.png')
        data_source = ImageData.fromfile(path)

        self.assertEqual(data_source.value_depth, 4)
Esempio n. 37
0
    def test_get_data_transposed(self):
        myarray = arange(15).reshape(5, 3, 1)
        data_source = ImageData(data=myarray, transposed=True)

        assert_array_equal(swapaxes(myarray, 0, 1), data_source.get_data())
Esempio n. 38
0
class ImageDataTestCase(UnittestTools, unittest.TestCase):
    def setUp(self):
        self.myarray = arange(15).reshape(5, 3, 1)
        self.data_source = ImageData(data=self.myarray)

    def test_init_defaults(self):
        data_source = ImageData()
        assert_array_equal(data_source.data, [])

        # this isn't right -
        #self.assertEqual(data_source.value_dimension, "scalar")
        #self.assertEqual(data_source.image_dimension, "image")

    def test_basic_setup(self):
        assert_array_equal(self.myarray, self.data_source.data)
        #self.assertEqual(self.data_source.value_dimension, "scalar")
        self.assertFalse(self.data_source.is_masked())

    def test_set_data(self):
        new_array = arange(0, 30, 2).reshape(5, 3, 1)

        with self.assertTraitChanges(self.data_source, 'data_changed',
                                     count=1):
            self.data_source.set_data(new_array)

        assert_array_equal(new_array, self.data_source.data)
        self.assertEqual(self.data_source.get_bounds(), (0, 28))

    def test_get_data(self):
        assert_array_equal(self.myarray, self.data_source.get_data())

    def test_get_data_no_data(self):
        data_source = ImageData()

        self.assertIsNone(data_source.get_data())

    def test_get_data_transposed(self):
        myarray = arange(15).reshape(5, 3, 1)
        data_source = ImageData(data=myarray, transposed=True)

        assert_array_equal(swapaxes(myarray, 0, 1), data_source.get_data())

    def test_get_data_mask(self):
        # XXX this is probably not the right thing
        with self.assertRaises(NotImplementedError):
            data, mask = self.data_source.get_data_mask()

    def test_get_data_mask_no_data(self):
        data_source = ImageData()

        # XXX this is probably not the right thing
        with self.assertRaises(NotImplementedError):
            data, mask = data_source.get_data_mask()

    def test_bounds(self):
        bounds = self.data_source.get_bounds()
        self.assertEqual(bounds, (0, 14))

    @unittest.skip('test_bounds_empty() fails in this case')
    def test_bounds_empty(self):
        data_source = ImageData()
        bounds = data_source.get_bounds()
        self.assertEqual(bounds, (0, 0))

    def test_data_size(self):
        self.assertEqual(15, self.data_source.get_size())

    def test_data_size_no_data(self):
        data_source = ImageData()
        self.assertEqual(0, data_source.get_size())

    def test_get_width(self):
        self.assertEqual(3, self.data_source.get_width())

    def test_get_width_transposed(self):
        myarray = arange(15).reshape(5, 3)
        data_source = ImageData(data=myarray, transposed=True)

        self.assertEqual(5, data_source.get_width())

    def test_get_height(self):
        self.assertEqual(5, self.data_source.get_height())

    def test_get_height_transposed(self):
        myarray = arange(15).reshape(5, 3, 1)
        data_source = ImageData(data=myarray, transposed=True)

        self.assertEqual(3, data_source.get_height())

    def test_array_bounds(self):
        self.assertEqual(((0, 3), (0, 5)), self.data_source.get_array_bounds())

    def test_array_bounds_transposed(self):
        myarray = arange(15).reshape(5, 3, 1)
        data_source = ImageData(data=myarray, transposed=True)

        self.assertEqual(((0, 5), (0, 3)), data_source.get_array_bounds())

    def test_fromfile_png_rgb(self):
        # basic smoke test - assume that kiva.image does the right thing
        path = os.path.join(data_dir, 'PngSuite', 'basn2c08.png')
        data_source = ImageData.fromfile(path)

        self.assertEqual(data_source.value_depth, 3)

    def test_fromfile_png_rgba(self):
        # basic smoke test - assume that kiva.image does the right thing
        path = os.path.join(data_dir, 'PngSuite', 'basi6a08.png')
        data_source = ImageData.fromfile(path)

        self.assertEqual(data_source.value_depth, 4)

    def test_metadata(self):
        self.assertEqual(self.data_source.metadata, {
            'annotations': [],
            'selections': []
        })

    def test_metadata_changed(self):
        with self.assertTraitChanges(self.data_source,
                                     'metadata_changed',
                                     count=1):
            self.data_source.metadata = {'new_metadata': True}

    def test_metadata_items_changed(self):
        with self.assertTraitChanges(self.data_source,
                                     'metadata_changed',
                                     count=1):
            self.data_source.metadata['new_metadata'] = True
Esempio n. 39
0
    def test_get_width_transposed(self):
        myarray = arange(15).reshape(5, 3)
        data_source = ImageData(data=myarray, transposed=True)

        self.assertEqual(5, data_source.get_width())
Esempio n. 40
0
 def test_init_defaults(self):
     data_source = ImageData()
     assert_array_equal(data_source.data, [])
    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)
Esempio n. 42
0
    def test_get_data_transposed(self):
        myarray = arange(15).reshape(5, 3, 1)
        data_source = ImageData(data=myarray, transposed=True)

        assert_array_equal(swapaxes(myarray, 0, 1), data_source.get_data())
Esempio n. 43
0
    def test_fromfile_png_rgba(self):
        # basic smoke test - assume that kiva.image does the right thing
        path = os.path.join(data_dir, 'PngSuite', 'basi6a08.png')
        data_source = ImageData.fromfile(path)

        self.assertEqual(data_source.value_depth, 4)
Esempio n. 44
0
 def test_bounds_empty(self):
     data_source = ImageData()
     bounds = data_source.get_bounds()
     self.assertEqual(bounds, (0, 0))
Esempio n. 45
0
    def test_array_bounds_transposed(self):
        myarray = arange(15).reshape(5, 3, 1)
        data_source = ImageData(data=myarray, transposed=True)

        self.assertEqual(((0, 5), (0, 3)), data_source.get_array_bounds())
Esempio n. 46
0
    def test_get_width_transposed(self):
        myarray = arange(15).reshape(5, 3)
        data_source = ImageData(data=myarray, transposed=True)

        self.assertEqual(5, data_source.get_width())
Esempio n. 47
0
    def test_get_height_transposed(self):
        myarray = arange(15).reshape(5, 3, 1)
        data_source = ImageData(data=myarray, transposed=True)

        self.assertEqual(3, data_source.get_height())
Esempio n. 48
0
 def _filename_changed(self, new):
     image = ImageData.fromfile(new)
     self.plot_image(image._data)
Esempio n. 49
0
  def _myTIC_default( self ):

    # create an interesting scalar field for the image plot
    # Eggholder function
    limitF = 500.0
    xA = linspace(-limitF, limitF, 600)
    yA = linspace(-limitF, limitF, 600)
    ( xMG,yMG ) = meshgrid( xA,yA )
    zMG = -(yMG + 47) * sin( sqrt(abs(yMG + xMG/2 + 47 )))
    zMG = zMG - xMG * sin( sqrt(abs(xMG - (yMG + 47))))

    # Create an ArrayPlotData object and give it this data
    myAPD = ArrayPlotData()
    myAPD.set_data( "Z", zMG )
    myAPD.set_data( "X",xA )
    myAPD.set_data( "Y",yA )

    # Create the plot
    myTP = Plot( myAPD )

    # contains a dict of default colormaps and their functions. We have to
    # pass the colormapper the data range of interest to set up the private
    # attributes
    default_colormaps.color_map_name_dict

    # the colormap method needs the range of the image data that we want to
    # plot. We first put the image data (zMG) into an ImageData object. We
    # then use DataRange1D on the ImageData instance to produce a DataRange1D
    # instance describing the ImageData data. Finally, we feed the DataRange1D
    # instance into the colormapper to produce a working colormapper.
    myID = ImageData( )
    myID.set_data( zMG )
    myDR1D = DataRange1D( myID )

    # pick a colormap
    myColorMapperFn = default_colormaps.color_map_name_dict['copper']

    # choose one or more modifications to the colormap function
    #myColorMapperFn = default_colormaps.reverse( myColorMapperFn )
    #myColorMapperFn = default_colormaps.center( myColorMapperFn,500 )
    #myColorMapperFn = default_colormaps.fix( myColorMapperFn,(-500,500) )

    # finally, build the colormapper function
    myColorMapper = myColorMapperFn( myDR1D )

    # add the image plot to this plot object
    # specify the colormap explicitly
    myTP.img_plot(
        "Z",
        xbounds = (xA[0],xA[-1]),
        ybounds = (yA[0],yA[-1]),
        colormap = myColorMapper,
    )

    # add the title and padding around the plot
    myTP.title = "Eggholder Function"
    myTP.padding = 50

    # grids, fonts, etc
    myTP.x_axis.title = "X"
    myTP.y_axis.title = "Y"

    # generate a ColorBar. pulls its colormapper from the myTP Plot object
    myTCB = ColorBar(
      plot = myTP,
      index_mapper = LinearMapper( range = myTP.color_mapper.range ),
      orientation = 'v',
      resizable = 'v',
      width = 40,
      padding = 30,
    )

    # set the padding of the ColorBar to match the padding of the plot
    myTCB.padding_top = myTP.padding_top
    myTCB.padding_bottom = myTP.padding_bottom

    # range of the colormapper. Changes the min/max values that are mapped
    # to the ends of the color range. Try +/-2000 for poor contrast and +/-200 for
    # saturated. Asymmetrical values work as well.
    #myTP.color_mapper.range.low_setting = 0
    #myTP.color_mapper.range.high_setting = 1000

    # build up a single container for the colorbar and the image
    myHPC = HPlotContainer( use_backbuffer = True )
    myHPC.add( myTP )
    myHPC.add( myTCB )

    return( myHPC )
Esempio n. 50
0
    def create_plot_component(self):
        if not self.data.size:
            return

        self.pd = ArrayPlotData()
        self.shape = self.data.shape
        self.pd.set_data("imagedata", self.data)
        self.pd.set_data("left_line", self.data[:, self.shape[0]//2])
        self.pd.set_data("top_line", self.data[self.shape[1]//2,:])

        plot = Plot(self.pd)
        cmap = default_colormaps.color_map_name_dict[self.colormap]

        if self.rev_cmap:
            cmap = default_colormaps.reverse(cmap)

        drange = DataRange1D(ImageData(data=self.data, value_depth=1))



        self.ccmap = cmap_constant_range(cmap, drange)(drange)

            #from copy import copy
        self.img_plot = plot.img_plot("imagedata",
                                 colormap=cmap,
                                 #xbounds=self.xbounds,
                                 #ybounds=self.ybounds,
                                 )[0]
        self.cmap = self.img_plot.value_mapper
        if not self.autoscale:
            self.img_plot.value_mapper = self.ccmap
        # Tweak some of the plot properties
        plot.title = self.title
        plot.padding = 10

        # Attach some tools to the plot
        plot.tools.append(PanTool(plot))
        zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
        plot.overlays.append(zoom)

        csr = CursorTool(self.img_plot,
                          drag_button='right',
                          color='white',
                          line_width=2.0
                          )
        self.cursor = csr

        csr.current_index = self.shape[0]//2, self.shape[1]//2
        self.img_plot.overlays.append(csr)

        imgtool = ImageInspectorTool(self.img_plot)
        self.img_plot.tools.append(imgtool)

        overlay = ImageInspectorOverlay(component=self.img_plot, image_inspector=imgtool,
                                        bgcolor="white", border_visible=True)

        self.img_plot.overlays.append(overlay)
        self.plot = plot

        self.cross_plot = Plot(self.pd,resizable='h')
        self.cross_plot.height = 40
        self.cross_plot.padding = 15
        self.cross_plot.plot("top_line",
                             line_style="dot")


        self.cross_plot.index_range = self.img_plot.index_range.x_range


        self.cross_plot2 = Plot(self.pd, width=40, orientation="v",
                                padding=15, padding_bottom=10, resizable='v')
        self.cross_plot2.plot("left_line",
                              line_style="dot")


        self.cross_plot2.index_range = self.img_plot.index_range.y_range

        # Create a container and add components
        #self.container = HPlotContainer(padding=10, fill_padding=False,
        #                                bgcolor="none", use_backbuffer=False)
        #inner_cont = VPlotContainer(padding=0, use_backbuffer=True, bgcolor="none")
        #inner_cont.add(self.plot)
        #inner_cont.add(self.cross_plot)
        self.container = GridPlotContainer(padding=20, fill_padding=False,
                                      bgcolor="none", use_backbuffer=True,
                                      shape=(2, 2), spacing=(12, 20))

        #self.container.add(self.colorbar)
        self.container.add(self.plot)
        self.container.add(self.cross_plot2)
        self.container.add(self.cross_plot)
Esempio n. 51
0
class ImageDataTestCase(UnittestTools, unittest.TestCase):

    def setUp(self):
        self.myarray = arange(15).reshape(5, 3, 1)
        self.data_source = ImageData(data=self.myarray)

    def test_init_defaults(self):
        data_source = ImageData()
        assert_array_equal(data_source.data, [])

        # this isn't right -
        #self.assertEqual(data_source.value_dimension, "scalar")
        #self.assertEqual(data_source.image_dimension, "image")

    def test_basic_setup(self):
        assert_array_equal(self.myarray, self.data_source.data)
        #self.assertEqual(self.data_source.value_dimension, "scalar")
        self.assertFalse(self.data_source.is_masked())

    def test_set_data(self):
        new_array = arange(0, 30, 2).reshape(5, 3, 1)

        with self.assertTraitChanges(self.data_source, 'data_changed', count=1):
            self.data_source.set_data(new_array)

        assert_array_equal(new_array, self.data_source.data)
        self.assertEqual(self.data_source.get_bounds(), (0, 28))

    def test_get_data(self):
        assert_array_equal(self.myarray, self.data_source.get_data())

    def test_get_data_no_data(self):
        data_source = ImageData()

        self.assertIsNone(data_source.get_data())

    def test_get_data_transposed(self):
        myarray = arange(15).reshape(5, 3, 1)
        data_source = ImageData(data=myarray, transposed=True)

        assert_array_equal(swapaxes(myarray, 0, 1), data_source.get_data())

    def test_get_data_mask(self):
        # XXX this is probably not the right thing
        with self.assertRaises(NotImplementedError):
            data, mask = self.data_source.get_data_mask()

    def test_get_data_mask_no_data(self):
        data_source = ImageData()

        # XXX this is probably not the right thing
        with self.assertRaises(NotImplementedError):
            data, mask = data_source.get_data_mask()

    def test_bounds(self):
        bounds = self.data_source.get_bounds()
        self.assertEqual(bounds, (0, 14))

    @unittest.skip('test_bounds_empty() fails in this case')
    def test_bounds_empty(self):
        data_source = ImageData()
        bounds = data_source.get_bounds()
        self.assertEqual(bounds, (0, 0))

    def test_data_size(self):
        self.assertEqual(15, self.data_source.get_size())

    def test_data_size_no_data(self):
        data_source = ImageData()
        self.assertEqual(0, data_source.get_size())

    def test_get_width(self):
        self.assertEqual(3, self.data_source.get_width())

    def test_get_width_transposed(self):
        myarray = arange(15).reshape(5, 3)
        data_source = ImageData(data=myarray, transposed=True)

        self.assertEqual(5, data_source.get_width())

    def test_get_height(self):
        self.assertEqual(5, self.data_source.get_height())

    def test_get_height_transposed(self):
        myarray = arange(15).reshape(5, 3, 1)
        data_source = ImageData(data=myarray, transposed=True)

        self.assertEqual(3, data_source.get_height())

    def test_array_bounds(self):
        self.assertEqual(((0, 3), (0, 5)), self.data_source.get_array_bounds())

    def test_array_bounds_transposed(self):
        myarray = arange(15).reshape(5, 3, 1)
        data_source = ImageData(data=myarray, transposed=True)

        self.assertEqual(((0, 5), (0, 3)), data_source.get_array_bounds())

    def test_fromfile_png_rgb(self):
        # basic smoke test - assume that kiva.image does the right thing
        path = os.path.join(data_dir, 'PngSuite', 'basn2c08.png')
        data_source = ImageData.fromfile(path)

        self.assertEqual(data_source.value_depth, 3)

    def test_fromfile_png_rgba(self):
        # basic smoke test - assume that kiva.image does the right thing
        path = os.path.join(data_dir, 'PngSuite', 'basi6a08.png')
        data_source = ImageData.fromfile(path)

        self.assertEqual(data_source.value_depth, 4)

    def test_metadata(self):
        self.assertEqual(self.data_source.metadata,
                         {'annotations': [], 'selections': []})

    def test_metadata_changed(self):
        with self.assertTraitChanges(self.data_source, 'metadata_changed', count=1):
            self.data_source.metadata = {'new_metadata': True}

    def test_metadata_items_changed(self):
        with self.assertTraitChanges(self.data_source, 'metadata_changed', count=1):
            self.data_source.metadata['new_metadata'] = True