def plot_marker_data(self, title: str, y_label: str, kine_var: str, fig_num: int, add_sd: bool = True,
                         clip_graph: bool = False, marker: str = '') -> matplotlib.figure.Figure:
        """Plot raw, filtered, and smoothed kinematic (position, velocity, acceleration) marker data, allowing the
        addition of confidence bounds."""
        fig = plt.figure(num=fig_num)
        ax = fig.subplots(3, 1, sharex=True)
        lines_raw = marker_graph_init(ax, getattr(self.raw.means, kine_var), y_label, x_data=self.frames,
                                      color='indigo', marker=marker)
        lines_filtered = marker_graph_add(ax, getattr(self.filtered.means, kine_var), self.filtered_frames, color='red')
        lines_smoothed = marker_graph_add(ax, getattr(self.smoothed.means, kine_var), self.filtered_frames,
                                          color='limegreen')

        if add_sd:
            marker_graph_add_cov(ax, getattr(self.filtered.means, kine_var), getattr(self.filtered.covars, kine_var),
                                 self.filtered_frames, 'red')
            marker_graph_add_cov(ax, getattr(self.smoothed.means, kine_var), getattr(self.smoothed.covars, kine_var),
                                 self.filtered_frames, 'limegreen')
        if clip_graph:
            for c_ax in ax:
                c_ax.set_xlim(self.vicon_frame_endpts[0], self.vicon_frame_endpts[1])
        else:
            add_vicon_start_stop(ax, self.vicon_frame_endpts[0], self.vicon_frame_endpts[1])
        fig.legend((lines_raw[0], lines_filtered[0], lines_smoothed[0]), ('Raw', 'Filtered', 'Smoothed'), 'upper right',
                   labelspacing=0.1)
        marker_graph_title(fig, title)
        make_interactive()
        return fig
    def plot_marker_data_diff_hist(self, title: str, x_label: str, fig_num: int, clip_graph: bool = True) \
            -> matplotlib.figure.Figure:
        """Plot histogram of smoothed marker positions - raw marker positions."""
        if clip_graph:
            endpts = np.zeros((2,), dtype=np.int)

            if self.vicon_endpts[0] > self.filtered.endpts[0]:
                endpts[0] = self.vicon_endpts[0] - self.filtered.endpts[0]

            if self.vicon_endpts[1] < self.filtered.endpts[1]:
                endpts[1] = self.vicon_endpts[1] - self.filtered.endpts[0]
            else:
                endpts[1] = self.filtered.endpts[1] - self.filtered.endpts[0]

            smoothed_diff = self.smoothed_pos_diff[endpts[0]:endpts[1]]
        else:
            smoothed_diff = self.smoothed_pos_diff

        fig = plt.figure(num=fig_num)
        ax = fig.subplots(1, 3, sharey=True)
        lines_smoothed = marker_diff_his_init(ax, smoothed_diff, x_label, 'limegreen')
        fig.legend([lines_smoothed[0]], ['Smoothed'], 'upper right', labelspacing=0.1)
        marker_graph_title(fig, title)
        make_interactive()
        return fig
Ejemplo n.º 3
0
    def plot_biplane_vicon(self, title: str, fig_num: int, vicon_field: str, vicon_type: str) \
            -> matplotlib.figure.Figure:
        """Plot overlayed marker position data as measured via Vicon and biplane fluoroscopy."""
        fig = plt.figure(num=fig_num)
        ax = fig.subplots(3, 1, sharex=True)
        lines_vicon = marker_graph_init(ax,
                                        getattr(self, vicon_field),
                                        'Distance (mm)',
                                        self.vicon_frames,
                                        color='limegreen',
                                        marker='.',
                                        lw=1,
                                        ms=2)
        lines_biplane = marker_graph_add(ax,
                                         self.biplane_data,
                                         self.vicon_frames,
                                         color='indigo',
                                         marker='.')

        fig.legend((lines_biplane[0], lines_vicon[0]),
                   ('Biplane', vicon_type + ' Vicon'),
                   'upper right',
                   ncol=3,
                   columnspacing=0.3,
                   handlelength=1.0)
        marker_graph_title(fig, title)
        make_interactive()
        return fig
 def plot(self) -> List[matplotlib.figure.Figure]:
     """Plot marker_data onto 3 row subplots on Figure 0."""
     fig = plt.figure(num=0)
     ax = fig.subplots(3, 1, sharex=True)
     marker_graph_init(ax, self.marker_pos_labeled, 'Pos (mm)', x_data=self.frame_nums, color='blue')
     add_vicon_start_stop(ax, self.vicon_endpts[0] + 1, self.vicon_endpts[1])
     marker_graph_title(fig, self.trial_name + ' ' + self.marker_name)
     make_interactive()
     return [fig]
 def plot_marker_data_diff(self, title: str, y_label: str, fig_num: int) -> matplotlib.figure.Figure:
     """Plot smoothed marker positions - raw marker positions."""
     fig = plt.figure(num=fig_num)
     ax = fig.subplots(3, 1, sharex=True)
     lines_smoothed = marker_graph_init(ax, self.smoothed_pos_diff, y_label, x_data=self.filtered_frames,
                                        color='limegreen')
     fig.legend([lines_smoothed[0]], ['Smoothed'], 'upper right', labelspacing=0.1)
     add_vicon_start_stop(ax, self.vicon_frame_endpts[0], self.vicon_frame_endpts[1])
     marker_graph_title(fig, title)
     make_interactive()
     return fig
 def plot_marker_data_smooth(self, title: str, y_label: str, kine_var: str, fig_num: int) \
         -> matplotlib.figure.Figure:
     """Plot smoothed kinematic (position, velocity, acceleration) marker data."""
     fig = plt.figure(num=fig_num)
     ax = fig.subplots(3, 1, sharex=True)
     lines_smoothed = marker_graph_init(ax, getattr(self.smoothed.means, kine_var), y_label,
                                        x_data=self.filtered_frames, color='limegreen')
     fig.legend([lines_smoothed[0]], ['Smoothed'], 'upper right', labelspacing=0.1)
     add_vicon_start_stop(ax, self.vicon_frame_endpts[0], self.vicon_frame_endpts[1])
     marker_graph_title(fig, title)
     make_interactive()
     return fig
 def plot_cov(self, title: str, y_labels: Sequence[str], fig_num: int) -> matplotlib.figure.Figure:
     """Plot overlayed variance of filtered and smoothed kinematic variables (position, velocity, acceleration) in
     separate rows with 3 columns for each spatial dimension (3x3). """
     fig = plt.figure(num=fig_num)
     ax = fig.subplots(3, 3, sharex='all', sharey='row')
     lines_filtered = cov_trend_graph_init(ax, self.filtered.covars, self.filtered_frames, y_labels, np.sqrt,
                                           color='red')
     lines_smooth = cov_trend_graph_add(ax, self.smoothed.covars, self.filtered_frames, np.sqrt, color='limegreen')
     fig.legend((lines_filtered[0][0], lines_smooth[0][0]), ('Filtered', 'Smoothed'), 'upper right',
                labelspacing=0.1, ncol=2)
     add_vicon_start_stop(ax, self.vicon_frame_endpts[0], self.vicon_frame_endpts[1])
     marker_graph_title(fig, title)
     make_interactive()
     return fig