def test_get_spectra_selection_removes_wrong_workspace_types_from_list(
         self):
     table = WorkspaceFactory.Instance().createTable()
     workspaces = [self._single_spec_ws, table]
     self.assertEqual(
         get_spectra_selection(workspaces).workspaces,
         [self._single_spec_ws])
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    def test_get_spectra_selection_cancelled_returns_None(
            self, mock_SpectraSelectionDialog):
        # a new instance of the mock created inside get_user_action_and_selection will return
        # dialog_mock
        mock_SpectraSelectionDialog.return_value = mock_SpectraSelectionDialog
        mock_SpectraSelectionDialog.Rejected = QDialog.Rejected
        mock_SpectraSelectionDialog.exec_.return_value = mock_SpectraSelectionDialog.Rejected
        mock_SpectraSelectionDialog.decision = QDialog.Rejected
        mock_SpectraSelectionDialog.selection = None

        selection = get_spectra_selection([self._multi_spec_ws])

        mock_SpectraSelectionDialog.exec_.assert_called_once_with()
        self.assertTrue(selection is None)
Exemplo n.º 4
0
    def test_get_spectra_selection_does_not_use_dialog_for_multiple__single_spectrum(
            self, dialog_mock):
        spectra_1 = ExtractSpectra(InputWorkspace=self._multi_spec_ws,
                                   StartWorkspaceIndex=0,
                                   EndWorkspaceIndex=0)
        spectra_2 = ExtractSpectra(InputWorkspace=self._multi_spec_ws,
                                   StartWorkspaceIndex=1,
                                   EndWorkspaceIndex=1)
        dialog_mock.get_compatible_workspaces.return_value = [
            spectra_1, spectra_2
        ]
        selection = get_spectra_selection([spectra_1, spectra_2])

        dialog_mock.assert_not_called()
        self.assertEqual([0], selection.wksp_indices)
        self.assertEqual([spectra_1, spectra_2], selection.workspaces)
Exemplo n.º 5
0
def plot_from_names(names,
                    errors,
                    overplot,
                    fig=None,
                    show_colorfill_btn=False):
    """
    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
    """
    workspaces = AnalysisDataService.Instance().retrieveWorkspaces(
        names, unrollGroups=True)
    try:
        selection = get_spectra_selection(
            workspaces,
            show_colorfill_btn=show_colorfill_btn,
            overplot=overplot)
    except Exception as exc:
        LOGGER.warning(format(str(exc)))
        selection = None

    if selection is None:
        return None
    elif selection == 'colorfill':
        return pcolormesh_from_names(names)

    return plot(selection.workspaces,
                spectrum_nums=selection.spectra,
                wksp_indices=selection.wksp_indices,
                errors=errors,
                overplot=overplot,
                fig=fig,
                tiled=selection.plot_type == selection.Tiled,
                waterfall=selection.plot_type == selection.Waterfall)
Exemplo n.º 6
0
def plot_from_names(names,
                    errors,
                    overplot,
                    fig=None,
                    show_colorfill_btn=False,
                    advanced=False,
                    superplot=False):
    """
    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
    :param advanced: If true then the advanced options will be shown in the spectra selector dialog.
    :return: The figure containing the plot or None if selection was cancelled
    """
    # Get workspaces from ADS with names
    workspaces = AnalysisDataService.Instance().retrieveWorkspaces(
        names, unrollGroups=True)

    try:
        # Get selected spectra from all MatrixWorkspaces
        selection = get_spectra_selection(
            workspaces,
            show_colorfill_btn=show_colorfill_btn,
            overplot=overplot,
            advanced=advanced)
    except Exception as exc:
        LOGGER.warning(format(str(exc)))
        selection = None

    if selection is None:
        return None
    elif selection == 'colorfill':
        # plot mesh for color fill
        return pcolormesh_from_names(names)

    log_values = None

    if advanced:
        errors = selection.errors

        nums = selection.spectra if selection.spectra is not None else selection.wksp_indices

        if selection.log_name not in ['Workspace name', 'Workspace index']:
            log_values = []
            counter = 0
            for workspace in workspaces:
                for _ in nums:
                    if selection.custom_log_values is not None:
                        log_values.append(
                            get_single_workspace_log_value(
                                counter,
                                log_values=selection.custom_log_values))
                        counter += 1
                    else:
                        log_values.append(
                            get_single_workspace_log_value(
                                1,
                                matrix_ws=workspace,
                                log_name=selection.log_name))

    if selection.plot_type == selection.Surface or selection.plot_type == selection.Contour:
        if selection.spectra is not None:
            plot_index = workspaces[0].getIndexFromSpectrumNumber(
                selection.spectra[0])
        else:
            plot_index = selection.wksp_indices[0]

        # import here to avoid circular import
        from mantid.plots.surfacecontourplots import plot as plot_surface_or_contour
        return plot_surface_or_contour(selection.plot_type, int(plot_index),
                                       selection.axis_name, selection.log_name,
                                       selection.custom_log_values, workspaces)
    else:
        return plot(selection.workspaces,
                    spectrum_nums=selection.spectra,
                    wksp_indices=selection.wksp_indices,
                    errors=errors,
                    overplot=overplot,
                    fig=fig,
                    tiled=selection.plot_type == selection.Tiled,
                    waterfall=selection.plot_type == selection.Waterfall,
                    log_name=selection.log_name,
                    log_values=log_values,
                    superplot=superplot)