예제 #1
0
    def create_plot(self):

        # Create the mapper, etc
        self._image_index = GridDataSource(array([]),
                                           array([]),
                                           sort_order=("ascending",
                                                       "ascending"))
        image_index_range = DataRange2D(self._image_index)
        self._image_index.on_trait_change(self._metadata_changed,
                                          "metadata_changed")

        self._image_value = ImageData(data=array([]), value_depth=1)
        image_value_range = DataRange1D(self._image_value)

        # Create the contour plots
        self.polyplot = ContourPolyPlot(index=self._image_index,
                                        value=self._image_value,
                                        index_mapper=GridMapper(range=
                                            image_index_range),
                                        color_mapper=\
                                            self._cmap(image_value_range),
                                        levels=self.num_levels)

        self.lineplot = ContourLinePlot(
            index=self._image_index,
            value=self._image_value,
            index_mapper=GridMapper(range=self.polyplot.index_mapper.range),
            levels=self.num_levels)

        # Add a left axis to the plot
        left = PlotAxis(orientation='left',
                        title="y",
                        mapper=self.polyplot.index_mapper._ymapper,
                        component=self.polyplot)
        self.polyplot.overlays.append(left)

        # Add a bottom axis to the plot
        bottom = PlotAxis(orientation='bottom',
                          title="x",
                          mapper=self.polyplot.index_mapper._xmapper,
                          component=self.polyplot)
        self.polyplot.overlays.append(bottom)

        # Add some tools to the plot
        self.polyplot.tools.append(
            PanTool(self.polyplot, constrain_key="shift"))
        self.polyplot.overlays.append(
            ZoomTool(component=self.polyplot, tool_mode="box",
                     always_on=False))
        self.polyplot.overlays.append(
            LineInspector(component=self.polyplot,
                          axis='index_x',
                          inspect_mode="indexed",
                          write_metadata=True,
                          is_listener=False,
                          color="white"))
        self.polyplot.overlays.append(
            LineInspector(component=self.polyplot,
                          axis='index_y',
                          inspect_mode="indexed",
                          write_metadata=True,
                          color="white",
                          is_listener=False))

        # Add these two plots to one container
        contour_container = OverlayPlotContainer(padding=20,
                                                 use_backbuffer=True,
                                                 unified_draw=True)
        contour_container.add(self.polyplot)
        contour_container.add(self.lineplot)

        # Create a colorbar
        cbar_index_mapper = LinearMapper(range=image_value_range)
        self.colorbar = ColorBar(index_mapper=cbar_index_mapper,
                                 plot=self.polyplot,
                                 padding_top=self.polyplot.padding_top,
                                 padding_bottom=self.polyplot.padding_bottom,
                                 padding_right=40,
                                 resizable='v',
                                 width=30)

        self.pd = ArrayPlotData(line_index=array([]),
                                line_value=array([]),
                                scatter_index=array([]),
                                scatter_value=array([]),
                                scatter_color=array([]))

        self.cross_plot = Plot(self.pd, resizable="h")
        self.cross_plot.height = 100
        self.cross_plot.padding = 20
        self.cross_plot.plot(("line_index", "line_value"), line_style="dot")
        self.cross_plot.plot(
            ("scatter_index", "scatter_value", "scatter_color"),
            type="cmap_scatter",
            name="dot",
            color_mapper=self._cmap(image_value_range),
            marker="circle",
            marker_size=8)

        self.cross_plot.index_range = self.polyplot.index_range.x_range

        self.pd.set_data("line_index2", array([]))
        self.pd.set_data("line_value2", array([]))
        self.pd.set_data("scatter_index2", array([]))
        self.pd.set_data("scatter_value2", array([]))
        self.pd.set_data("scatter_color2", array([]))

        self.cross_plot2 = Plot(self.pd,
                                width=140,
                                orientation="v",
                                resizable="v",
                                padding=20,
                                padding_bottom=160)
        self.cross_plot2.plot(("line_index2", "line_value2"), line_style="dot")
        self.cross_plot2.plot(
            ("scatter_index2", "scatter_value2", "scatter_color2"),
            type="cmap_scatter",
            name="dot",
            color_mapper=self._cmap(image_value_range),
            marker="circle",
            marker_size=8)

        self.cross_plot2.index_range = self.polyplot.index_range.y_range

        # Create a container and add components
        self.container = HPlotContainer(padding=40,
                                        fill_padding=True,
                                        bgcolor="white",
                                        use_backbuffer=False)
        inner_cont = VPlotContainer(padding=0, use_backbuffer=True)
        inner_cont.add(self.cross_plot)
        inner_cont.add(contour_container)
        self.container.add(self.colorbar)
        self.container.add(inner_cont)
        self.container.add(self.cross_plot2)
예제 #2
0
def _create_plot_component(obj):
    # Setup the spectrum plot
    frequencies = linspace(0.0, float(SAMPLING_RATE) / 2, num=NUM_SAMPLES / 2)
    obj.spectrum_data = ArrayPlotData(frequency=frequencies)
    empty_amplitude = zeros(NUM_SAMPLES / 2)
    obj.spectrum_data.set_data('amplitude', empty_amplitude)

    obj.spectrum_plot = Plot(obj.spectrum_data)
    obj.spectrum_plot.plot(("frequency", "amplitude"),
                           name="Spectrum",
                           color="red")
    obj.spectrum_plot.padding = 50
    obj.spectrum_plot.title = "Spectrum"
    #spec_range = obj.spectrum_plot.plots.values()[0][0].value_mapper.range
    #spec_range.low = 0.0
    #spec_range.high = 5.0
    obj.spectrum_plot.index_axis.title = 'Frequency (Hz)'
    obj.spectrum_plot.value_axis.title = 'Amplitude'

    # Time Series plot
    times = linspace(0.0, float(NUM_SAMPLES) / SAMPLING_RATE, num=NUM_SAMPLES)
    obj.time_data = ArrayPlotData(time=times)
    empty_amplitude = zeros(NUM_SAMPLES)
    obj.time_data.set_data('amplitude', empty_amplitude)

    obj.time_plot = Plot(obj.time_data)
    obj.time_plot.plot(("time", "amplitude"), name="Time", color="blue")
    obj.time_plot.padding = 50
    obj.time_plot.title = "Time"
    obj.time_plot.index_axis.title = 'Time (seconds)'
    obj.time_plot.value_axis.title = 'Amplitude'
    time_range = obj.time_plot.plots.values()[0][0].value_mapper.range
    time_range.low = -0.2
    time_range.high = 0.2

    # Spectrogram plot
    spectrogram_data = zeros((NUM_SAMPLES / 2, SPECTROGRAM_LENGTH))
    obj.spectrogram_plotdata = ArrayPlotData()
    obj.spectrogram_plotdata.set_data('imagedata', spectrogram_data)
    spectrogram_plot = Plot(obj.spectrogram_plotdata)
    max_time = float(SPECTROGRAM_LENGTH * NUM_SAMPLES) / SAMPLING_RATE
    max_freq = float(SAMPLING_RATE / 2)
    spectrogram_plot.img_plot(
        'imagedata',
        name='Spectrogram',
        xbounds=(0, max_time),
        ybounds=(0, max_freq),
        colormap=hot,
    )
    range_obj = spectrogram_plot.plots['Spectrogram'][0].value_mapper.range
    range_obj.high = 5
    range_obj.low = 0.0
    spectrogram_plot.title = 'Spectrogram'
    obj.spectrogram_plot = spectrogram_plot

    container = HPlotContainer()
    container.add(obj.spectrum_plot)
    container.add(obj.time_plot)
    container.add(spectrogram_plot)

    return container
예제 #3
0
파일: display2.py 프로젝트: jcapriot/src
    def __init__(self):

        super(ContainerExample, self).__init__()

        # make a list of the files names on the command line
        # command line entries without = are assumed to be files
        filenames = []
        for parameter in sys.argv[1:]:
            print("processing parameter", parameter)
            if parameter.find("=") == -1:
                print("no = in parameter", parameter, "must be a file name")
                filenames.append(parameter)
        if len(filenames) < 1:
            print("just to help me test, if there are no files in the list, ")
            print("I will append the file foldplot1.rsf")
            filenames.append('foldplot1.rsf')

        # there should be a try while these files are opened to identify
        # bad file names and make error messages.

        self.seis_data = []
        for filename in filenames:
            print("  ")
            print("+++++++++++++++++++++++++++++++++++++++++++")
            print("+++++++++++++++++++++++++++++++++++++++++++")
            print("open the file", filename)
            self.seis_data.append(SeisData(filename))

        # kls files should be tested to make sure they are all same shape
        print("number files=", len(filenames))
        self.displayParameters = DisplayParameters()
        self.cmap = jet  # kls this should come from display parameters

        self.slice_y = self.displayParameters.slice_y  # kls this should be pointer

        print("self.slice_y=", self.slice_y)
        self.arrayPlotDatas = []
        for filename in filenames:
            self.arrayPlotDatas.append(ArrayPlotData())
        self._update_images()

        x_extents = (self.seis_data[0].axis_start[1],
                     self.seis_data[0].axis_end[1])
        y_extents = (self.seis_data[0].axis_start[2],
                     self.seis_data[0].axis_end[2])
        bottomplot = Plot(self.arrayPlotDatas[0], origin="top left")
        self.bottomplot = bottomplot
        imgplot = bottomplot.img_plot("xz",
                                      xbounds=x_extents,
                                      ybounds=y_extents,
                                      colormap=self.cmap)[0]
        self.bottom = imgplot

        plotright = Plot(self.arrayPlotDatas[1],
                         origin="top left",
                         range2d=bottomplot.range2d)
        imgplotright = plotright.img_plot("xz",
                                          xbounds=x_extents,
                                          ybounds=y_extents,
                                          colormap=self.cmap)[0]
        self.right = imgplotright

        container = HPlotContainer(fill_padding=True,
                                   bgcolor="white",
                                   use_backbuffer=True)
        container.add(bottomplot)
        container.add(plotright)

        self.plot = container

        self.displayParameters = DisplayParameters()
        self.slice_y = self.displayParameters.slice_y

        imgplot.tools.append(CustomTool(imgplot))
        imgplot.tools.append(PanTool(imgplot, constrain_key="shift"))
        imgplot.overlays.append(
            ZoomTool(component=imgplot, tool_mode="box", always_on=False))
        imgplotright.tools.append(PanTool(imgplotright, constrain_key="shift"))
        imgplotright.overlays.append(
            ZoomTool(component=self.right, tool_mode="box", always_on=False))