Example #1
0
def plot_from_names(names, errors, overplot, fig=None):
    """
    Given a list of names of workspaces, raise a dialog asking for the
    a selection of what to plot and then plot it.

    :param names: A list of workspace names
    :param errors: If true then error bars will be plotted on the points
    :param overplot: If true then the add to the current figure if one
                     exists and it is a compatible figure
    :param fig: If not None then use this figure object to plot
    :return: The figure containing the plot or None if selection was cancelled
    """
    if fig and len(fig.axes) > 1:
        LOGGER.warning("Cannot plot workspace on top of Matplotlib subplots.")
        return None

    workspaces = AnalysisDataService.Instance().retrieveWorkspaces(names, unrollGroups=True)
    try:
        selection = get_spectra_selection(workspaces)
    except Exception as exc:
        LOGGER.warning(format(str(exc)))
        selection = None

    if selection is None:
        return None

    return plot(selection.workspaces, spectrum_nums=selection.spectra,
                wksp_indices=selection.wksp_indices,
                errors=errors, overplot=overplot, fig=fig)
Example #2
0
def plot_from_names(names, errors, overplot, fig=None):
    """
    Given a list of names of workspaces, raise a dialog asking for the
    a selection of what to plot and then plot it.

    :param names: A list of workspace names
    :param errors: If true then error bars will be plotted on the points
    :param overplot: If true then the add to the current figure if one
                     exists and it is a compatible figure
    :param fig: If not None then use this figure object to plot
    :return: The figure containing the plot or None if selection was cancelled
    """
    if fig and len(fig.axes) > 1:
        LOGGER.warning("Cannot plot workspace on top of Matplotlib subplots.")
        return None

    workspaces = AnalysisDataService.Instance().retrieveWorkspaces(
        names, unrollGroups=True)
    try:
        selection = get_spectra_selection(workspaces)
    except Exception as exc:
        LOGGER.warning(format(str(exc)))
        selection = None

    if selection is None:
        return None

    return plot(selection.workspaces,
                spectrum_nums=selection.spectra,
                wksp_indices=selection.wksp_indices,
                errors=errors,
                overplot=overplot,
                fig=fig)
    def test_get_spectra_selection_does_not_use_dialog_for_single_spectrum(
            self, dialog_mock):
        selection = get_spectra_selection([self._single_spec_ws])

        dialog_mock.assert_not_called()
        self.assertEqual([0], selection.wksp_indices)
        self.assertEqual([self._single_spec_ws], selection.workspaces)
    def test_get_spectra_selection_cancelled_returns_None(self, dialog_mock):
        # a new instance of the mock created inside get_spectra_selection will return
        # dialog_mock
        dialog_mock.return_value = dialog_mock
        dialog_mock.Rejected = QDialog.Rejected
        dialog_mock.exec_.return_value = dialog_mock.Rejected

        selection = get_spectra_selection([self._multi_spec_ws])

        dialog_mock.exec_.assert_called_once_with()
        self.assertTrue(selection is None)
    def test_get_spectra_selection_cancelled_returns_None(self, dialog_mock):
        # a new instance of the mock created inside get_spectra_selection will return
        # dialog_mock
        dialog_mock.return_value = dialog_mock
        dialog_mock.Rejected = QDialog.Rejected
        dialog_mock.exec_.return_value = dialog_mock.Rejected

        selection = get_spectra_selection([self._multi_spec_ws])

        dialog_mock.exec_.assert_called_once_with()
        self.assertTrue(selection is None)
    def test_get_spectra_selection_does_not_use_dialog_for_single_spectrum(self, dialog_mock):
        selection = get_spectra_selection([self._single_spec_ws])

        dialog_mock.assert_not_called()
        self.assertEqual([0], selection.wksp_indices)
        self.assertEqual([self._single_spec_ws], selection.workspaces)