Example #1
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
Example #2
0
 def change_color_map(self):
     try:
         cmap_func = getattr(cmaps, self.current_map)
         if self.reverse_map:
             cmap_func = reverse(cmap_func)
         self.imgplot.color_mapper = cmap_func(DataRange1D(self.imgplot.value))
         self.plot.request_redraw()
     except:
         print "Cannot set color map:%s" % self.current_map
Example #3
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)
def make_color_map():
    return ColorMapper.from_palette_array(palette11, range=DataRange1D(low=0, high=10))
Example #5
0
    def __init__(self):
        super(CyclesPlot, self).__init__()

        # Normally you'd pass in the data, but I'll hardwire things for this
        #    one-off plot.

        srecs = read_time_series_from_csv("./biz_cycles2.csv",
                                          date_col=0,
                                          date_format="%Y-%m-%d")

        dt = srecs["Date"]

        # Industrial production compared with trend (plotted on value axis)
        iprod_vs_trend = srecs["Metric 1"]

        # Industrial production change in last 6 Months (plotted on index axis)
        iprod_delta = srecs["Metric 2"]

        self._dates = dt
        self._series1 = self._selected_s1 = iprod_delta
        self._series2 = self._selected_s2 = iprod_vs_trend

        end_x = np.array([self._selected_s1[-1]])
        end_y = np.array([self._selected_s2[-1]])

        plotdata = ArrayPlotData(x=self._series1,
                                 y=self._series2,
                                 dates=self._dates,
                                 selected_x=self._selected_s1,
                                 selected_y=self._selected_s2,
                                 endpoint_x=end_x,
                                 endpoint_y=end_y)

        cycles = Plot(plotdata, padding=20)

        cycles.plot(("x", "y"), type="line", color=(.2, .4, .5, .4))

        cycles.plot(("selected_x", "selected_y"),
                    type="line",
                    marker="circle",
                    line_width=3,
                    color=(.2, .4, .5, .9))

        cycles.plot(("endpoint_x", "endpoint_y"),
                    type="scatter",
                    marker_size=4,
                    marker="circle",
                    color=(.2, .4, .5, .2),
                    outline_color=(.2, .4, .5, .6))

        cycles.index_range = DataRange1D(low_setting=80., high_setting=120.)

        cycles.value_range = DataRange1D(low_setting=80., high_setting=120.)

        # dig down to use actual Plot object
        cyc_plot = cycles.components[0]

        # Add the labels in the quadrants
        cyc_plot.overlays.append(
            PlotLabel("\nSlowdown" + 40 * " " + "Expansion",
                      component=cyc_plot,
                      font="swiss 24",
                      color=(.2, .4, .5, .6),
                      overlay_position="inside top"))

        cyc_plot.overlays.append(
            PlotLabel("Downturn" + 40 * " " + "Recovery\n ",
                      component=cyc_plot,
                      font="swiss 24",
                      color=(.2, .4, .5, .6),
                      overlay_position="inside bottom"))

        timeline = Plot(plotdata, resizable='h', height=50, padding=20)
        timeline.plot(("dates", "x"),
                      type="line",
                      color=(.2, .4, .5, .8),
                      name='x')
        timeline.plot(("dates", "y"),
                      type="line",
                      color=(.5, .4, .2, .8),
                      name='y')

        # Snap on the tools
        zoomer = ZoomTool(timeline,
                          drag_button="right",
                          always_on=True,
                          tool_mode="range",
                          axis="index",
                          max_zoom_out_factor=1.1)

        panner = PanTool(timeline, constrain=True, constrain_direction="x")

        # dig down to get Plot component I want
        x_plt = timeline.plots['x'][0]

        range_selection = RangeSelection(x_plt, left_button_selects=True)
        range_selection.on_trait_change(self.update_interval, 'selection')

        x_plt.tools.append(range_selection)
        x_plt.overlays.append(RangeSelectionOverlay(x_plt))

        # Set the plot's bottom axis to use the Scales ticking system
        scale_sys = CalendarScaleSystem(
            fill_ratio=0.4,
            default_numlabels=5,
            default_numticks=10,
        )
        tick_gen = ScalesTickGenerator(scale=scale_sys)

        bottom_axis = ScalesPlotAxis(timeline,
                                     orientation="bottom",
                                     tick_generator=tick_gen)

        # Hack to remove default axis - FIXME: how do I *replace* an axis?
        del (timeline.underlays[-2])

        timeline.overlays.append(bottom_axis)

        container = GridContainer(padding=20,
                                  fill_padding=True,
                                  bgcolor="lightgray",
                                  use_backbuffer=True,
                                  shape=(2, 1),
                                  spacing=(30, 30))

        # add a central "x" and "y" axis

        x_line = LineInspector(cyc_plot,
                               is_listener=True,
                               color="gray",
                               width=2)
        y_line = LineInspector(cyc_plot,
                               is_listener=True,
                               color="gray",
                               width=2,
                               axis="value")

        cyc_plot.overlays.append(x_line)
        cyc_plot.overlays.append(y_line)

        cyc_plot.index.metadata["selections"] = 100.0
        cyc_plot.value.metadata["selections"] = 100.0

        container.add(cycles)
        container.add(timeline)

        container.title = "Business Cycles"

        self.plot = container
Example #6
0
 def _update_model(self, cmap):
     range = DataRange1D(low=numpy.amin(self.model.dose),
                         high=numpy.amax(self.model.dose))
     self.colormap = cmap(range)
     self.colorcube = (self.colormap.map_screen(self.model.dose) *
                       255).astype(numpy.uint8)
Example #7
0
    def _init_components(self):
        # Since this is called after the HasTraits constructor, we have to make
        # sure that we don't blow away any components that the caller may have
        # already set.

        if not self.freq_range:
            self.freq_range = DataRange1D()

        if not self.range2d:
            self.range2d = DataRange2D()

        if not self.index_mapper:
            self.index_mapper = SmithMapper(range=self.range2d.x_range)

        if not self.value_mapper:
            self.value_mapper = SmithMapper(range=self.range2d.y_range)

        # make sure the grid and bgcolor are not the same color

        grid_color = 'lightgray'
        #        if color_table[self.bgcolor] == color_table[grid_color]:
        #            grid_color = 'white'

        if not self.x_grid:
            self.x_grid = PlotGrid(mapper=self.x_mapper,
                                   orientation="vertical",
                                   line_color=grid_color,
                                   line_style="dot",
                                   component=self)
        if not self.y_grid:
            self.y_grid = PlotGrid(mapper=self.y_mapper,
                                   orientation="horizontal",
                                   line_color=grid_color,
                                   line_style="dot",
                                   component=self)

        if not self.x_axis:
            self.x_axis = PlotAxis(mapper=self.x_mapper,
                                   orientation="bottom",
                                   component=self)

        if not self.y_axis:
            self.y_axis = PlotAxis(mapper=self.y_mapper,
                                   orientation="left",
                                   component=self)

        # Smith axes and grids
        if not self.resistance_grid:
            self.resistance_grid = SmithResistanceGrid(x_mapper=self.x_mapper,
                                                       y_mapper=self.y_mapper,
                                                       component=self)
            self.overlays.append(self.resistance_grid)

        if not self.reactance_grid:
            self.reactance_grid = SmithReactanceGrid(x_mapper=self.x_mapper,
                                                     y_mapper=self.y_mapper,
                                                     component=self)
            self.overlays.append(self.reactance_grid)

        if not self.zero_resistance_circle:
            self.zero_resistance_circle = SmithCircle(x_mapper=self.x_mapper,
                                                      y_mapper=self.y_mapper,
                                                      component=self)
            self.overlays.append(self.zero_resistance_circle)
Example #8
0
    def _create_plot_window(self):
        # Create the model
        min_value = 350
        max_value = self.max_data
        image_value_range = DataRange1D(low=min_value, high=max_value)
        self.cmap = jet(range=image_value_range)
        self._update_model()
        datacube = self.colorcube

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        self.SetSizer(self.sizer)
        self.Centre()
        self.Show(True)
Example #9
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)