Exemplo n.º 1
0
    def plot2axes(self,
                  axes: plt.Axes = None,
                  edgecolor: str = 'black',
                  fill: bool = False,
                  plot_peaks: bool = True):
        """Plot the circle to an axes.

        Parameters
        ----------
        axes : matplotlib.Axes, None
            The axes to plot on. If None, will create a new figure of the image array.
        edgecolor : str
            Color of the Circle; must be a valid matplotlib color.
        fill : bool
            Whether to fill the circle. matplotlib keyword.
        plot_peaks : bool
            If True, plots the found peaks as well.
        """
        if axes is None:
            fig, axes = plt.subplots()
            axes.imshow(self.image_array)
        axes.add_patch(
            mpl_Circle((self.center.x, self.center.y),
                       edgecolor=edgecolor,
                       radius=self.radius,
                       fill=fill))
        if plot_peaks:
            x_locs = [peak.x for peak in self.peaks]
            y_locs = [peak.y for peak in self.peaks]
            axes.autoscale(enable=False)
            axes.scatter(x_locs, y_locs, s=40, marker='x', c=edgecolor)
Exemplo n.º 2
0
    def plot2axes(self,
                  axes: plt.Axes = None,
                  edgecolor: str = 'black',
                  fill: bool = False,
                  plot_peaks: bool = True):
        """Add 2 circles to the axes: one at the maximum and minimum radius of the ROI.

        See Also
        --------
        :meth:`~pylinac.core.profile.CircleProfile.plot2axes` : Further parameter info.
        """
        if axes is None:
            fig, axes = plt.subplots()
            axes.imshow(self.image_array)
        axes.add_patch(
            mpl_Circle((self.center.x, self.center.y),
                       edgecolor=edgecolor,
                       radius=self.radius * (1 + self.width_ratio),
                       fill=fill))
        axes.add_patch(
            mpl_Circle((self.center.x, self.center.y),
                       edgecolor=edgecolor,
                       radius=self.radius * (1 - self.width_ratio),
                       fill=fill))
        if plot_peaks:
            x_locs = [peak.x for peak in self.peaks]
            y_locs = [peak.y for peak in self.peaks]
            axes.autoscale(enable=False)
            axes.scatter(x_locs, y_locs, s=20, marker='x', c=edgecolor)
Exemplo n.º 3
0
    def plot_analyzed_subimage(self, subimage: str='wobble', ax: plt.Axes=None, show: bool=True):
        """Plot a subimage of the starshot analysis. Current options are the zoomed out image and the zoomed in image.

        Parameters
        ----------
        subimage : str
            If 'wobble', will show a zoomed in plot of the wobble circle.
            Any other string will show the zoomed out plot.
        ax : None, matplotlib Axes
            If None (default), will create a new figure to plot on, otherwise plot to the passed axes.
        """
        if ax is None:
            fig, ax = plt.subplots()
        # show analyzed image
        ax.imshow(self.image.array, cmap=get_dicom_cmap())
        self.lines.plot(ax)
        self.wobble.plot2axes(ax, edgecolor='green')
        self.circle_profile.plot2axes(ax, edgecolor='green')
        ax.autoscale(tight=True)
        ax.axis('off')

        # zoom in if wobble plot
        if subimage == 'wobble':
            xlims = [self.wobble.center.x + self.wobble.diameter, self.wobble.center.x - self.wobble.diameter]
            ylims = [self.wobble.center.y + self.wobble.diameter, self.wobble.center.y - self.wobble.diameter]
            ax.set_xlim(xlims)
            ax.set_ylim(ylims)
            ax.axis('on')

        if show:
            plt.show()
Exemplo n.º 4
0
def generate_correlation_plot(axes: plt.Axes, window_metrics: pd.DataFrame):
    """
    Creates plot that demonstrates correlation between fixation counts and average fixation duration.

    :param axes: the axes to plot on
    :param window_metrics: the pre-cleaned data
    :return: None
    """
    plt.sca(axes)

    min_fix_dur = window_metrics[AVERAGE_FIX_DUR].min()  # left
    max_fix_dur = window_metrics[AVERAGE_FIX_DUR].max()  # right
    min_fix_count = window_metrics[FIXATION_COUNTS].min()  # bottom
    max_fix_count = window_metrics[FIXATION_COUNTS].max()  # top

    axes.set_title("Overview of Participant Visual Effort")

    x_mid = (max_fix_dur + min_fix_dur) // 2
    y_mid = (max_fix_count + min_fix_count) // 2

    # Background quadrant colors
    bars = axes.bar(x=(x_mid, min_fix_dur, min_fix_dur, x_mid),
                    height=y_mid - min_fix_count,
                    bottom=(y_mid, y_mid, min_fix_count, min_fix_count),
                    width=x_mid - min_fix_dur,
                    color=get_quadrant_color_map().values(),
                    align='edge',
                    alpha=.3,
                    zorder=1)

    # Vertical line for quadrants
    axes.plot([x_mid, x_mid], [min_fix_count, max_fix_count],
              color="black",
              zorder=2)

    # Horizontal line for quadrants
    axes.plot([min_fix_dur, max_fix_dur], [y_mid, y_mid],
              color="black",
              zorder=3)

    legend = plt.legend(
        bars,
        ("Slow Comprehension\nComplexity\nImportance\nConfusion",
         "Fast Comprehension\nSimplicity\nImportance\nPossible confusion",
         "Fast Comprehension\nSimplicity\nUnimportance",
         "Slow Comprehension\nComplexity\nUnimportance"),
        loc='center left',
        bbox_to_anchor=(1, 0.5))

    for lh in legend.legendHandles:
        lh.set_alpha(1)

    axes.scatter(window_metrics[AVERAGE_FIX_DUR],
                 window_metrics[FIXATION_COUNTS],
                 zorder=4)
    axes.set_xlabel("Mean Fixation Duration (ms)", fontsize="large")
    axes.set_ylabel("Fixation Count", fontsize="large")
    axes.autoscale(tight=True)
Exemplo n.º 5
0
def set_windowed_x_axis(axes: plt.Axes):
    """
    A helper function for showing markers on windowed data.
    In particular, we show two-minute segments with the major
    indicator and the proper window size with the minor indicator

    :param axes:
    :return:
    """
    seconds = int(WINDOW[:-1])
    axes.xaxis.set_major_locator(MultipleLocator(2))
    axes.xaxis.set_minor_locator(MultipleLocator(seconds / 60))
    axes.autoscale(tight=True, axis="x")
Exemplo n.º 6
0
def plot_scenario(ex, ax: plt.Axes = None, *, figsize=(12, 8)):
    """
    Plot the source position, sensor position and room dimensions from an
    SMS-WSJ example in the (x, y) plane, i.e. the z-axis is ignored.

    Args:
        ex: An example from SMS-WSJ
        ax:

    Returns:

    """

    if ax is None:
        ax = plt.subplots(1, figsize=figsize)[1]

    speaker_id_to_source_position = {}
    for i, source_position in enumerate(np.array(ex['source_position']).T):
        x, y, z = source_position
        speaker_id = ex["speaker_id"][i]
        if speaker_id in speaker_id_to_source_position:
            np.testing.assert_equal(
                source_position, speaker_id_to_source_position[speaker_id])
        else:
            speaker_id_to_source_position[speaker_id] = source_position
            ax.scatter(x, y, label=f'Speaker {speaker_id}')

    xs, ys, zs = np.array(ex['sensor_position'])
    ax.scatter(xs, ys, label=f'Microphones')

    room_dimensions = ex['room_dimensions']
    (x,), (y,), (z,) = room_dimensions
    # Draw the wall
    w = 0.30
    ax.add_patch(matplotlib.patches.Polygon(np.array([
        (0, 0), (x, 0), (x, y), (0, y), (0, -w), (-w, -w), (-w, y+w),
        (x+w, y+w), (x+w, -w), (0, -w)
    ]), fill=False, hatch='/', linewidth=0))
    ax.add_patch(matplotlib.patches.Rectangle((0, 0), x, y, fill=None))

    ax.set(title=f'Dataset: {ex["dataset"]!r}, ExID: {ex["example_id"]!r}, RT60: {ex["sound_decay_time"]}')
    ax.autoscale(tight=True)
    ax.set_aspect('equal')
    ax.legend()
    return ax
Exemplo n.º 7
0
    def _plot_analyzed_subimage(self,
                                subimage: str,
                                show: bool = True,
                                ax: plt.Axes = None):
        """Plot an individual piece of the VMAT analysis.

        Parameters
        ----------
        subimage : str
            Specifies which image to plot.
        show : bool
            Whether to actually plot the image.
        ax : matplotlib Axes, None
            If None (default), creates a new figure to plot to, otherwise plots to the given axes.
        """
        plt.ioff()
        if ax is None:
            fig, ax = plt.subplots()

        # plot DMLC or OPEN image
        if subimage in (DMLC, OPEN):
            if subimage == DMLC:
                img = self.dmlc_image
            elif subimage == OPEN:
                img = self.open_image
            ax.imshow(img, cmap=get_dicom_cmap())
            self._draw_segments(ax)
            plt.sca(ax)
            plt.axis('off')
            plt.tight_layout()

        # plot profile
        elif subimage == PROFILE:
            dmlc_prof, open_prof = self._median_profiles(
                (self.dmlc_image, self.open_image))
            ax.plot(dmlc_prof.values, label='DMLC')
            ax.plot(open_prof.values, label='Open')
            ax.autoscale(axis='x', tight=True)
            ax.legend(loc=8, fontsize='large')
            ax.grid()

        if show:
            plt.show()
Exemplo n.º 8
0
    def plot2axes(self, axes: plt.Axes=None, edgecolor: str='black', fill: bool=False, plot_peaks: bool=True):
        """Add 2 circles to the axes: one at the maximum and minimum radius of the ROI.

        See Also
        --------
        :meth:`~pylinac.core.profile.CircleProfile.plot2axes` : Further parameter info.
        """
        if axes is None:
            fig, axes = plt.subplots()
            axes.imshow(self.image_array)
        axes.add_patch(mpl_Circle((self.center.x, self.center.y), edgecolor=edgecolor, radius=self.radius*(1+self.width_ratio),
                                  fill=fill))
        axes.add_patch(mpl_Circle((self.center.x, self.center.y), edgecolor=edgecolor, radius=self.radius*(1-self.width_ratio),
                                  fill=fill))
        if plot_peaks:
            x_locs = [peak.x for peak in self.peaks]
            y_locs = [peak.y for peak in self.peaks]
            axes.autoscale(enable=False)
            axes.scatter(x_locs, y_locs, s=20, marker='x', c=edgecolor)
Exemplo n.º 9
0
    def plot_analyzed_subimage(self,
                               subimage: str = 'wobble',
                               ax: plt.Axes = None,
                               show: bool = True):
        """Plot a subimage of the starshot analysis. Current options are the zoomed out image and the zoomed in image.

        Parameters
        ----------
        subimage : str
            If 'wobble', will show a zoomed in plot of the wobble circle.
            Any other string will show the zoomed out plot.
        ax : None, matplotlib Axes
            If None (default), will create a new figure to plot on, otherwise plot to the passed axes.
        """
        if ax is None:
            fig, ax = plt.subplots()
        # show analyzed image
        ax.imshow(self.image.array, cmap=get_dicom_cmap())
        self.lines.plot(ax)
        self.wobble.plot2axes(ax, edgecolor='green')
        self.circle_profile.plot2axes(ax, edgecolor='green')
        ax.autoscale(tight=True)
        ax.axis('off')

        # zoom in if wobble plot
        if subimage == 'wobble':
            xlims = [
                self.wobble.center.x + self.wobble.diameter,
                self.wobble.center.x - self.wobble.diameter
            ]
            ylims = [
                self.wobble.center.y + self.wobble.diameter,
                self.wobble.center.y - self.wobble.diameter
            ]
            ax.set_xlim(xlims)
            ax.set_ylim(ylims)
            ax.axis('on')

        if show:
            plt.show()
Exemplo n.º 10
0
    def _plot_analyzed_subimage(self, subimage: str, show: bool=True, ax: plt.Axes=None):
        """Plot an individual piece of the VMAT analysis.

        Parameters
        ----------
        subimage : str
            Specifies which image to plot.
        show : bool
            Whether to actually plot the image.
        ax : matplotlib Axes, None
            If None (default), creates a new figure to plot to, otherwise plots to the given axes.
        """
        plt.ioff()
        if ax is None:
            fig, ax = plt.subplots()

        # plot DMLC or OPEN image
        if subimage in (DMLC, OPEN):
            if subimage == DMLC:
                img = self.dmlc_image
            elif subimage == OPEN:
                img = self.open_image
            ax.imshow(img, cmap=get_dicom_cmap())
            self._draw_segments(ax)
            plt.sca(ax)
            plt.axis('off')
            plt.tight_layout()

        # plot profile
        elif subimage == PROFILE:
            dmlc_prof, open_prof = self._median_profiles((self.dmlc_image, self.open_image))
            ax.plot(dmlc_prof.values, label='DMLC')
            ax.plot(open_prof.values, label='Open')
            ax.autoscale(axis='x', tight=True)
            ax.legend(loc=8, fontsize='large')
            ax.grid()

        if show:
            plt.show()
Exemplo n.º 11
0
    def plot2axes(self, axes: plt.Axes=None, edgecolor: str='black', fill: bool=False, plot_peaks: bool=True):
        """Plot the circle to an axes.

        Parameters
        ----------
        axes : matplotlib.Axes, None
            The axes to plot on. If None, will create a new figure of the image array.
        edgecolor : str
            Color of the Circle; must be a valid matplotlib color.
        fill : bool
            Whether to fill the circle. matplotlib keyword.
        plot_peaks : bool
            If True, plots the found peaks as well.
        """
        if axes is None:
            fig, axes = plt.subplots()
            axes.imshow(self.image_array)
        axes.add_patch(
            mpl_Circle((self.center.x, self.center.y), edgecolor=edgecolor, radius=self.radius, fill=fill))
        if plot_peaks:
            x_locs = [peak.x for peak in self.peaks]
            y_locs = [peak.y for peak in self.peaks]
            axes.autoscale(enable=False)
            axes.scatter(x_locs, y_locs, s=40, marker='x', c=edgecolor)