Esempio n. 1
0
def _create_plot_component():

    container = OverlayPlotContainer(padding = 50, fill_padding = True,
                                     bgcolor = "lightgray", use_backbuffer=True)

    # Create the initial X-series of data
    numpoints = 100
    low = -5
    high = 15.0
    x = arange(low, high+0.001, (high-low)/numpoints)

    # Plot some bessel functions
    plots = {}
    broadcaster = BroadcasterTool()
    for i in range(4):
        y = jn(i, x)
        plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[i]), width=2.0)
        plot.index.sort_order = "ascending"
        plot.bgcolor = "white"
        plot.border_visible = True
        if i == 0:
            add_default_grids(plot)
            add_default_axes(plot)

        # Create a pan tool and give it a reference to the plot it should
        # manipulate, but don't attach it to the plot.  Instead, attach it to
        # the broadcaster.
        pan = PanTool(plot)
        broadcaster.tools.append(pan)

        container.add(plot)
        plots["Bessel j_%d"%i] = plot

    # Add an axis on the right-hand side that corresponds to the second plot.
    # Note that it uses plot.value_mapper instead of plot0.value_mapper.
    plot1 = plots["Bessel j_1"]
    axis = PlotAxis(plot1, orientation="right")
    plot1.underlays.append(axis)

    # Add the broadcast tool to the container, instead of to an
    # individual plot
    container.tools.append(broadcaster)

    legend = Legend(component=container, padding=10, align="ur")
    legend.tools.append(LegendTool(legend, drag_button="right"))
    container.overlays.append(legend)

    # Set the list of plots on the legend
    legend.plots = plots

    # Add the title at the top
    container.overlays.append(PlotLabel("Bessel functions",
                              component=container,
                              font = "swiss 16",
                              overlay_position="top"))

    # Add the traits inspector tool to the container
    container.tools.append(TraitsTool(container))

    return container
Esempio n. 2
0
 def _tt1_fired(self):
     self.addele()
     self.plotdata.del_data("x")
     self.plotdata.del_data("y")
     self.plotdata.del_data("xrt")
     self.plotdata.del_data("xx")
     self.plotdata.del_data("yy")
     self.plotdata.del_data("tt")
     self.plotdata.set_data("x",self.x)
     self.plotdata.set_data("y",self.y)
     self.plotdata.set_data("xrt",self.xrt)
     self.plotdata.set_data("xx",xx)
     self.plotdata.set_data("yy",yy)
     self.plotdata.set_data("tt",self.ttt)
     plot1 =  Plot(self.plotdata)
     plot1.plot(("x", "y"),type="line",color="blue",name='1')
     plot1.plot(("x", "y"),type="scatter",color="blue", marker = 'circle', marker_size = 2,name='1')
     plot1.plot(("x", "xrt"),type="line",color="red",name='2')
     plot1.plot(("x", "xrt"),type="scatter",color="red", marker = 'circle', marker_size = 2,name='2')
     plot2 = Plot(self.plotdata)
     plot2.plot(("xx", "yy"),type="line",color="blue")
     plot2.plot(("xx","yy"),type="scatter",color="blue")
     plot3 = Plot(self.plotdata)
     plot3.plot(("x", "tt"),type="line",color="blue")
     plot3.plot(("x","tt"),type="scatter",color="blue")
     container = HPlotContainer(plot1,plot2,plot3)        
     self.plot= container
     
     legend= Legend(padding=10, align="ur")
     legend.plots = plot1.plots
     plot1.overlays.append(legend)
Esempio n. 3
0
    def _create_plot_component_vertical(signals=Array, use_downsampling=False):

        # container = HPlotContainer(resizable = "hv", bgcolor="lightgray",
        #                            fill_padding=True, padding = 10)
        container = VPlotContainer(resizable="hv",
                                   bgcolor="lightgray",
                                   fill_padding=True,
                                   padding=50)

        nSignal, nSample = np.shape(signals)
        time = arange(nSample)

        value_range = None
        plots = {}
        for i in range(nSignal):

            plot = create_line_plot(
                (time, signals[i]),
                color=tuple(COLOR_PALETTE[i % len(COLOR_PALETTE)]),
                width=1.0,
                # orientation="v")
                orientation="h")
            plot.origin_axis_visible = True
            # plot.origin = "top left"
            plot.padding_left = 10
            plot.padding_right = 10
            plot.border_visible = False
            plot.bgcolor = "white"
            if value_range is None:
                value_range = plot.value_mapper.range
            else:
                plot.value_range = value_range
                value_range.add(plot.value)

            container.add(plot)
            plots["Corr fun %d" % i] = plot

        # Add a legend in the upper right corner, and make it relocatable
        legend = Legend(component=plot, padding=10, align="ur")
        legend.tools.append(LegendTool(legend, drag_button="right"))
        plot.overlays.append(legend)
        legend.plots = plots
        # container.padding_top = 50
        container.overlays.append(
            PlotLabel("Correlation function",
                      component=container,
                      font="swiss 16",
                      overlay_position="top"))
        # selection_overlay = RangeSelectionOverlay(component=plot)
        # plot.tools.append(RangeSelection(plot))
        zoom = ZoomTool(plot, tool_mode="box", always_on=False)
        # plot.overlays.append(selection_overlay)
        plot.overlays.append(zoom)
        return container
Esempio n. 4
0
	def _select_angle_names_changed(self):
		for _myos_in in range(2):
			self.stream_Angle[_myos_in] = np.zeros(self.Angle_length)
		self.plot_Angle = Plot(self.data_Angle)
		self.plot_Angle.auto_colors = ['blue','red']
		for _pic in self.select_angle_names:
			self.plot_Angle.plot(('x',)+(_pic,),name = _pic,color = 'auto')
		self.plot_Angle.title='Multiple Angle'
		_legend = Legend(padding=10,align="ur")
		_legend.plots = self.plot_Angle.plots
		self.plot_Angle.overlays.append(_legend)
Esempio n. 5
0
def gen_line_plot(series_one, series_two, y_axis_name=''):
    """
    Parameters
    ----------
    series_one : nd array
    series_two : nd array

    """

    size = min(series_one.shape[0],
        series_two.shape[0])

    idx = ArrayDataSource(arange(size))

    series_one_data = ArrayDataSource(series_one[:size])
    series_two_data = ArrayDataSource(series_two[:size])

    y_range = DataRange1D(series_one_data)
    y_range.tight_bounds = False
    y_range.margin = 50
    x_mapper = LinearMapper(range=DataRange1D(idx))
    y_mapper = LinearMapper(range=y_range)

    series_one_plot = LinePlot(index=idx,
        value=series_one_data, index_mapper=x_mapper,
        value_mapper=y_mapper, color='blue')

    series_two_plot = LinePlot(index=idx,
        value=series_two_data, index_mapper=x_mapper,
        value_mapper=y_mapper, color='red')

    container = OverlayPlotContainer(bgcolor='white',
        padding=25, fill_padding=False, border_visible=True)

    y_axis = PlotAxis(mapper=y_mapper, component=container,
        orientation='left')

    x_axis = PlotAxis(mapper=x_mapper, component=container,
        orientation='bottom')

    x_axis.title = 'Time'
    y_axis.title = y_axis_name

    legend = Legend(component=container, padding=10, align='ur')
    legend.plots = {
        'Predicted': series_one_plot,
        'Actual': series_two_plot,
    }

    container.add(series_one_plot)
    container.add(series_two_plot)
    container.overlays.append(y_axis)
    container.overlays.append(legend)
    return container
Esempio n. 6
0
 def _select_angle_names_changed(self):
     for _myos_in in range(2):
         self.stream_Angle[_myos_in] = deque(np.zeros(self.Angle_length))
     self.plot_Angle = Plot(self.data_Angle)
     self.plot_Angle.auto_colors = ['blue', 'red']
     for _pic in self.select_angle_names:
         self.plot_Angle.plot(('x', ) + (_pic, ), name=_pic, color='auto')
     self.plot_Angle.title = 'Multiple Angle'
     _legend = Legend(padding=10, align="ur")
     _legend.plots = self.plot_Angle.plots
     self.plot_Angle.overlays.append(_legend)
Esempio n. 7
0
	def _select_emg_names_changed(self):
		for chanel in range(8):
			self.stream_emg[chanel] = np.zeros(self.sEMG_length)
		self.plot_EMG = Plot(self.data_EMG)
		self.plot_EMG.auto_colors = ['green', 'lightgreen','blue', 
			'lightblue', 'red', 'pink', 'darkgray', 'silver']
		for pic in self.select_emg_names:
			self.plot_EMG.plot(('x',)+(pic,),name = pic,color = 'auto')
		self.plot_EMG.title='Multiple sEMG'
		legend = Legend(padding=10,align="ur")
		legend.plots = self.plot_EMG.plots
		self.plot_EMG.overlays.append(legend) 		
Esempio n. 8
0
 def _create_plot_component_vertical(signals=Array,
                                     use_downsampling=False):
 
     # container = HPlotContainer(resizable = "hv", bgcolor="lightgray",
     #                            fill_padding=True, padding = 10)
     container = VPlotContainer(resizable="hv", bgcolor="lightgray",
                                fill_padding=True, padding=50)
 
     nSignal, nSample = np.shape(signals)
     time = arange(nSample)
 
     value_range = None
     plots = {}
     for i in range(nSignal):
 
         plot = create_line_plot((time, signals[i]),
                         color=tuple(COLOR_PALETTE[i % len(COLOR_PALETTE)]),
                         width=1.0,
                         # orientation="v")
                         orientation="h")
         plot.origin_axis_visible = True
         # plot.origin = "top left"
         plot.padding_left = 10
         plot.padding_right = 10
         plot.border_visible = False
         plot.bgcolor = "white"
         if value_range is None:
             value_range = plot.value_mapper.range
         else:
             plot.value_range = value_range
             value_range.add(plot.value)
 
         container.add(plot)
         plots["Corr fun %d" % i] = plot
 
     # Add a legend in the upper right corner, and make it relocatable
     legend = Legend(component=plot, padding=10, align="ur")
     legend.tools.append(LegendTool(legend, drag_button="right"))
     plot.overlays.append(legend)
     legend.plots = plots
     # container.padding_top = 50
     container.overlays.append(PlotLabel("Correlation function",
                                         component=container,
                                         font="swiss 16",
                                         overlay_position="top"))
     # selection_overlay = RangeSelectionOverlay(component=plot)
     # plot.tools.append(RangeSelection(plot))
     zoom = ZoomTool(plot, tool_mode="box", always_on=False)
     # plot.overlays.append(selection_overlay)
     plot.overlays.append(zoom)
     return container
Esempio n. 9
0
 def _select_emg_names_changed(self):
     for chanel in range(8):
         self.stream_emg[chanel] = deque(np.zeros(self.sEMG_length))
     self.plot_EMG = Plot(self.data_EMG)
     self.plot_EMG.auto_colors = [
         'green', 'lightgreen', 'blue', 'lightblue', 'red', 'pink',
         'darkgray', 'silver'
     ]
     for pic in self.select_emg_names:
         self.plot_EMG.plot(('x', ) + (pic, ), name=pic, color='auto')
     self.plot_EMG.title = 'Multiple sEMG'
     legend = Legend(padding=10, align="ur")
     legend.plots = self.plot_EMG.plots
     self.plot_EMG.overlays.append(legend)
Esempio n. 10
0
    def _plots_default(self):
        plotdata = self.get_data_sets()
        plots = Plot(plotdata)
        plotsDict = {}

        # plot background sonar image and impound lines
        xbounds = self.model.survey_rng_m
        ybounds = self.model.depth_m
        plots.img_plot("sonarimg", colormap=jet,
                        xbounds=xbounds, ybounds=ybounds)
        ip = plots.plot(('impound1_X','impound1_Y'), type='line', marker='square')
        plotsDict['Impoundment line'] = ip
        plots.x_axis.title = 'Distance along survey line (m)'
        plots.y_axis.title = 'Depth (m)'

        # add core samples as scatter with separate y-axis
        corex = plotdata.get_data('coreX')
        corey = plotdata.get_data('coreY')
        scatter = create_scatter_plot((corex,corey), marker='diamond',
                                       color='red' )
        scatter.index_range = plots.index_range
        axis = PlotAxis(scatter, orientation='right')
        axis.title = 'Core sample dist from survey line (m)'
        scatter.underlays.append(axis)
        plots.add(scatter)

        # create vertical line for indicating selected core sample position
        vals1 = [0 for x in corey]
        vline = create_line_plot((corey,vals1), color='blue', orientation='v')
        vline.value_range = scatter.index_range
        plots.add(vline)

        # Add Legend
        legend = Legend(component=plots, padding=10, align="ur")
        legend.tools.append(LegendTool(legend, drag_button="left"))
        legend.plots = plotsDict
        plots.overlays.append(legend)

        # Add tools
        scatter.tools.append(PickTool(scatter))
        plots.tools.append(TraceTool(plots))
        plots.tools.append(PanTool(plots))
        plots.tools.append(ZoomTool(plots))

        return plots
Esempio n. 11
0
 def __init__(self):
     super(calc, self).__init__()
     self.addele()
     self.plotdata = ArrayPlotData(x = self.x, y = self.y, xrt=self.xrt, xx=xx, yy=yy,tt=self.ttt)
     plot1 =  Plot(self.plotdata)
     plot1.plot(("x", "y"),type="line",color="blue",name='1')
     plot1.plot(("x", "y"),type="scatter",color="blue", marker = 'circle', marker_size = 2,name='1')
     plot1.plot(("x", "xrt"),type="line",color="red",name='2')
     plot1.plot(("x", "xrt"),type="scatter",color="red", marker = 'circle', marker_size = 2,name='2')
     plot2 = Plot(self.plotdata)
     plot2.plot(("xx", "yy"),type="line",color="blue")
     plot2.plot(("xx","yy"),type="scatter",color="blue")
     plot3 = Plot(self.plotdata)
     plot3.plot(("x", "tt"),type="line",color="blue")
     plot3.plot(("x","tt"),type="scatter",color="blue")
     container = HPlotContainer(plot1,plot2,plot3)        
     self.plot= container
     
     legend= Legend(padding=10, align="ur")
     legend.plots = plot1.plots
     plot1.overlays.append(legend)
Esempio n. 12
0
 def plotParsedData(self):
   self.plotdata = ArrayPlotData(x = self.data["ts"], wrdlt = self.data["wrdlt"])
   self.plotA = Plot(self.plotdata)
   self.plotAA = self.plotA.plot(("x", "wrdlt"), type="line", color=(0,0.99,0), spacing=0, padding=0, alpha=0.7, use_downsampling=True, line_style = "dash") #render_style='connectedhold'
   # cache default axes limits
   self.Arng = [ self.plotA.x_axis.mapper.range.low, self.plotA.x_axis.mapper.range.high,
     self.plotA.y_axis.mapper.range.low, self.plotA.y_axis.mapper.range.high]
   self.plotA.x_axis.tick_label_position="inside"
   self.plotA.y_axis.tick_label_position="inside"
   self.container = VPlotContainer(self.plotA, spacing=0, padding=0, bgcolor="lightgray", use_backbuffer = True)
   self.plotA.spacing = 0 # set child padding after container set!
   self.plotA.padding = 0
   self.plotA.tools.append(PanTool(self.plotA))
   self.plotA.tools.append(ZoomTool(self.plotA))
   self.plotA.overlays.append(BetterSelectingZoom(self.plotA))
   legend = Legend(component=self.plotA, padding=1, align="ur")
   # to hide plots, make LegendHighlighter scale line to 0 on selection
   legend.tools.append(LegendHighlighter(legend, line_scale=0.0))
   self.plots = {}
   self.plots["wrdlt"] = self.plotAA
   legend.plots = self.plots
   self.plotA.overlays.append(legend)
Esempio n. 13
0
def _create_plot_component():
    container = OverlayPlotContainer(padding = 50, fill_padding = True,
                                     bgcolor = "lightgray", use_backbuffer=True)

    # Create the initial X-series of data
    numpoints = 100
    low = -5
    high = 15.0
    x = linspace(low, high, numpoints)

    now = time()
    timex = linspace(now, now+7*24*3600, numpoints)

    # Plot some bessel functions
    value_mapper = None
    index_mapper = None
    plots = {}
    for i in range(10):
        y = jn(i, x)
        if i%2 == 1:
            plot = create_line_plot((timex,y), color=tuple(COLOR_PALETTE[i]), width=2.0)
            plot.index.sort_order = "ascending"
        else:
            plot = create_scatter_plot((timex,y), color=tuple(COLOR_PALETTE[i]))
        plot.bgcolor = "white"
        plot.border_visible = True
        if i == 0:
            value_mapper = plot.value_mapper
            index_mapper = plot.index_mapper
            left, bottom = add_default_axes(plot)
            left.tick_generator = ScalesTickGenerator()
            bottom.tick_generator = ScalesTickGenerator(scale=CalendarScaleSystem())
            add_default_grids(plot, tick_gen=bottom.tick_generator)
        else:
            plot.value_mapper = value_mapper
            value_mapper.range.add(plot.value)
            plot.index_mapper = index_mapper
            index_mapper.range.add(plot.index)

        if i==0:
            plot.tools.append(PanTool(plot))
            zoom = ZoomTool(plot, tool_mode="box", always_on=False)
            plot.overlays.append(zoom)
            # Add a legend in the upper right corner, and make it relocatable
            legend = Legend(component=plot, padding=10, align="ur")
            legend.tools.append(LegendTool(legend, drag_button="right"))
            plot.overlays.append(legend)

        container.add(plot)
        plots["Bessel j_%d"%i] = plot

    # Set the list of plots on the legend
    legend.plots = plots

    # Add the title at the top
    container.overlays.append(PlotLabel("Bessel functions",
                              component=container,
                              font = "swiss 16",
                              overlay_position="top"))

    # Add the traits inspector tool to the container
    container.tools.append(TraitsTool(container))

    return container
Esempio n. 14
0
def _create_plot_component():
    container = OverlayPlotContainer(padding = 50, fill_padding = True,
        bgcolor = "lightgray", use_backbuffer=True)

    fprefix = './test_data/CEN184/'

    filename1 = fprefix + 'THL_2012-03-21_18-40-42_000.dat'
    filename2  = fprefix + 'THL_2012-03-21_18-44-42_000.dat'
    fprefix = './test_data/CEN111/'
    filename3 = fprefix + 'THL_2011-07-09_15-02-54_000.dat'
    ioreader = HekaIO(filename3)

    #read a block
    blo = ioreader.read_block(group = 2)

    #protocol stuff
    f = open(filename1)
    head = BundleHeader(f)
    head.load(f)
    bi = head.oBundleItems[2]
    pgf = PGFFile(f,bi)

    value_mapper = None
    index_mapper = None
    plots = {}

    firstplot = True
    for seg in blo.segments:
        #prococol building
        for a_sig in seg.analogsignals:
            x = array(a_sig.times)
            y = array(a_sig)
            ch = int(a_sig.annotations['trSourceChannel'])
            plot = create_line_plot((x,y), width=0.5,color=tuple(COLOR_PALETTE[ch]))
            plot.index.sort_order = "ascending"
            plot.bgcolor = "white"
            plot.border_visible = True

            #code for protocols

            print "###########################"
            st_rec = pgf.tree['children'][a_sig.annotations['pgf_index']]['contents']
            se_rec = pgf.tree['children'][a_sig.annotations['pgf_index']]['children'][0]['children'][1]['contents']
            for key in ['stMark','stDataStartSegment','stDataStartTime']:
                print key+ ' ' +str(st_rec.__dict__[key])
            for key in ['seVoltageIncMode','seDuration','seDurationIncMode','seVoltage',]:
                print key+' '+str(se_rec.__dict__[key])
            for key in ['pgf_index','trTraceCount','trAdcChannel','trSourceChannel','swStimCount']:

                print "%s:%s"%(key,a_sig.annotations[key])
                #se_index = int(seg.annotations['seSeriesCount']) -1
                #sw_index = int(a_sig.annotations['swSweepCount']) -1
                #st_index = int(a_sig.annotations['swStimCount']) -1
            #print pgf.tree['children'][se_index]['children'][st_index]['children'][1]['contents'].seVoltage
            if not firstplot:
                plot.value_mapper = value_mapper
                value_mapper.range.add(plot.value)
                plot.index_mapper = index_mapper
                index_mapper.range.add(plot.index)
            else:
                value_mapper = plot.value_mapper
                index_mapper = plot.index_mapper
                add_default_grids(plot)
                add_default_axes(plot)
                plot.index_range.tight_bounds = False
                plot.index_range.refresh()
                plot.value_range.tight_bounds = False
                plot.value_range.refresh()
                plot.tools.append(PanTool(plot))
                # The ZoomTool tool is stateful and allows drawing a zoom
                # box to select a zoom region.
                zoom = ZoomTool(plot, tool_mode="box", always_on=False)
                plot.overlays.append(zoom)
                # The DragZoom tool just zooms in and out as the user drags
                # the mouse vertically.
                dragzoom = DragZoom(plot, drag_button="right")
                plot.tools.append(dragzoom)
                # Add a legend in the upper right corner, and make it relocatable
                legend = Legend(component=plot, padding=10, align="ur")
                legend.tools.append(LegendTool(legend, drag_button="right"))
                #print a_sig.annotations
                plot.overlays.append(legend)
                firstplot = False
            container.add(plot)
            plots["sweep %s"%a_sig.annotations['trLabel'][:4]] = plot
            # Set the list of plots on the legend
    legend.plots = plots
    # Add the title at the top
    container.overlays.append(PlotLabel(blo.annotations['grLabel'],
        component=container,
        font = "swiss 16",
        overlay_position="top"))
    # Add the traits inspector tool to the container
    container.tools.append(TraitsTool(container))

    return container
Esempio n. 15
0
    def __init__(self, **traits):
        Ice.Application.__init__(self)
        HasTraits.__init__(self,**traits)

        plots = {}
        container = OverlayPlotContainer(padding = 50, fill_padding = True,
                                         bgcolor = "lightgray", use_backbuffer=True)
        self.jtrig = 0

        # Plot all telescopes
        self.LSTdefault = ArrayPlotData()
        self.LSTdefault.set_data('xtel', LSTelX)
        self.LSTdefault.set_data('ytel', LSTelY)
        self.plotLST = Plot(self.LSTdefault)
        self.rLST = self.plotLST.plot(('xtel', 'ytel'), type = "scatter", color = 'black', name = 'LST', marker = 'circle')	  
        self.rLST[0].marker_size = 6    
        self.plotLST.range2d.x_range.high = np.max(TelX + 100.)
        self.plotLST.range2d.x_range.low = np.min(TelX - 100.)
        self.plotLST.range2d.y_range.high = np.max(TelY + 100.)
        self.plotLST.range2d.y_range.low = np.min(TelY - 100.)
        self.plotLST.title = "Triggered telescopes"
 
        container.add(self.plotLST)

        self.MSTdefault = ArrayPlotData()
        self.MSTdefault.set_data('xtel', MSTelX)
        self.MSTdefault.set_data('ytel', MSTelY)
 
        self.plotMST = Plot(self.MSTdefault)
        self.rMST = self.plotMST.plot(('xtel', 'ytel'), type = "scatter", color = 'black', name = 'MST', marker = 'circle')	  
        self.rMST[0].marker_size = 4    
        self.plotMST.range2d = self.plotLST.range2d
 
        container.add(self.plotMST)
 
        self.SSTdefault = ArrayPlotData()
        self.SSTdefault.set_data('xtel', SSTelX)
        self.SSTdefault.set_data('ytel', SSTelY)
 
        self.plotSST = Plot(self.SSTdefault)
        self.rSST = self.plotSST.plot(('xtel', 'ytel'), type = "scatter", color = 'black', name = 'MST', marker = 'circle')	  
        self.rSST[0].marker_size = 1    
        self.plotSST.range2d = self.plotLST.range2d

        container.add(self.plotSST)

        self.plotLST.tools.append(PanTool(self.plotLST))

        # The ZoomTool tool is stateful and allows drawing a zoom
        # box to select a zoom region.
        zoom = ZoomTool(self.plotLST, tool_mode="box", always_on=False)
        self.plotLST.overlays.append(zoom)

        # The DragZoom tool just zooms in and out as the user drags
        # the mouse vertically.
        dragzoom = DragZoom(self.plotLST, drag_button="right")
        self.plotLST.tools.append(dragzoom)

        # Add a legend in the upper right corner, and make it relocatable
        plots["LST"] = self.rLST
        plots["MST"] = self.rMST
        plots["SST"] = self.rSST
        legend = Legend(component=self.plotLST, padding=10, align="ur", line_spacing = 7, font = 'modern 14')
        legend.tools.append(LegendTool(legend, drag_button="right"))
        self.plotLST.overlays.append(legend)
        legend.plots = plots

        # Triggered telescopes
        self.LSTdata = ArrayPlotData()
        self.LSTdata.set_data('xtel', LSTelX)
        self.LSTdata.set_data('ytel', LSTelY)
 
        self.plotLSTtrig = Plot(self.LSTdata)
        self.rLSTdata = self.plotLSTtrig.plot(('xtel', 'ytel'), type = "scatter", marker = 'circle', marker_size = 6)	  
        self.plotLSTtrig.range2d = self.plotLST.range2d
        container.add(self.plotLSTtrig)

        self.MSTdata = ArrayPlotData()
        self.MSTdata.set_data('xtel', MSTelX)
        self.MSTdata.set_data('ytel', MSTelY)
 
        self.plotMSTtrig = Plot(self.MSTdata)
        self.rMSTdata = self.plotMSTtrig.plot(('xtel', 'ytel'), type = "scatter", marker = 'circle', marker_size = 4)	  
        self.plotMSTtrig.range2d = self.plotMST.range2d
 
        container.add(self.plotMSTtrig)
 
        self.SSTdata = ArrayPlotData()
        self.SSTdata.set_data('xtel', SSTelX)
        self.SSTdata.set_data('ytel', SSTelY)

        self.plotSSTtrig = Plot(self.SSTdata)
        self.rSSTdata = self.plotSSTtrig.plot(('xtel', 'ytel'), type = "scatter", marker = 'circle', marker_size = 1)	  
        self.plotSSTtrig.range2d = self.plotSST.range2d

        container.add(self.plotSSTtrig)
 
        # Set the list of plots on the legend
        #legend.plots = plots

        # Add the traits inspector tool to the container
        container.tools.append(TraitsTool(container))

        #draw_png(home_dir + '/Projects/visRTA/Plots/visTrigTel'+str(counter)+'.png', _create_plot_component(self))
        #filename = home_dir + '/Projects/visRTA/Plots/visTrigTel'+str(counter)+'.png'
        #gc = PlotGraphicsContext(size, dpi=72.0)
        #gc.render_component(container)
        #gc.save(filename)

        self.plot = container
        print "end init"
Esempio n. 16
0
def _create_plot_component():

    container = OverlayPlotContainer(padding=60,
                                     fill_padding=True,
                                     use_backbuffer=True,
                                     border_visible=True)

    # Create the initial X-series of data
    numpoints = 100
    low = -5
    high = 15.0
    x = arange(low, high + 0.001, (high - low) / numpoints)

    # Plot some bessel functions
    plots = {}
    broadcaster = BroadcasterTool()
    for i in range(4):
        y = jn(i, x)
        plot = create_line_plot((x, y),
                                color=tuple(COLOR_PALETTE[i]),
                                width=2.0)
        if i == 0:
            add_default_grids(plot)
            left_axis, _ = add_default_axes(plot)
            left_axis.title = "Bessel j0, j2, j3"
        elif i != 1:
            # Map correctly j2 and j3 on the first plot's axis:
            plot0 = plots["Bessel j_0"]
            plot.index_mapper = plot0.index_mapper
            plot.value_mapper = plot0.value_mapper
            plot0.value_mapper.range.add(plot.value)

        # Create a pan/zoom tool and give it a reference to the plot it should
        # manipulate, but don't attach it to the plot. Instead, attach it to
        # the broadcaster. Do it only for each independent set of axis_mappers:
        if i in [0, 1]:
            pan = PanTool(component=plot)
            broadcaster.tools.append(pan)

            zoom = ZoomTool(component=plot)
            broadcaster.tools.append(zoom)

        container.add(plot)
        plots["Bessel j_%d" % i] = plot

    # Add an axis on the right-hand side that corresponds to the second plot.
    # Note that it uses plot.value_mapper instead of plot0.value_mapper.
    plot1 = plots["Bessel j_1"]
    axis = PlotAxis(plot1, orientation="right")
    plot1.underlays.append(axis)
    axis.title = "Bessel j1"

    # Add the broadcast tool to one of the renderers: adding it to the
    # container instead breaks the box mode of the ZoomTool:
    plot0 = plots["Bessel j_0"]
    plot0.tools.append(broadcaster)

    # Create a legend, with tools to move it around and highlight renderers:
    legend = Legend(component=container, padding=10, align="ur")
    legend.tools.append(LegendTool(legend, drag_button="right"))
    legend.tools.append(LegendHighlighter(legend))
    container.overlays.append(legend)
    # Set the list of plots on the legend
    legend.plots = plots

    # Add the title at the top
    container.overlays.append(
        PlotLabel("Bessel functions",
                  component=container,
                  font="swiss 16",
                  overlay_position="top"))

    # Add the traits inspector tool to the container
    container.tools.append(TraitsTool(container))

    return container
Esempio n. 17
0
    def build_plot(self):
        print 'Building plot...'
        fitrange = self.fitrange  # Just for convenience
        onearray = Array
        onearray = sp.ones(self.indata.shape[0])
        minuses = onearray * (-1.)

        # Define index array for fit function:
        self.mod_x = sp.arange(self.line_center - 50., self.line_center + 50.,
                               .01)
        self.Model = sp.zeros(self.mod_x.shape[0])

        # Establish continuum array in a way that opens for other, more
        #   elaborate continua.
        self.contarray = sp.ones(self.mod_x.shape[0]) * \
                self.Components['Contin'][0]
        self.y = {}

        for comp in self.CompoList:
            self.y[comp] = gauss(  # x, mu, sigma, amplitude
                self.mod_x, self.Components[comp][0] + self.line_center,
                self.Components[comp][1], self.Components[comp][2])

        self.Model = self.contarray + self.y[self.select]

        broca = BroadcasterTool()

        # Define the part of the data to show in initial view:
        plotrange = sp.where((self.x > self.line_center - 30)
                             & (self.x < self.line_center + 30))
        # Define the y axis max value in initial view (can be panned/zoomed):
        maxval = float(self.indata[fitrange].max() * 1.2)
        minval = maxval / 15.
        minval = abs(np.median(self.indata[fitrange])) * 1.5
        maxerr = self.errs[fitrange].max() * 1.3
        resmin = max(sp.absolute(self.Resids[self.fitrange]).max(), 5.) * 1.2
        cenx = sp.array([self.line_center, self.line_center])
        ceny = sp.array([-minval, maxval])
        cenz = sp.array([-maxval, maxval])
        # Gray shading of ignored ranges
        rangelist = np.array(self.rangelist)
        grayx = np.array(rangelist.flatten().repeat(2))
        grayx = np.hstack((self.x.min(), grayx, self.x.max()))
        grayy = np.ones_like(grayx) * self.indata.max() * 2.
        grayy[1::4] = -grayy[1::4]
        grayy[2::4] = -grayy[2::4]
        grayy = np.hstack((grayy[-1], grayy[:-1]))

        # Build plot of data and model
        self.plotdata = ArrayPlotData(
            wl=self.x,
            data=self.indata,
            xs=self.mod_x,
            cont=self.contarray,
            ones=onearray,
            minus=minuses,
            model=self.Model,
            errors=self.errs,
            ceny=ceny,
            cenz=cenz,
            cenx=cenx,
            Residuals=self.Resids,
            grayx=grayx,
            grayy=grayy,
        )

        # Add dynamically created components to plotdata
        for comp in self.CompoList:
            self.plotdata.set_data(comp, self.y[comp])
        olplot = GridContainer(shape=(2, 1),
                               padding=10,
                               fill_padding=True,
                               bgcolor='transparent',
                               spacing=(5, 10))
        plot = Plot(self.plotdata)
        plot.y_axis.title = 'Flux density'
        resplot = Plot(self.plotdata, tick_visible=True, y_auto=True)
        resplot.x_axis.title = u'Wavelength [Å]'
        resplot.y_axis.title = u'Residuals/std. err.'

        # Create initial plot: Spectrum data, default first component,
        #   default total line profile.

        self.comprenders = []

        self.datarender = plot.plot(('wl', 'data'),
                                    color='black',
                                    name='Data',
                                    render_style='connectedhold')

        self.contrender = plot.plot(('xs', 'cont'),
                                    color='darkgray',
                                    name='Cont')

        self.modlrender = plot.plot(('xs', 'model'),
                                    color='blue',
                                    line_width=1.6,
                                    name='Model')

        self.centrender = plot.plot(('cenx', 'ceny'),
                                    color='black',
                                    type='line',
                                    line_style='dot',
                                    name='Line center',
                                    line_width=1.)

        self.rangrender = plot.plot(
            ('grayx', 'grayy'),
            type='polygon',
            face_color='lightgray',
            edge_color='gray',
            face_alpha=0.3,
            alpha=0.3,
        )

        # There may be an arbitrary number of gaussian components, so:
        print 'Updating model'
        for comp in self.CompoList:
            self.comprenders.append(
                plot.plot(
                    ('xs', comp),
                    type='line',
                    color=Paired[self.Components[comp]
                                 [3]],  # tuple(COLOR_PALETTE[self.CompNum]),
                    line_color=Paired[self.Components[comp][
                        3]],  # tuple(COLOR_PALETTE[self.CompNum]),
                    line_style='dash',
                    name=comp))

        # Create panel with residuals:
        resplot.plot(('wl', 'Residuals'), color='black', name='Resids')
        resplot.plot(('wl', 'ones'), color='green')
        resplot.plot(('wl', 'minus'), color='green')
        resplot.plot(('cenx', 'cenz'),
                     color='red',
                     type='line',
                     line_style='dot',
                     line_width=.5)
        resplot.plot(
            ('grayx', 'grayy'),  # Yes, that one again
            type='polygon',
            face_color='lightgray',
            edge_color='gray',
            face_alpha=0.3,
            alpha=0.3,
        )
        plot.x_axis.visible = False

        # Set ranges to change automatically when plot values change.
        plot.value_range.low_setting,\
            plot.value_range.high_setting = (-minval, maxval)
        plot.index_range.low_setting,\
            plot.index_range.high_setting = (self.line_center - 30.,
                                             self.line_center + 30.)
        resplot.value_range.low_setting,\
            resplot.value_range.high_setting = (-resmin, resmin)
        resplot.index_range.low_setting,\
            resplot.index_range.high_setting = (plot.index_range.low_setting,
                                                plot.index_range.high_setting)
        #resplot.index_range = plot.index_range  # Yes or no? FIXME
        plot.overlays.append(
            ZoomTool(plot,
                     tool_mode='box',
                     drag_button='left',
                     always_on=False))

        resplot.overlays.append(
            ZoomTool(resplot,
                     tool_mode='range',
                     drag_button='left',
                     always_on=False))

        # List of renderers to tell the legend what to write
        self.plots['Contin'] = self.contrender
        self.plots['Center'] = self.centrender
        self.plots['Model'] = self.modlrender
        for i in sp.arange(len(self.comprenders)):
            self.plots[self.CompoList[i]] = self.comprenders[i]

        # Build Legend:
        legend = Legend(component=plot, padding=10, align="ur")
        legend.tools.append(LegendTool(legend, drag_button="right"))
        legend.plots = self.plots
        plot.overlays.append(legend)
        olplot.tools.append(broca)
        pan = PanTool(plot)
        respan = PanTool(resplot, constrain=True, constrain_direction='x')
        broca.tools.append(pan)
        broca.tools.append(respan)
        plot.overlays.append(ZoomTool(plot, tool_mode='box', always_on=False))
        olplot.add(plot)
        olplot.add(resplot)
        olplot.components[0].set(resizable='hv', bounds=[500, 400])
        olplot.components[1].set(resizable='h', bounds=[500, 100])
        self.plot = plot
        self.resplot = resplot
        self.plwin = olplot
        self.legend = legend
        self.plotrange = plotrange
Esempio n. 18
0
    def build_plot(self):
        global plotdata  # FIXME: Don't use global!
        onearray = Array
        onearray = sp.ones(self.indata.shape[0])
        minuses = onearray * (-1.)

        # Define index array for fit function:
        self.mod_x = sp.arange(self.line_center - 50.,
                               self.line_center + 50., .01)
        self.Model = sp.zeros(self.mod_x.shape[0])

        # Establish continuum array in a way that opens for other, more
        #   elaborate continua.
        self.contarray = sp.ones(self.mod_x.shape[0]) * \
                self.Components['Contin']
        self.y = {}

        for comp in self.CompoList:
            self.y[comp] = stats.norm.pdf(
                self.mod_x,
                self.Components[comp][0] + self.line_center,
                self.Components[comp][1]
            ) * self.Components[comp][1] * sp.sqrt(2. * sp.pi) * \
                    self.Components[comp][2]
        self.Model = self.contarray + self.y[self.select]

        broca = BroadcasterTool()

        # Define the part of the data to show in initial view:
        plotrange = sp.where((self.x > self.line_center - 20) &
                             (self.x < self.line_center + 20))
        # Define the y axis max value in initial view (can be panned/zoomed):
        maxval = float(self.indata[plotrange].max() * 1.1)
        minval = maxval / 15.
        maxerr = self.errs[plotrange].max() * 1.3
        resmin = max(self.Resids[plotrange].max(), 5.) * 1.2
        cenx = sp.array([self.line_center, self.line_center])
        ceny = sp.array([-minval, maxval])
        cenz = sp.array([-maxval, maxval])
        # Build plot of data and model
        plotdata = ArrayPlotData(
            wl=self.x,
            data=self.indata,
            xs=self.mod_x,
            cont=self.contarray,
            ones=onearray,
            minus=minuses,
            model=self.Model,
            errors=self.errs,
            ceny=ceny,
            cenz=cenz,
            cenx=cenx,
            Residuals=self.Resids,
        )
        for comp in self.CompoList:
            plotdata.set_data(comp, self.y[comp])
        olplot = GridContainer(shape=(2, 1), padding=10,
                               fill_padding=True,
                               bgcolor='transparent',
                               spacing=(5, 10))
        plot = Plot(plotdata)
        plot.y_axis.title = 'Flux density'
        resplot = Plot(plotdata, tick_visible=True, y_auto=True)
        resplot.x_axis.title = u'Wavelength [Å]'
        resplot.y_axis.title = u'Residuals/std. err.'

        # Create initial plot: Spectrum data, default first component,
        #   default total line profile.
        self.comprenders = []
        self.datarender = plot.plot(('wl', 'data'), color='black',
                                    name='Data',
                                    render_style='connectedhold')
        self.contrender = plot.plot(('xs', 'cont'), color='darkgray',
                                    name='Cont')
        self.modlrender = plot.plot(('xs', 'model'), color='blue',
                                    line_width=1.6, name='Model')
        self.centrender = plot.plot(('cenx', 'ceny'),
                                    color='black',
                                    type='line',
                                    line_style='dot',
                                    name='Line center',
                                    line_width=1.)

        # There may be an arbitrary number of gaussian components, so:
        for comp in self.CompoList:
            self.comprenders.append(
                plot.plot(('xs', comp),
                          type='line',
                          #color='auto',
                          color=tuple(COLOR_PALETTE[self.CompNum]),
                          line_style='dash',
                          name=comp)
            )

        # Create panel with residuals:
        resplot.plot(('wl', 'Residuals'), color='black', name='Resids')
        resplot.plot(('wl', 'ones'), color='green')
        resplot.plot(('wl', 'minus'), color='green')
        resplot.plot(('cenx', 'cenz'), color='red',
                     type='line',
                     line_style='dot',
                     line_width=.5)
        plot.x_axis.visible = False

        # Set ranges to change automatically when plot values change.
        plot.value_range.low_setting,\
            plot.value_range.high_setting = (-minval, maxval)
        plot.index_range.low_setting,\
            plot.index_range.high_setting = (self.line_center - 20.,
                                             self.line_center + 20.)
        resplot.value_range.low_setting,\
            resplot.value_range.high_setting = (-resmin, resmin)
        resplot.index_range.low_setting,\
            resplot.index_range.high_setting = (plot.index_range.low_setting,
                                                plot.index_range.high_setting)
        #resplot.index_range = plot.index_range  # Yes or no? FIXME
        plot.overlays.append(ZoomTool(plot, tool_mode='box',
                                      drag_button='left',
                                      always_on=False))

        resplot.overlays.append(ZoomTool(resplot, tool_mode='range',
                                         drag_button='left',
                                         always_on=False))

        # List of renderers to tell the legend what to write
        self.plots['Contin'] = self.contrender
        self.plots['Center'] = self.centrender
        self.plots['Model'] = self.modlrender
        for i in sp.arange(len(self.comprenders)):
            self.plots[self.CompoList[i]] = self.comprenders[i]

        # Build Legend:
        legend = Legend(component=plot, padding=10, align="ur")
        legend.tools.append(LegendTool(legend, drag_button="right"))
        legend.plots = self.plots
        plot.overlays.append(legend)
        olplot.tools.append(broca)
        pan = PanTool(plot)
        respan = PanTool(resplot, constrain=True, constrain_direction='x')
        broca.tools.append(pan)
        broca.tools.append(respan)
        plot.overlays.append(ZoomTool(plot, tool_mode='box',
                                      always_on=False))
        olplot.add(plot)
        olplot.add(resplot)
        olplot.components[0].set(resizable='hv', bounds=[500, 400])
        olplot.components[1].set(resizable='h', bounds=[500, 100])
        self.plot = plot
        self.resplot = resplot
        self.plwin = olplot
        self.legend = legend
        self.plotrange = plotrange
Esempio n. 19
0
def _create_plot_component():

    container = OverlayPlotContainer(padding=50,
                                     fill_padding=True,
                                     bgcolor="lightgray",
                                     use_backbuffer=True)

    # Create the initial X-series of data
    numpoints = 100
    low = -5
    high = 15.0
    x = arange(low, high + 0.001, (high - low) / numpoints)

    # Plot some bessel functions
    plots = {}
    broadcaster = BroadcasterTool()
    for i in range(4):
        y = jn(i, x)
        plot = create_line_plot((x, y),
                                color=tuple(COLOR_PALETTE[i]),
                                width=2.0)
        plot.index.sort_order = "ascending"
        plot.bgcolor = "white"
        plot.border_visible = True
        if i == 0:
            add_default_grids(plot)
            add_default_axes(plot)

        # Create a pan tool and give it a reference to the plot it should
        # manipulate, but don't attach it to the plot.  Instead, attach it to
        # the broadcaster.
        pan = PanTool(plot)
        broadcaster.tools.append(pan)

        container.add(plot)
        plots["Bessel j_%d" % i] = plot

    # Add an axis on the right-hand side that corresponds to the second plot.
    # Note that it uses plot.value_mapper instead of plot0.value_mapper.
    plot1 = plots["Bessel j_1"]
    axis = PlotAxis(plot1, orientation="right")
    plot1.underlays.append(axis)

    # Add the broadcast tool to the container, instead of to an
    # individual plot
    container.tools.append(broadcaster)

    legend = Legend(component=container, padding=10, align="ur")
    legend.tools.append(LegendTool(legend, drag_button="right"))
    container.overlays.append(legend)

    # Set the list of plots on the legend
    legend.plots = plots

    # Add the title at the top
    container.overlays.append(
        PlotLabel("Bessel functions",
                  component=container,
                  font="swiss 16",
                  overlay_position="top"))

    # Add the traits inspector tool to the container
    container.tools.append(TraitsTool(container))

    return container
Esempio n. 20
0
def _create_plot_component():
    container = OverlayPlotContainer(
        padding=50,
        fill_padding=True,
        bgcolor="lightgray",
        use_backbuffer=True)

    # Create the initial X-series of data
    numpoints = 100
    low = -5
    high = 15.0
    x = linspace(low, high, numpoints)

    now = time()
    timex = linspace(now, now + 7 * 24 * 3600, numpoints)

    # Plot some bessel functions
    value_mapper = None
    index_mapper = None
    plots = {}
    for i in range(10):
        y = jn(i, x)
        if i % 2 == 1:
            plot = create_line_plot(
                (timex, y), color=tuple(COLOR_PALETTE[i]), width=2.0)
            plot.index.sort_order = "ascending"
        else:
            plot = create_scatter_plot(
                (timex, y), color=tuple(COLOR_PALETTE[i]))
        plot.bgcolor = "white"
        plot.border_visible = True
        if i == 0:
            value_mapper = plot.value_mapper
            index_mapper = plot.index_mapper
            left, bottom = add_default_axes(plot)
            left.tick_generator = ScalesTickGenerator()
            bottom.tick_generator = ScalesTickGenerator(
                scale=CalendarScaleSystem())
            add_default_grids(plot, tick_gen=bottom.tick_generator)
        else:
            plot.value_mapper = value_mapper
            value_mapper.range.add(plot.value)
            plot.index_mapper = index_mapper
            index_mapper.range.add(plot.index)

        if i == 0:
            plot.tools.append(PanTool(plot))
            zoom = ZoomTool(plot, tool_mode="box", always_on=False)
            plot.overlays.append(zoom)
            # Add a legend in the upper right corner, and make it relocatable
            legend = Legend(component=plot, padding=10, align="ur")
            legend.tools.append(LegendTool(legend, drag_button="right"))
            plot.overlays.append(legend)

        container.add(plot)
        plots["Bessel j_%d" % i] = plot

    # Set the list of plots on the legend
    legend.plots = plots

    # Add the title at the top
    container.overlays.append(
        PlotLabel(
            "Bessel functions",
            component=container,
            font="swiss 16",
            overlay_position="top"))

    # Add the traits inspector tool to the container
    container.tools.append(TraitsTool(container))

    return container