Example #1
0
 def _resp_plot_default(self):
     # Create plotting components
     self.resp_plot_data = ArrayPlotData(
         time=self.time,
         inhale_times=self.resp_inhale_begin_times,
         inhale_values=self.resp_inhale_begin_values,
         exhale_times=self.resp_exhale_begin_times,
         exhale_values=self.resp_exhale_begin_values,
         filtered_resp=self.resp_signal,
         lpfilt_resp=self.lpfilt_resp)
     plot = Plot(self.resp_plot_data)
     plot.plot(("time", "filtered_resp"), color="blue", line_width=1)
     plot.plot(("time", "lpfilt_resp"), color="green", line_width=1)
     # Plot the inhalation peaks
     plot.plot(("inhale_times", "inhale_values"),
               type="scatter",
               marker="square")
     plot.plot(("exhale_times", "exhale_values"),
               type="scatter",
               marker="circle")
     plot.title = "Respiration"
     plot.title_position = "right"
     plot.title_angle = 270
     plot.padding = 20
     return plot
Example #2
0
    def _point_plots_default(self):
        """
        Instead of defining these in __init__, only
        construct the plots when a ui is requested
        """

        self.point_plotdata = ArrayPlotData(
            peak_times=self.physiodata.peak_times.flatten(),
            x_times=self.physiodata.x_indices - self.physiodata.dzdt_pre_peak,
            lvet=self.physiodata.lvet,
            pep=self.physiodata.pep)

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

        for sig in ("pep", "x_times", "lvet"):
            temp_plt = Plot(self.point_plotdata)
            temp_plt.plot(("peak_times", sig), line_width=2)
            temp_plt.title = sig
            container.add(temp_plt)
        container.padding_top = 10

        return container
Example #3
0
    def _karcher_plot_default(self):
        """
        Instead of defining these in __init__, only
        construct the plots when a ui is requested
        """
        self.interactive = True
        unreg_mean = self.global_ensemble.dzdt_signal
        # Temporarily fill in the karcher mean
        if not self.karcher_mean_calculated:
            karcher_mean = unreg_mean[self.dzdt_mask]
        else:
            karcher_mean = self.dzdt_karcher_mean

        self.karcher_plotdata = ArrayPlotData(
            time=self.global_ensemble.dzdt_time,
            unregistered_mean=self.global_ensemble.dzdt_signal,
            karcher_mean=karcher_mean,
            karcher_time=self.dzdt_karcher_mean_time)
        karcher_plot = Plot(self.karcher_plotdata)
        karcher_plot.plot(("time", "unregistered_mean"),
                          line_width=1,
                          color="lightblue")
        line_plot = karcher_plot.plot(("karcher_time", "karcher_mean"),
                                      line_width=3,
                                      color="blue")[0]
        # Create an overlay tool
        karcher_plot.datasources['karcher_time'].sort_order = "ascending"

        return karcher_plot
Example #4
0
    def _plot_default(self):

        plot = Plot(self.plotdata)

        if self.signal in ("tpr", "co", "sv"):
            rc_signal = "resp_corrected_" + self.signal
            if rc_signal in self.plotdata.arrays and self.plotdata.arrays[
                    rc_signal].size > 0:
                # Plot the resp-uncorrected version underneath
                plot.plot(("peak_times", self.signal),
                          type="line",
                          color="purple")
                signal = rc_signal
            signal = self.signal
        elif self.signal == "hr":
            plot.plot(("peak_times", self.signal), type="line", color="purple")
            signal = "mea_hr"
        else:
            signal = self.signal

        # Create the plot
        plot.plot(("peak_times", signal), type="line", color="blue")
        plot.plot(("peak_times", signal, "beat_type"),
                  type="cmap_scatter",
                  color_mapper=jet,
                  name="my_plot",
                  marker="circle",
                  border_visible=False,
                  outline_color="transparent",
                  bg_color="white",
                  index_sort="ascending",
                  marker_size=3,
                  fill_alpha=0.8)

        # Tweak some of the plot properties
        plot.title = self.signal  #"Scatter Plot With Lasso Selection"
        plot.title_position = "right"
        plot.title_angle = 270
        plot.line_width = 1
        plot.padding = 20

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

        # Attach some tools to the plot
        self.selection = BeatSelection(component=my_plot)
        my_plot.active_tool = self.selection
        selection_overlay = RangeSelectionOverlay(component=my_plot)
        my_plot.overlays.append(selection_overlay)

        # Set up the trait handler for the selection
        self.selection.on_trait_change(self._selection_changed,
                                       'selection_completed')

        return plot
Example #5
0
 def _z0_plot_default(self):
     self.z0_plot_data = ArrayPlotData(time=self.time,
                                       raw_data=self.raw_z0_signal,
                                       cleaned_data=self.resp_corrected_z0)
     plot = Plot(self.z0_plot_data)
     plot.plot(("time", "raw_data"), color="blue", line_width=1)
     plot.plot(("time", "cleaned_data"), color="green", line_width=1)
     plot.title = "z0"
     plot.title_position = "right"
     plot.title_angle = 270
     plot.padding = 20
     return plot
Example #6
0
    def _registration_plot_default(self):
        """
        Instead of defining these in __init__, only
        construct the plots when a ui is requested
        """
        unreg_mean = self.global_ensemble.dzdt_signal
        # Temporarily fill in the karcher mean
        if not self.karcher_mean_calculated:
            karcher_mean = unreg_mean[self.dzdt_mask]
        else:
            karcher_mean = self.dzdt_karcher_mean

        self.single_registration_plotdata = ArrayPlotData(
            karcher_time=self.dzdt_karcher_mean_time,
            karcher_mean=karcher_mean,
            registered_func=karcher_mean)

        self.single_plot = Plot(self.single_registration_plotdata)
        self.single_plot.plot(("karcher_time", "karcher_mean"),
                              line_width=2,
                              color="blue")
        self.single_plot.plot(("karcher_time", "registered_func"),
                              line_width=2,
                              color="maroon")


        if self.all_beats_registered_to_initial or \
           self.all_beats_registered_to_mode:
            image_data = self.registered_functions.copy()
        else:
            image_data = self.dzdt_functions_to_warp.copy()

        # Create a plot of all the functions registered or not
        self.all_registration_plotdata = ArrayPlotData(image_data=image_data)
        self.all_plot = Plot(self.all_registration_plotdata)
        self.all_plot.img_plot("image_data", colormap=jet)

        return HPlotContainer(self.single_plot, self.all_plot)
Example #7
0
 def _image_plot_default(self):
     # for image plot
     img = self.ecg_matrix
     if self.ecg_matrix.size == 0:
         img = np.zeros((100, 100))
     self.image_plot_data = ArrayPlotData(imagedata=img)
     plot = Plot(self.image_plot_data)
     self.image_selection_tool = ImageRangeSelector(component=plot,
                                                    tool_mode="range",
                                                    axis="value",
                                                    always_on=True)
     plot.img_plot("imagedata",
                   colormap=jet,
                   name="plot1",
                   origin="bottom left")[0]
     plot.overlays.append(self.image_selection_tool)
     return plot
Example #8
0
 def _dzdt_plot_default(self):
     """
     Creates a plot of the ecg_ts data and the signals derived during
     the Pan Tomkins algorithm
     """
     # Create plotting components
     self.dzdt_plot_data = ArrayPlotData(
         time=self.time,
         raw_data=self.raw_dzdt_signal,
         cleaned_data=self.resp_corrected_dzdt)
     plot = Plot(self.dzdt_plot_data)
     plot.plot(("time", "raw_data"), color="blue", line_width=1)
     plot.plot(("time", "cleaned_data"), color="green", line_width=1)
     plot.title = "dZ/dt"
     plot.title_position = "right"
     plot.title_angle = 270
     plot.padding = 20
     return plot
Example #9
0
    def _plot_default(self):
        # Create plotting components
        plotdata = ArrayPlotData(time=self.time, data=self.data)
        plot = Plot(plotdata)
        self.renderer = plot.plot(("time", "data"), color=self.line_color)[0]
        plot.title = self.name
        plot.title_position = "right"
        plot.title_angle = 270
        plot.line_width = 1
        plot.padding = 25
        plot.width = 400

        # Load the censor regions and add them to the plot
        for censor_region in self.censored_regions:
            # Make a censor region on the Timeseries object
            censor_region.plot = self.renderer
            censor_region.viz
            censor_region.set_limits(censor_region.start_time,
                                     censor_region.end_time)
        return plot
Example #10
0
    def _plot_default(self):
        """
        Creates a plot of the ecg_ts data and the signals derived during
        the Pan Tomkins algorithm
        """
        # Create plotting components
        self.plot_data = ArrayPlotData(
            time=self.ecg_time,
            raw_ecg=self.ecg_signal,
            qrs_power=self.qrs_power_signal,
            aux_signal=self.aux_signal,
            # Ensembleable peaks
            peak_times=self.peak_times,
            peak_values=self.peak_values,
            # Non-ensembleable, useful for HR, HRV
            dne_peak_times=self.dne_peak_times,
            dne_peak_values=self.dne_peak_values,
            # Threshold slider bar
            thr_times=np.array([self.ecg_time[0], self.ecg_time[-1]]),
            thr_vals=np.array([0, 0]))

        plot = Plot(self.plot_data, use_backbuffer=True)
        self.aux_trace = plot.plot(("time", "aux_signal"),
                                   color="purple",
                                   alpha=0.6,
                                   line_width=2)[0]
        self.qrs_power_trace = plot.plot(("time", "qrs_power"),
                                         color="blue",
                                         alpha=0.8)[0]
        self.ecg_trace = plot.plot(("time", "raw_ecg"),
                                   color="red",
                                   line_width=2)[0]

        # Load the censor regions and add them to the plot
        for n, (start, end) in enumerate(self.censored_intervals):
            censor_key = "censor%03d" % n
            self.censored_region_graphics.append(
                StaticCensoredInterval(component=self.qrs_power_trace,
                                       metadata_name=censor_key))
            self.ecg_trace.overlays.append(self.censored_region_graphics[-1])
            self.ecg_trace.index.metadata[censor_key] = start, end

        # Line showing
        self.threshold_trace = plot.plot(("thr_times", "thr_vals"),
                                         color="black",
                                         line_width=3)[0]

        # Plot for plausible peaks
        self.ppeak_vis = plot.plot(("dne_peak_times", "dne_peak_values"),
                                   type="scatter",
                                   marker="diamond")[0]

        # Make a scatter plot where you can edit the peaks
        self.peak_vis = plot.plot(("peak_times", "peak_values"),
                                  type="scatter")[0]
        self.scatter = plot.components[-1]
        self.peak_editor = PeakPickingTool(self.scatter)
        self.scatter.tools.append(self.peak_editor)
        # when the user adds or removes a point, automatically extract
        self.on_trait_event(self._change_peaks, "peak_editor.done_selecting")

        self.scatter.overlays.append(
            PeakPickingOverlay(component=self.scatter))

        return plot