Пример #1
0
    def plot_amplitude(self, refinement_roi=True, **kwargs):
        """
        Plot the amplitude for each g-vector previously set.

        Parameters
        ----------
        refinement_roi : bool, optional
            If True, also add the refinement ROI. If no refinement ROI have
            been previously, a rectangular ROI is added in the middle of the
            image. The default is True.

        **kwargs
            The keywords argument are passed to the plot method of the hyperspy
            Signal2D.

        Returns
        -------
        None.

        """
        for amplitude in self.amplitudes.values():
            if 'cmap' not in kwargs:
                kwargs['cmap'] = 'viridis'
            amplitude.plot(**kwargs)

            if refinement_roi and self.refinement_roi is not None:
                add_roi_to_signal_plot(amplitude, self.refinement_roi)
Пример #2
0
    def set_refinement_roi(self, roi=None):
        """
        Set the area where the phase is refined. If the phases are displayed,
        the ROI is added on the phase figure.

        Parameters
        ----------
        roi : hyperspy ROI or list of float or None, optional
            If list of float, a rectangular ROI is created and the list of
            float is used to initialised the ROI. If None, a rectangular ROI
            is set in the middle of the image. The default is None.

        Returns
        -------
        None.

        """
        if roi is None:
            roi = self._get_default_refinement_roi()
        elif not isinstance(roi, BaseROI):
            roi = hs.roi.RectangularROI(*roi)

        self.refinement_roi = roi

        for phase in self.phases.values():
            add_roi_to_signal_plot(phase, roi)

        for amplitude in self.amplitudes.values():
            add_roi_to_signal_plot(phase, roi)
Пример #3
0
    def plot_power_spectrum(self, **kwargs):
        """
        Plot the power spectrum of the signal. As a convenience, only the
        central part of the power spectrum is displayed.

        Parameters
        ----------
        *args, **kwargs
            The keywords argument are passed to the plot method of the
            hyperspy Signal2D.

        Returns
        -------
        None.

        """
        if self.fft_signal is None:
            self.set_fft(shift=True)

        self.fft_signal.plot(power_spectrum=True, **kwargs)
        signal_axes = self.fft_signal.axes_manager.signal_axes
        start = [relative2value(axis, 3 / 8) for axis in signal_axes]
        end = [relative2value(axis, 1 - 3 / 8) for axis in signal_axes]

        ax = self.fft_signal._plot.signal_plot.ax
        ax.set_xlim(start[0], end[0])
        # hyperspy image plotting start from top
        ax.set_ylim(-start[1], -end[1])

        for roi in self.rois.values():
            add_roi_to_signal_plot(self.fft_signal, roi, snap=False)
Пример #4
0
    def add_rois(self, roi_args=None):
        """
        Add the ROIs on the power spectrum to select the two g vectors. The
        radius of the ROIs defines the sigma of the Gaussian mask.

        Parameters
        ----------
        roi_args : {str, list of list of float, None}, optional
            Parameters used to create the ROIs. If str, use this value to set
            the ROIs at this spacial frequency. If list of list of float,
            this needs to be a list of two lists of float which will be pass
            to :py:class:`hyperspy.roi.CircleROI` - see examples. If None,
            set the ROIs at a spacing frequencies corresponding to 2 Å.
            Default is None.

        Returns
        -------
        None.

        Examples
        --------
        >>> s = gpa.datasets.get_atomic_resolution_tem_signal2d()
        >>> gpa_tool = gpa.GeometricalPhaseAnalysisTool(s)
        >>> gpa_tool.set_fft(True)
        >>> gpa_tool.plot_power_spectrum()

        Specify the ROI arguments (see CircleROI documentation)

        >>> gpa_tool.add_rois([[4.2793, 1.1138, 2.0], [-1.07473, 4.20123, 2.0]])

        Specify a spatial frequency

        >>> gpa_tool.add_rois(0.6)

        """
        if roi_args is None:
            ureg = pint.UnitRegistry()
            value = 2.0 * ureg.angstrom
            value = value.to(self.signal.axes_manager[0].units).magnitude
            roi_args = 1 / value
        if isinstance(roi_args, float):
            roi_args = [[roi_args, 0, 2], [0, roi_args, 2]]
        for i, args in enumerate(roi_args, start=1):
            roi = hs.roi.CircleROI(*args)
            self.rois[f'g{i}'] = roi
            if self.fft_signal is not None:
                add_roi_to_signal_plot(self.fft_signal, roi, snap=False)

            if self.synchronise_roi_radius:
                roi.events.changed.connect(self._sync_radius_roi,
                                           {'roi': 'roi'})
Пример #5
0
def test_plot_phase_amplitude_refinement_roi(gpa_tool, rois, refinement_roi):
    gpa_tool.add_rois(rois[:1])
    gpa_tool.calculate_phase()
    phase = gpa_tool.phases['g1']
    with pytest.raises(ValueError):
        add_roi_to_signal_plot(phase, rois[0])

    phase.plot()
    assert phase._plot is not None
    assert phase._plot.is_active
    add_roi_to_signal_plot(phase, refinement_roi)

    amplitude = gpa_tool.amplitudes['g1']
    with pytest.raises(ValueError):
        add_roi_to_signal_plot(amplitude, rois[0])

    amplitude.plot()
    assert amplitude._plot is not None
    assert amplitude._plot.is_active
    add_roi_to_signal_plot(amplitude, refinement_roi)