Esempio n. 1
0
    def __init__(self, **traits):
        super(CameraImage, self).__init__(**traits)
        self._dims = (200, 320)
        self.data_store = ArrayPlotData(image=self.data)
        self._hud = dict()
        self.plot = Plot(self.data_store)
        # Draw the image
        renderers = self.plot.img_plot('image', name='camera_image',
            colormap=fix(gray, (0, 255)))
        self._image = renderers[0]
        self.plot.aspect_ratio = float(self._dims[1]) / self._dims[0]

        self.hud_overlay = PlotLabel(text='', component=self.plot,
            hjustify='left', overlay_position='inside bottom',
            color='white')
        self.plot.overlays.append(self.hud_overlay)
Esempio n. 2
0
    def __init__(self, **traits):
        super(CameraImage, self).__init__(**traits)
        self._dims = (200, 320)
        self.data_store = ArrayPlotData(image=self.data)
        self._hud = dict()
        self.plot = Plot(self.data_store)
        # Draw the image
        renderers = self.plot.img_plot('image',
                                       name='camera_image',
                                       colormap=fix(gray, (0, 255)))
        self._image = renderers[0]
        self.plot.aspect_ratio = float(self._dims[1]) / self._dims[0]

        self.hud_overlay = PlotLabel(text='',
                                     component=self.plot,
                                     hjustify='left',
                                     overlay_position='inside bottom',
                                     color='white')
        self.plot.overlays.append(self.hud_overlay)
  def _modify_colormap(self):

    #myTP.color_mapper.range.low_setting = 0
    #myTP.color_mapper.range.high_setting = 1000

    # pick out the color map function
    myColorMapperFn = default_colormaps.color_map_name_dict[self.colormapNameTE]

    # reverse the colormap, if req'd
    if self.reversedColormapTB:
      myColorMapperFn = default_colormaps.reverse( myColorMapperFn )

    ## TODO adjust for too low, too high, end cases

    myColorMapperFn = default_colormaps.fix(
        myColorMapperFn,
        (self.colormapLowTR, self.colormapHighTR)
    )
    myColorMapper = myColorMapperFn( self.myDR1D )
    self.myTP.color_mapper = myColorMapper
    self.myTP.request_redraw()
Esempio n. 4
0
    def _plot(self, x, y, z, scale):
        pd = ArrayPlotData()
        pd.set_data("imagedata", z)
        plot = Plot(pd, padding_left=60, fill_padding=True)
        plot.bgcolor = "white"
        cmap = fix(jet, (0, z.max()))
        origin = "bottom left"  # origin = 'top left' # to flip y-axis
        plot.img_plot(
            "imagedata",
            name="surface2d",
            xbounds=(np.min(x), np.max(x)),
            ybounds=(1.0, y[-1, -1]),
            colormap=cmap,
            hide_grids=True,
            interpolation="nearest",
            origin=origin,
        )
        plot.default_origin = origin
        plot.x_axis.title = u"Angle (2\u0398)"

        tick_font = settings.tick_font
        plot.x_axis.title_font = settings.axis_title_font
        plot.y_axis.title_font = settings.axis_title_font
        plot.x_axis.tick_label_font = tick_font
        plot.y_axis.tick_label_font = tick_font
        plot.y_axis.title = "Dataset"
        plot.y_axis.tick_interval = 1.0
        actual_plot = plot.plots["surface2d"][0]

        self.plot_zoom_tool = ClickUndoZoomTool(
            plot,
            tool_mode="box",
            always_on=True,
            pointer="cross",
            drag_button=settings.zoom_button,
            undo_button=settings.undo_button,
            x_min_zoom_factor=-np.inf,
            y_min_zoom_factor=-np.inf,
        )
        plot.overlays.append(self.plot_zoom_tool)
        plot.tools.append(TraitsTool(plot))

        # Add a color bar
        colormap = actual_plot.color_mapper
        colorbar = ColorBar(
            index_mapper=LinearMapper(range=colormap.range),
            color_mapper=colormap,
            plot=actual_plot,
            orientation="v",
            resizable="v",
            width=30,
            padding=40,
            padding_top=50,
            fill_padding=True,
        )

        colorbar._axis.title_font = settings.axis_title_font
        colorbar._axis.tick_label_font = settings.tick_font
        # Add pan and zoom tools to the colorbar
        self.colorbar_zoom_tool = ClickUndoZoomTool(
            colorbar,
            axis="index",
            tool_mode="range",
            always_on=True,
            drag_button=settings.zoom_button,
            undo_button=settings.undo_button,
        )
        pan_tool = PanToolWithHistory(
            colorbar,
            history_tool=self.colorbar_zoom_tool,
            constrain_direction="y",
            constrain=True,
            drag_button=settings.pan_button,
        )
        colorbar.tools.append(pan_tool)
        colorbar.overlays.append(self.colorbar_zoom_tool)

        # Add a label to the top of the color bar
        colorbar_label = PlotLabel(
            u"Intensity\n{:^9}".format("(" + get_value_scale_label(scale) + ")"),
            component=colorbar,
            font=settings.axis_title_font,
        )
        colorbar.overlays.append(colorbar_label)
        colorbar.tools.append(TraitsTool(colorbar))

        # Add the plot and colorbar side-by-side
        container = HPlotContainer(use_backbuffer=True)
        container.add(plot)
        container.add(colorbar)
        return container
Esempio n. 5
0
    def _plot(self, x, y, z, scale):
        pd = ArrayPlotData()
     #   pd.set_data("imagedata", z)
        plot = Plot(pd, padding_left=60, fill_padding=True)
        plot.bgcolor = 'white'
        cmap = fix(jet, (0, z.max()))
        plot.default_origin = 'bottom left' # origin = 'top left' # to flip y-axis

        fid = FunctionImageData(func=self._prepare_data_for_window, data_range=plot.range2d)
        pd.set_data("imagedata", fid)

        self.img_plot = plot.img_plot("imagedata", name="surface2d",
                      xbounds=(np.min(x), np.max(x)),
                      ybounds=(1.0, y[-1,-1]),
                      colormap=cmap, hide_grids=True, interpolation='nearest'
                     # origin=origin,
                      )[0]
        #plot.default_origin = origin
        
        plot.x_axis = MyPlotAxis(component=plot, orientation='bottom')
        plot.y_axis = MyPlotAxis(component=plot, orientation='left')
        plot.x_axis.title = u'Angle (2\u0398)'

        tick_font = settings.tick_font
        plot.x_axis.title_font = settings.axis_title_font
        plot.y_axis.title_font = settings.axis_title_font
        plot.x_axis.tick_label_font = tick_font
        plot.y_axis.tick_label_font = tick_font
        plot.y_axis.title = "Dataset"
        # if <10 datasets we want to reduce down the tickmarks to multiples
        if len(y)<10:
            plot.y_axis.tick_interval = 1.0
        else:
            plot.y_axis.tick_interval = len(y)/10
        actual_plot = plot.plots["surface2d"][0]

        self.plot_zoom_tool = ClickUndoZoomTool(
            plot, always_on=True, pointer="cross",
            tool_mode="range",
            axis="index",
            drag_button=settings.zoom_button,
            undo_button=settings.undo_button,
            x_min_zoom_factor=-np.inf, y_min_zoom_factor=-np.inf,
        )
        plot.overlays.append(self.plot_zoom_tool)
        plot.tools.append(TraitsTool(plot))

        # Add a color bar
        colormap = actual_plot.color_mapper
        colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                        color_mapper=colormap,
                        plot=actual_plot,
                        orientation='v',
                        resizable='v',
                        width=30,
                        padding=40,
                        padding_top=50,
                        fill_padding=True)

        colorbar._axis.title_font = settings.axis_title_font
        colorbar._axis.tick_label_font = settings.tick_font


        # Add pan and zoom tools to the colorbar
        self.colorbar_zoom_tool = ClickUndoZoomTool(colorbar,
                                                    axis="index",
                                                    tool_mode="range",
                                                    always_on=True,
                                                    drag_button=settings.zoom_button,
                                                   undo_button=settings.undo_button)
        pan_tool = PanToolWithHistory(colorbar,
                                      history_tool=self.colorbar_zoom_tool,
                                      constrain_direction="y", constrain=True,
                                      drag_button=settings.pan_button)
        colorbar.tools.append(pan_tool)
        colorbar.overlays.append(self.colorbar_zoom_tool)

        # Add a label to the top of the color bar
        colorbar_label = PlotLabel(
            u'Intensity\n{:^9}'.format('(' + get_value_scale_label(scale) + ')'),
            component=colorbar,
            font=settings.axis_title_font,
        )
        colorbar.overlays.append(colorbar_label)
        colorbar.tools.append(TraitsTool(colorbar))

        # Add the plot and colorbar side-by-side
        container = HPlotContainer(use_backbuffer=True)
        container.add(plot)
        container.add(colorbar)
        self.twod_plot = plot 
        return container
Esempio n. 6
0
    def _plot(self, x, y, z, scale):
        pd = ArrayPlotData()
        pd.set_data("imagedata", z)
        plot = Plot(pd, padding_left=60, fill_padding=True)
        plot.bgcolor = 'white'
        cmap = fix(jet, (0, z.max()))
        origin = 'bottom left' # origin = 'top left' # to flip y-axis
        plot.img_plot("imagedata", name="surface2d",
                      xbounds=(np.min(x), np.max(x)),
                      ybounds=(1.0, y[-1,-1]),
                      colormap=cmap, hide_grids=True, interpolation='nearest',
                      origin=origin,
                      )
        plot.default_origin = origin
        plot.x_axis.title = u'Angle (2\u0398)'

        tick_font = settings.tick_font
        plot.x_axis.title_font = settings.axis_title_font
        plot.y_axis.title_font = settings.axis_title_font
        plot.x_axis.tick_label_font = tick_font
        plot.y_axis.tick_label_font = tick_font
        plot.y_axis.title = "Dataset"
        plot.y_axis.tick_interval = 1.0
        actual_plot = plot.plots["surface2d"][0]

        self.plot_zoom_tool = ClickUndoZoomTool(
            plot, tool_mode="box", always_on=True, pointer="cross",
            drag_button=settings.zoom_button,
            undo_button=settings.undo_button,
            x_min_zoom_factor=-np.inf, y_min_zoom_factor=-np.inf,
        )
        plot.overlays.append(self.plot_zoom_tool)
        plot.tools.append(TraitsTool(plot))

        # Add a color bar
        colormap = actual_plot.color_mapper
        colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                        color_mapper=colormap,
                        plot=actual_plot,
                        orientation='v',
                        resizable='v',
                        width=30,
                        padding=40,
                        padding_top=50,
                        fill_padding=True)

        colorbar._axis.title_font = settings.axis_title_font
        colorbar._axis.tick_label_font = settings.tick_font
        # Add pan and zoom tools to the colorbar
        self.colorbar_zoom_tool = ClickUndoZoomTool(colorbar,
                                                    axis="index",
                                                    tool_mode="range",
                                                    always_on=True,
                                                    drag_button=settings.zoom_button,
                                                    undo_button=settings.undo_button)
        pan_tool = PanToolWithHistory(colorbar,
                                      history_tool=self.colorbar_zoom_tool,
                                      constrain_direction="y", constrain=True,
                                      drag_button=settings.pan_button)
        colorbar.tools.append(pan_tool)
        colorbar.overlays.append(self.colorbar_zoom_tool)

        # Add a label to the top of the color bar
        colorbar_label = PlotLabel(
            u'Intensity\n{:^9}'.format('(' + get_value_scale_label(scale) + ')'),
            component=colorbar,
            font=settings.axis_title_font,
        )
        colorbar.overlays.append(colorbar_label)
        colorbar.tools.append(TraitsTool(colorbar))

        # Add the plot and colorbar side-by-side
        container = HPlotContainer(use_backbuffer=True)
        container.add(plot)
        container.add(colorbar)
        return container
Esempio n. 7
0
 def _get_cmap_function(self):
     return fix(
         gray if self.cmap is None else self.cmap,
         (0, 65535 if self.data.dtype == N.uint16 else 255))
Esempio n. 8
0
 def _get_cmap_function(self):
     return fix(gray if self.cmap is None else self.cmap,
                (0, 65535 if self.data.dtype == N.uint16 else 255))