예제 #1
0
 def test_reversed(self):
     ary = array([5.0, 6.0, 7.0, 8.0, 9.0, 10.0])
     ds = ArrayDataSource(ary)
     r = DataRange1D(ds)
     mapper = LinearMapper(range=r, low_pos=100, high_pos=0)
     result = mapper.map_screen(ary)
     assert_equal(result , array([100, 80, 60, 40, 20, 0]))
     return
예제 #2
0
def create_timechart_container(project):
    """ create a vplotcontainer which connects all the inside plots to synchronize their index_range """

    # find index limits
    low = 1<<64
    high = 0
    for i in xrange(len(project.c_states)):
        if len(project.c_states[i].start_ts):
            low = min(low,project.c_states[i].start_ts[0])
            high = max(high,project.c_states[i].end_ts[-1])
        if len(project.p_states[i].start_ts):
            low = min(low,project.p_states[i].start_ts[0])
            high = max(high,project.p_states[i].start_ts[-1])
    for tc in project.processes:
        if len(tc.start_ts):
            low = min(low,tc.start_ts[0])
            high = max(high,tc.end_ts[-1])
    project.process_stats(low,high)
    if low > high:
        low=0
        high=1
    # we have the same x_mapper/range for each plots
    index_range = DataRange1D(low=low, high=high)
    index_mapper = LinearMapper(range=index_range,domain_limit=(low,high))
    value_range = DataRange1D(low=0, high=project.num_cpu*2+project.num_process)
    value_mapper = LinearMapper(range=value_range,domain_limit=(0,project.num_cpu*2+project.num_process))
    index = ArrayDataSource(array((low,high)), sort_order="ascending")
    plot = tcPlot(index=index,
                         proj=project, bgcolor="white",padding=(0,0,0,40),
                         use_backbuffer = True,
                         fill_padding = True,
                         value_mapper = value_mapper,
                         index_mapper=index_mapper,
                         line_color="black",
                         render_style='hold',
                         line_width=1)
    plot.lowest_i = low
    plot.highest_i = high
    project.on_trait_change(plot.invalidate, "plot_redraw")
    project.on_trait_change(plot.invalidate, "selected")
    max_process = 50
    if value_range.high>max_process:
        value_range.low = value_range.high-max_process
    # Attach some tools
    plot.tools.append(tools.myPanTool(plot,drag_button='left'))
    zoom = tools.myZoomTool(component=plot, tool_mode="range", always_on=True,axis="index",drag_button=None, zoom_to_mouse=True,x_max_zoom_factor=float("inf"),x_min_zoom_factor=float("-inf"))
    plot.tools.append(zoom)

    plot.range_selection = tools.myRangeSelection(plot,resize_margin=3)
    plot.tools.append(plot.range_selection)
    plot.overlays.append(RangeSelectionOverlay(component=plot,axis="index",use_backbuffer=True))

    axe = PlotAxis(orientation='bottom',title='time',mapper=index_mapper,component=plot)
    plot.underlays.append(axe)
    plot.options.connect(plot)
    plot.range_tools.connect(plot)
    return plot
예제 #3
0
 def _create_TracePlot_component(self):
     plot = DataView(border_visible=True)
     line = LinePlot(value=ArrayDataSource(self.Trace),
                     index=ArrayDataSource(numpy.arange(len(self.Trace))),
                     color='blue',
                     index_mapper=LinearMapper(range=plot.index_range),
                     value_mapper=LinearMapper(range=plot.value_range))
     plot.index_range.sources.append(line.index)
     plot.value_range.sources.append(line.value)
     plot.add(line)
     plot.index_axis.title = 'index'
     plot.value_axis.title = 'Fluorescence [ counts / s ]'
     plot.tools.append(PanTool(plot))
     plot.overlays.append(ZoomTool(plot))
     self.TraceLine = line
     return plot
    def test_reverse_construction(self):
        mapper = LinearMapper()
        r = DataRange1D()
        ds = ArrayDataSource()
        ary = array([1,2,3,4,5,6,7])

        mapper.range = r
        mapper.low_pos = 1.0
        mapper.high_pos = 7.0
        r.add(ds)
        ds.set_data(ary)

        self.assert_(r.low == 1)
        self.assert_(r.high == 7)
        screen_pts = mapper.map_screen(array([1,3,7]))
        self.assert_(tuple(screen_pts) == (1.0, 3.0, 7.0))
        return
예제 #5
0
 def _create_colorbar(self):
     cmap = self.plot.color_mapper
     self._colorbar = ColorBar(index_mapper=LinearMapper(range=cmap.range),
                               color_mapper=cmap,
                               orientation='v',
                               resizable='v',
                               width=30,
                               padding=30)
예제 #6
0
    def __init__(self, **kwargs):
        super(VariableMeshPannerView, self).__init__(**kwargs)
        # Create the plot
        self.add_trait("field", DelegatesTo("vm_plot"))

        plot = self.vm_plot.plot
        img_plot = self.vm_plot.img_plot

        if self.use_tools:
            plot.tools.append(PanTool(img_plot))
            zoom = ZoomTool(component=img_plot,
                            tool_mode="box",
                            always_on=False)
            plot.overlays.append(zoom)
            imgtool = ImageInspectorTool(img_plot)
            img_plot.tools.append(imgtool)
            overlay = ImageInspectorOverlay(component=img_plot,
                                            image_inspector=imgtool,
                                            bgcolor="white",
                                            border_visible=True)
            img_plot.overlays.append(overlay)

        image_value_range = DataRange1D(self.vm_plot.fid)
        cbar_index_mapper = LinearMapper(range=image_value_range)
        self.colorbar = ColorBar(index_mapper=cbar_index_mapper,
                                 plot=img_plot,
                                 padding_right=40,
                                 resizable='v',
                                 width=30)

        self.colorbar.tools.append(
            PanTool(self.colorbar, constrain_direction="y", constrain=True))
        zoom_overlay = ZoomTool(self.colorbar,
                                axis="index",
                                tool_mode="range",
                                always_on=True,
                                drag_button="right")
        self.colorbar.overlays.append(zoom_overlay)

        # create a range selection for the colorbar
        range_selection = RangeSelection(component=self.colorbar)
        self.colorbar.tools.append(range_selection)
        self.colorbar.overlays.append(
            RangeSelectionOverlay(component=self.colorbar,
                                  border_color="white",
                                  alpha=0.8,
                                  fill_color="lightgray"))

        # we also want to the range selection to inform the cmap plot of
        # the selection, so set that up as well
        range_selection.listeners.append(img_plot)

        self.full_container = HPlotContainer(padding=30)
        self.container = OverlayPlotContainer(padding=0)
        self.full_container.add(self.colorbar)
        self.full_container.add(self.container)
        self.container.add(self.vm_plot.plot)
예제 #7
0
 def _create_HistPlot_component(self):
     plot = DataView(border_visible=True)
     line = LinePlot(
         index=ArrayDataSource(self.HistogramBins),
         value=ArrayDataSource(self.HistogramN),
         color='blue',
         #fill_color='blue',
         index_mapper=LinearMapper(range=plot.index_range),
         value_mapper=LinearMapper(range=plot.value_range))
     plot.index_range.sources.append(line.index)
     plot.value_range.sources.append(line.value)
     plot.add(line)
     plot.index_axis.title = 'Fluorescence counts'
     plot.value_axis.title = 'number of occurences'
     plot.tools.append(PanTool(plot))
     plot.overlays.append(ZoomTool(plot))
     self.HistLine = line
     return plot
예제 #8
0
파일: ucc.py 프로젝트: hongliliu/hyperspy
 def draw_colorbar(self):
     scatplot = self.scatplot
     cmap_renderer = scatplot.plots["my_plot"][0]
     selection = ColormappedSelectionOverlay(cmap_renderer,
                                             fade_alpha=0.35,
                                             selection_type="range")
     cmap_renderer.overlays.append(selection)
     if self.thresh is not None:
         cmap_renderer.color_data.metadata['selections'] = self.thresh
         cmap_renderer.color_data.metadata_changed = {
             'selections': self.thresh
         }
     # Create the colorbar, handing in the appropriate range and colormap
     colormap = scatplot.color_mapper
     colorbar = ColorBar(
         index_mapper=LinearMapper(range=DataRange1D(low=0.0, high=1.0)),
         orientation='v',
         resizable='v',
         width=30,
         padding=20)
     colorbar_selection = RangeSelection(component=colorbar)
     colorbar.tools.append(colorbar_selection)
     ovr = colorbar.overlays.append(
         RangeSelectionOverlay(component=colorbar,
                               border_color="white",
                               alpha=0.8,
                               fill_color="lightgray",
                               metadata_name='selections'))
     #ipshell('colorbar, colorbar_selection and ovr available:')
     self.cbar_selection = colorbar_selection
     self.cmap_renderer = cmap_renderer
     colorbar.plot = cmap_renderer
     colorbar.padding_top = scatplot.padding_top
     colorbar.padding_bottom = scatplot.padding_bottom
     self.colorbar = colorbar
     return colorbar
    def _create_plot_component(self):

        # Create a plot data object and give it this data
        self.pd = ArrayPlotData()
        self.pd.set_data("imagedata", self.data[self.data_name])

        # Create the plot
        self.tplot = Plot(self.pd, default_origin="top left")
        self.tplot.x_axis.orientation = "top"
        self.tplot.img_plot(
            "imagedata",
            name="my_plot",
            #xbounds=(0,10),
            #ybounds=(0,10),
            colormap=jet)

        # Tweak some of the plot properties
        self.tplot.title = "Matrix"
        self.tplot.padding = 50

        # Right now, some of the tools are a little invasive, and we need the
        # actual CMapImage object to give to them
        self.my_plot = self.tplot.plots["my_plot"][0]

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

        # my custom tool to get the connection information
        self.custtool = CustomTool(self.tplot)
        self.tplot.tools.append(self.custtool)

        # Create the colorbar, handing in the appropriate range and colormap
        colormap = self.my_plot.color_mapper
        self.colorbar = ColorBar(
            index_mapper=LinearMapper(range=colormap.range),
            color_mapper=colormap,
            plot=self.my_plot,
            orientation='v',
            resizable='v',
            width=30,
            padding=20)

        self.colorbar.padding_top = self.tplot.padding_top
        self.colorbar.padding_bottom = self.tplot.padding_bottom

        # create a range selection for the colorbar
        self.range_selection = RangeSelection(component=self.colorbar)
        self.colorbar.tools.append(self.range_selection)
        self.colorbar.overlays.append(
            RangeSelectionOverlay(component=self.colorbar,
                                  border_color="white",
                                  alpha=0.8,
                                  fill_color="lightgray"))

        # we also want to the range selection to inform the cmap plot of
        # the selection, so set that up as well
        self.range_selection.listeners.append(self.my_plot)

        # Create a container to position the plot and the colorbar side-by-side
        container = HPlotContainer(use_backbuffer=True)
        container.add(self.tplot)
        container.add(self.colorbar)
        container.bgcolor = "white"

        return container
예제 #10
0
파일: fitgui.py 프로젝트: eteq/pymodelfit
    def __init__(self,xdata=None,ydata=None,weights=None,model=None,
                 include_models=None,exclude_models=None,fittype=None,**traits):
        """

        :param xdata: the first dimension of the data to be fit
        :type xdata: array-like
        :param ydata: the second dimension of the data to be fit
        :type ydata: array-like
        :param weights:
            The weights to apply to the data. Statistically interpreted as inverse
            errors (*not* inverse variance). May be any of the following forms:

            * None for equal weights
            * an array of points that must match `ydata`
            * a 2-sequence of arrays (xierr,yierr) such that xierr matches the
              `xdata` and yierr matches `ydata`
            * a function called as f(params) that returns an array of weights
              that match one of the above two conditions

        :param model: the initial model to use to fit this data
        :type model:
            None, string, or :class:`pymodelfit.core.FunctionModel1D`
            instance.
        :param include_models:
            With `exclude_models`, specifies which models should be available in
            the "new model" dialog (see `models.list_models` for syntax).
        :param exclude_models:
            With `include_models`, specifies which models should be available in
            the "new model" dialog (see `models.list_models` for syntax).
        :param fittype:
            The fitting technique for the initial fit (see
            :class:`pymodelfit.core.FunctionModel`).
        :type fittype: string

        kwargs are passed in as any additional traits to apply to the
        application.

        """

        self.modelpanel = View(Label('empty'),kind='subpanel',title='model editor')

        self.tmodel = TraitedModel(model)

        if model is not None and fittype is not None:
            self.tmodel.model.fittype = fittype

        if xdata is None or ydata is None:
            if not hasattr(self.tmodel.model,'data') or self.tmodel.model.data is None:
                raise ValueError('data not provided and no data in model')
            if xdata is None:
                xdata = self.tmodel.model.data[0]
            if ydata is None:
                ydata = self.tmodel.model.data[1]
            if weights is None:
                weights = self.tmodel.model.data[2]

        self.on_trait_change(self._paramsChanged,'tmodel.paramchange')

        self.modelselector = NewModelSelector(include_models,exclude_models)

        self.data = [xdata,ydata]


        if weights is None:
            self.weights = np.ones_like(xdata)
            self.weighttype = 'equal'
        else:
            self.weights = np.array(weights,copy=True)
            self.savews = True

        weights1d = self.weights
        while len(weights1d.shape)>1:
            weights1d = np.sum(weights1d**2,axis=0)

        pd = ArrayPlotData(xdata=self.data[0],ydata=self.data[1],weights=weights1d)
        self.plot = plot = Plot(pd,resizable='hv')

        self.scatter = plot.plot(('xdata','ydata','weights'),name='data',
                         color_mapper=_cmapblack if self.weights0rem else _cmap,
                         type='cmap_scatter', marker='circle')[0]

        self.errorplots = None

        if not isinstance(model,FunctionModel1D):
            self.fitmodel = True

        self.updatemodelplot = False #force plot update - generates xmod and ymod
        plot.plot(('xmod','ymod'),name='model',type='line',line_style='dash',color='black',line_width=2)
        del plot.x_mapper.range.sources[-1]  #remove the line plot from the x_mapper source so only the data is tied to the scaling

        self.on_trait_change(self._rangeChanged,'plot.index_mapper.range.updated')

        self.pantool = PanTool(plot,drag_button='left')
        plot.tools.append(self.pantool)
        self.zoomtool = ZoomTool(plot)
        self.zoomtool.prev_state_key = KeySpec('a')
        self.zoomtool.next_state_key = KeySpec('s')
        plot.overlays.append(self.zoomtool)

        self.scattertool = None
        self.scatter.overlays.append(ScatterInspectorOverlay(self.scatter,
                        hover_color = "black",
                        selection_color="black",
                        selection_outline_color="red",
                        selection_line_width=2))


        self.colorbar = colorbar = ColorBar(index_mapper=LinearMapper(range=plot.color_mapper.range),
                                            color_mapper=plot.color_mapper.range,
                                            plot=plot,
                                            orientation='v',
                                            resizable='v',
                                            width = 30,
                                            padding = 5)
        colorbar.padding_top = plot.padding_top
        colorbar.padding_bottom = plot.padding_bottom
        colorbar._axis.title = 'Weights'

        self.plotcontainer = container = HPlotContainer(use_backbuffer=True)
        container.add(plot)
        container.add(colorbar)

        super(FitGui,self).__init__(**traits)

        self.on_trait_change(self._scale_change,'plot.value_scale,plot.index_scale')

        if weights is not None and len(weights)==2:
            self.weightsChanged() #update error bars
예제 #11
0
    def setup_plots(self):
        '''
        
        Args: 
        Returns:
        Raises:
        '''
        ext = self.extension

        if ext == "S2":
            color = "green"
        else:
            color = "blue"

        self.create_plot("AAE " + ext, ylabel="[ ]", color=color)
        self.create_plot("ARE " + ext, ylabel="[ ]", color=color)
        self.create_plot("Jerk " + ext, ylabel="[m/s2/s]", color=color)
        self.create_plot("SI " + ext, ylabel="[ ]", color=color)
        self.create_plot("VI " + ext, ylabel="[ ]", color=color)

        p = self.plots["VI " + ext]

        null_ds = ArrayDataSource([])
        self.time_plot = LinePlot(
            index=self.time_src,
            value=null_ds,
            index_mapper=LinearMapper(range=DataRange1D(self.time_src)),
            value_mapper=LinearMapper(range=DataRange1D(null_ds)),
            color="black",
            border_visible=True,
            bgcolor="white",
            height=10,
            resizable="h",
            padding_top=50,
            padding_bottom=40,
            padding_left=50,
            padding_right=20)
        self.ticker = ScalesTickGenerator()
        self.x_axis = LabelAxis(self.time_plot,
                                orientation="bottom",
                                title="Time [sec]",
                                label_rotation=0)
        #self.x_axis = PlotAxis(self.time_plot, orientation="bottom", tick_generator = self.ticker, title="Time [sec]")
        self.time_plot.underlays.append(self.x_axis)
        self.container.add(self.time_plot)

        # Add a range overlay to the miniplot that is hooked up to the range
        # of the main price_plot
        range_tool = RangeSelection(self.time_plot)
        self.time_plot.tools.append(range_tool)
        range_overlay = RangeSelectionOverlay(self.time_plot,
                                              metadata_name="selections")
        self.time_plot.overlays.append(range_overlay)
        range_tool.on_trait_change(self._range_selection_handler, "selection")
        self.range_tool = range_tool

        p.plot_conactory.index_range.on_trait_change(self._plot_range_handler,
                                                     "updated")
        self.zoom_overlay = ZoomOverlay(source=self.time_plot,
                                        destination=p.plot_conactory)
        self.container.overlays.append(self.zoom_overlay)