Exemplo n.º 1
0
    def test_categorizing_of_uncategorized_plot(self, mock_figure_class):
        mock_figures = [mock.Mock(), mock.Mock(), mock.Mock()]
        fig1_mock_manager = mock.Mock()
        # This manager is used to compare the relative order of calls of two differebc functions
        fig1_mock_manager.attach_mock(mock_figures[0].flag_as_kept, 'fig1_kept')
        fig1_mock_manager.attach_mock(mock_figures[0].flag_as_current, 'fig1_current')
        mock_figure_class.side_effect = mock_figures
        cat1 = '1d'
        cat2 = '2d'
        cat1_get_active_figure = set_category(cat1)(GlobalFigureManager.get_active_figure)
        cat2_get_active_figure = set_category(cat2)(GlobalFigureManager.get_active_figure)

        # test is an arbitrary method just to make sure the correct figures are returned

        cat1_get_active_figure().test(1)  # create a figure of category 1
        cat2_get_active_figure().test(2)  # create a figure of category 2
        GlobalFigureManager.set_figure_as_kept(2) # now there is no active figure

        GlobalFigureManager.get_active_figure().test(3) # create an uncategorized figure
        cat1_get_active_figure().test(4) # the previously uncategorized figure should now be categorized as cat1

        mock_figures[0].test.assert_has_calls([call(1)])
        mock_figures[1].test.assert_has_calls([call(2)])
        mock_figures[2].test.assert_has_calls([call(3), call(4)])

        self.assertTrue(fig1_mock_manager.mock_calls[-1] == call.fig1_kept())  # assert final status of fig1 is kept
        self.assertTrue(GlobalFigureManager._active_figure == 3)
Exemplo n.º 2
0
    def test_make_current_with_single_category(self, mock_figure_class):
        mock_figures = [mock.Mock(), mock.Mock()]
        # These manager is used to compare the relative order of calls of two different functions
        mock_managers = [mock.Mock(), mock.Mock()]

        for i in range(len(mock_figures)):
            mock_managers[i].attach_mock(mock_figures[i].flag_as_kept, 'fig_kept')
            mock_managers[i].attach_mock(mock_figures[i].flag_as_current, 'fig_current')
        mock_figure_class.side_effect = mock_figures
        cat1 = '1d'
        cat1_get_active_figure = set_category(cat1)(GlobalFigureManager.get_active_figure)
        # test is an arbitrary method just to make sure the correct figures are returned

        cat1_get_active_figure().test(1)  # create a figure of category 1
        GlobalFigureManager.set_figure_as_kept(1)  # now there is no active figure
        cat1_get_active_figure().test(2)  # this command should go to a new figure

        self.assertTrue(mock_managers[0].mock_calls[-1] == call.fig_kept())     # assert fig1 now displays kept
        self.assertTrue(mock_managers[1].mock_calls[-1] == call.fig_current())  # assert fig2 now displays current

        GlobalFigureManager.set_figure_as_current(1)
        self.assertTrue(mock_managers[0].mock_calls[-1] == call.fig_current())     # assert fig1 now displays current
        self.assertTrue(mock_managers[1].mock_calls[-1] == call.fig_kept())        # assert fig2 now displays kept

        cat1_get_active_figure().test(3)                # This should go to fig1
        GlobalFigureManager.get_active_figure().test(4)       # This should go to fig1 as well

        mock_figures[0].test.assert_has_calls([call(1), call(3), call(4)])
        mock_figures[1].test.assert_has_calls([call(2)])

        self.assertTrue(GlobalFigureManager._active_figure == 1)
Exemplo n.º 3
0
def pcolormesh(axes, workspace, *args, **kwargs):
    """
    Same as the CLI PlotSlice but returns the relevant axes object.
    """
    from mslice.app.presenters import get_slice_plotter_presenter, cli_slice_plotter_presenter
    _check_workspace_name(workspace)
    workspace = get_workspace_handle(workspace)
    _check_workspace_type(workspace, HistogramWorkspace)

    # slice cache needed from main slice plotter presenter
    if is_gui() and GlobalFigureManager.get_active_figure().plot_handler is not None:
        cli_slice_plotter_presenter._slice_cache = app.MAIN_WINDOW.slice_plotter_presenter._slice_cache
    else:
        # Needed so the figure manager knows about the slice plot handler
        create_slice_figure(workspace.name[2:], get_slice_plotter_presenter())

    slice_cache = get_slice_plotter_presenter().get_slice_cache(workspace)

    intensity = kwargs.pop('intensity', None)
    temperature = kwargs.pop('temperature', None)

    if temperature is not None:
        get_slice_plotter_presenter().set_sample_temperature(workspace.name[2:], temperature)

    if intensity is not None and intensity != 's(q,e)':
        workspace = getattr(slice_cache, _intensity_to_workspace[intensity])
        plot_window = GlobalFigureManager.get_active_figure().window
        plot_handler = GlobalFigureManager.get_active_figure().plot_handler
        intensity_action = getattr(plot_window, _intensity_to_action[intensity])
        plot_handler.set_intensity(intensity_action)
        intensity_action.setChecked(True)

        # Set intensity properties for generated script to use
        if not is_gui():
            for key, value in _function_to_intensity.items():
                if value == intensity:
                    intensity_method = key
                    break
            plot_handler.intensity = True
            plot_handler.intensity_method = intensity_method
            plot_handler.temp = temperature
            plot_handler.temp_dependent = True if temperature is not None else False
            plot_handler._slice_plotter_presenter._slice_cache[plot_handler.ws_name].colourmap = kwargs.get('cmap')

    if not workspace.is_PSD and not slice_cache.rotated:
        workspace = Transpose(OutputWorkspace=workspace.name, InputWorkspace=workspace, store=False)
    plotfunctions.pcolormesh(axes, workspace.raw_ws, *args, **kwargs)
    axes.set_title(workspace.name[2:], picker=SLICE_PICKER_TOL_PTS)
    x_axis = slice_cache.energy_axis if slice_cache.rotated else slice_cache.momentum_axis
    y_axis = slice_cache.momentum_axis if slice_cache.rotated else slice_cache.energy_axis
    axes.get_xaxis().set_units(x_axis.units)
    axes.get_yaxis().set_units(y_axis.units)
    # labels
    axes.set_xlabel(get_display_name(x_axis), picker=SLICE_PICKER_TOL_PTS)
    axes.set_ylabel(get_display_name(y_axis), picker=SLICE_PICKER_TOL_PTS)
    axes.set_xlim(x_axis.start, x_axis.end)
    axes.set_ylim(y_axis.start, y_axis.end)
    return axes.collections[0]  # Quadmesh object
Exemplo n.º 4
0
    def test_close_non_existant_window_fail(self,mock_figure_class):
        mock_figures = [mock.Mock()]
        mock_figure_class.side_effect = mock_figures
        # Get a figure
        fig1 = GlobalFigureManager.get_active_figure()
        # check that getting the active window doesnt bring up a new one
        self.assertTrue(GlobalFigureManager.get_active_figure() == fig1)
        self.assertRaises(KeyError, GlobalFigureManager.figure_closed, 2)
        fig2 = GlobalFigureManager.get_active_figure()

        self.assertTrue(fig1 == mock_figures[0])
        self.assertTrue(fig2 == mock_figures[0])
Exemplo n.º 5
0
    def test_close_non_existant_window_fail(self, mock_figure_class):
        mock_figures = [mock.Mock()]
        mock_figure_class.side_effect = mock_figures
        # Get a figure
        fig1 = GlobalFigureManager.get_active_figure()
        # check that getting the active window doesnt bring up a new one
        self.assertTrue(GlobalFigureManager.get_active_figure() == fig1)
        self.assertRaises(KeyError, GlobalFigureManager.figure_closed, 2)
        fig2 = GlobalFigureManager.get_active_figure()

        self.assertTrue(fig1 == mock_figures[0])
        self.assertTrue(fig2 == mock_figures[0])
Exemplo n.º 6
0
    def test_close_only_window(self, mock_figure_class):
        mock_figures = [mock.Mock(), mock.Mock()]
        mock_figure_class.side_effect = mock_figures
        # Get a figure
        fig1 = GlobalFigureManager.get_active_figure()
        # check that getting the active window doesnt bring up a new one
        self.assertTrue(GlobalFigureManager.get_active_figure() == fig1)
        GlobalFigureManager.figure_closed(1)
        fig2 = GlobalFigureManager.get_active_figure()

        self.assertTrue(fig1 == mock_figures[0])
        self.assertTrue(fig2 == mock_figures[1])
Exemplo n.º 7
0
    def test_close_only_window(self,mock_figure_class):
        mock_figures = [mock.Mock(), mock.Mock()]
        mock_figure_class.side_effect = mock_figures
        # Get a figure
        fig1 = GlobalFigureManager.get_active_figure()
        # check that getting the active window doesnt bring up a new one
        self.assertTrue(GlobalFigureManager.get_active_figure() == fig1)
        GlobalFigureManager.figure_closed(1)
        fig2 = GlobalFigureManager.get_active_figure()

        self.assertTrue(fig1 == mock_figures[0])
        self.assertTrue(fig2 == mock_figures[1])
Exemplo n.º 8
0
    def test_create_single_unclassified_plot_success(self, mock_figure_class):
        mock_figures = [mock.Mock()]
        mock_figure_class.side_effect = mock_figures

        GlobalFigureManager.get_figure_number()
        self.assertTrue(1 in GlobalFigureManager.all_figure_numbers()) #Check that a new figure with number=1 was created
        self.assertRaises(KeyError, GlobalFigureManager.get_category, 1) #Check that figure has no category
        self.assertTrue(GlobalFigureManager.get_active_figure() == mock_figures[0]) # Check that it is set as the active figure
Exemplo n.º 9
0
    def grid(self, b=None, which='major', axis='both', **kwargs):
        Axes.grid(self, b, which, axis, **kwargs)

        plot_handler = GlobalFigureManager.get_active_figure().plot_handler
        if plot_handler is not None and not is_gui():
            if axis == 'x':
                plot_handler.manager._xgrid = b
            elif axis == 'y':
                plot_handler.manager._ygrid = b
Exemplo n.º 10
0
 def test_create_single_categorised_figure(self,mock_figure_class):
     mock_figures = [mock.Mock()]
     mock_figure_class.side_effect = mock_figures
     category = '1d'
     # The following line is equivalent to applying the decorator setcategory with the parameter category
     # to function GlobalFigureManager.get_active_figure
     categorised_get_active_figure = set_category(category)(GlobalFigureManager.get_active_figure)
     fig = categorised_get_active_figure()
     self.assertTrue(fig == mock_figures[0]) # Assert Figure object came from right place
     self.assertTrue(GlobalFigureManager.get_category(1) == category)
     self.assertTrue(GlobalFigureManager.get_active_figure() == mock_figures[0]) # Check that it is set as the active figure
Exemplo n.º 11
0
    def test_make_current_with_single_category(self, mock_figure_class):
        mock_figures = [mock.Mock(), mock.Mock()]
        # These manager is used to compare the relative order of calls of two different functions
        mock_managers = [mock.Mock(), mock.Mock()]

        for i in range(len(mock_figures)):
            mock_managers[i].attach_mock(mock_figures[i].flag_as_kept,
                                         'fig_kept')
            mock_managers[i].attach_mock(mock_figures[i].flag_as_current,
                                         'fig_current')
        mock_figure_class.side_effect = mock_figures
        cat1 = '1d'
        cat1_get_active_figure = set_category(cat1)(
            GlobalFigureManager.get_active_figure)
        # test is an arbitrary method just to make sure the correct figures are returned

        cat1_get_active_figure().test(1)  # create a figure of category 1
        GlobalFigureManager.set_figure_as_kept(
            1)  # now there is no active figure
        cat1_get_active_figure().test(
            2)  # this command should go to a new figure

        self.assertTrue(mock_managers[0].mock_calls[-1] ==
                        call.fig_kept())  # assert fig1 now displays kept
        self.assertTrue(mock_managers[1].mock_calls[-1] ==
                        call.fig_current())  # assert fig2 now displays current

        GlobalFigureManager.set_figure_as_current(1)
        self.assertTrue(mock_managers[0].mock_calls[-1] ==
                        call.fig_current())  # assert fig1 now displays current
        self.assertTrue(mock_managers[1].mock_calls[-1] ==
                        call.fig_kept())  # assert fig2 now displays kept

        cat1_get_active_figure().test(3)  # This should go to fig1
        GlobalFigureManager.get_active_figure().test(
            4)  # This should go to fig1 as well

        mock_figures[0].test.assert_has_calls([call(1), call(3), call(4)])
        mock_figures[1].test.assert_has_calls([call(2)])

        self.assertTrue(GlobalFigureManager._active_figure == 1)
Exemplo n.º 12
0
    def test_create_single_unclassified_plot_success(self, mock_figure_class):
        mock_figures = [mock.Mock()]
        mock_figure_class.side_effect = mock_figures

        GlobalFigureManager.get_figure_number()
        self.assertTrue(1 in GlobalFigureManager.all_figure_numbers()
                        )  #Check that a new figure with number=1 was created
        self.assertRaises(KeyError, GlobalFigureManager.get_category,
                          1)  #Check that figure has no category
        self.assertTrue(
            GlobalFigureManager.get_active_figure() ==
            mock_figures[0])  # Check that it is set as the active figure
Exemplo n.º 13
0
 def set_waterfall(self, isWaterfall=True, x_offset=None, y_offset=None):
     """ Change the plot to/from a waterfall """
     from mslice.plotting.plot_window.cut_plot import CutPlot
     plot_handler = GlobalFigureManager.get_active_figure().plot_handler
     if isinstance(plot_handler, CutPlot):
         plot_handler.waterfall = isWaterfall
         if x_offset is not None:
             plot_handler.waterfall_x = x_offset
         if y_offset is not None:
             plot_handler.waterfall_y = y_offset
         plot_handler.toggle_waterfall()
     else:
         raise RuntimeError('Waterfall plots may only be applied to cuts')
Exemplo n.º 14
0
    def test_create_categorised_figure_then_uncategorised_figure(self,mock_figure_class):
        mock_figures = [mock.Mock(), mock.Mock()]
        mock_figure_class.side_effect = mock_figures
        category = '1d'
        categorised_get_active_figure = set_category(category)(GlobalFigureManager.get_active_figure)

        fig1 = categorised_get_active_figure()
        fig2 = GlobalFigureManager.get_figure_number()
        fig1_number = GlobalFigureManager.number_of_figure(fig1)
        fig2_number = GlobalFigureManager.number_of_figure(fig2)
        self.assertTrue(GlobalFigureManager.get_active_figure() == fig2)
        self.assertTrue(GlobalFigureManager.get_category(fig1_number) == category)
        self.assertRaises(KeyError, GlobalFigureManager.get_category, fig2_number)
        self.assertTrue( fig1_number == 1 and fig2_number == 2)
Exemplo n.º 15
0
    def test_categorizing_of_uncategorized_plot(self, mock_figure_class):
        mock_figures = [mock.Mock(), mock.Mock(), mock.Mock()]
        fig1_mock_manager = mock.Mock()
        # This manager is used to compare the relative order of calls of two differebc functions
        fig1_mock_manager.attach_mock(mock_figures[0].flag_as_kept,
                                      'fig1_kept')
        fig1_mock_manager.attach_mock(mock_figures[0].flag_as_current,
                                      'fig1_current')
        mock_figure_class.side_effect = mock_figures
        cat1 = '1d'
        cat2 = '2d'
        cat1_get_active_figure = set_category(cat1)(
            GlobalFigureManager.get_active_figure)
        cat2_get_active_figure = set_category(cat2)(
            GlobalFigureManager.get_active_figure)

        # test is an arbitrary method just to make sure the correct figures are returned

        cat1_get_active_figure().test(1)  # create a figure of category 1
        cat2_get_active_figure().test(2)  # create a figure of category 2
        GlobalFigureManager.set_figure_as_kept(
            2)  # now there is no active figure

        GlobalFigureManager.get_active_figure().test(
            3)  # create an uncategorized figure
        cat1_get_active_figure().test(
            4
        )  # the previously uncategorized figure should now be categorized as cat1

        mock_figures[0].test.assert_has_calls([call(1)])
        mock_figures[1].test.assert_has_calls([call(2)])
        mock_figures[2].test.assert_has_calls([call(3), call(4)])

        self.assertTrue(
            fig1_mock_manager.mock_calls[-1] ==
            call.fig1_kept())  # assert final status of fig1 is kept
        self.assertTrue(GlobalFigureManager._active_figure == 3)
Exemplo n.º 16
0
 def test_create_single_categorised_figure(self, mock_figure_class):
     mock_figures = [mock.Mock()]
     mock_figure_class.side_effect = mock_figures
     category = '1d'
     # The following line is equivalent to applying the decorator setcategory with the parameter category
     # to function GlobalFigureManager.get_active_figure
     categorised_get_active_figure = set_category(category)(
         GlobalFigureManager.get_active_figure)
     fig = categorised_get_active_figure()
     self.assertTrue(
         fig ==
         mock_figures[0])  # Assert Figure object came from right place
     self.assertTrue(GlobalFigureManager.get_category(1) == category)
     self.assertTrue(
         GlobalFigureManager.get_active_figure() ==
         mock_figures[0])  # Check that it is set as the active figure
Exemplo n.º 17
0
    def recoil(self, workspace, element=None, rmm=None):
        from mslice.app.presenters import get_slice_plotter_presenter
        _check_workspace_name(workspace)
        workspace = get_workspace_handle(workspace)
        _check_workspace_type(workspace, HistogramWorkspace)

        key = _get_overplot_key(element, rmm)

        if rmm is not None:
            plot_handler = GlobalFigureManager.get_active_figure().plot_handler
            plot_handler._arb_nuclei_rmm = rmm

        get_slice_plotter_presenter().add_overplot_line(workspace.name, key, recoil=True, cif=None)

        _update_overplot_checklist(key)
        _update_legend()
Exemplo n.º 18
0
    def test_create_categorised_figure_then_uncategorised_figure(
            self, mock_figure_class):
        mock_figures = [mock.Mock(), mock.Mock()]
        mock_figure_class.side_effect = mock_figures
        category = '1d'
        categorised_get_active_figure = set_category(category)(
            GlobalFigureManager.get_active_figure)

        fig1 = categorised_get_active_figure()
        fig2 = GlobalFigureManager.get_figure_number()
        fig1_number = GlobalFigureManager.number_of_figure(fig1)
        fig2_number = GlobalFigureManager.number_of_figure(fig2)
        self.assertTrue(GlobalFigureManager.get_active_figure() == fig2)
        self.assertTrue(
            GlobalFigureManager.get_category(fig1_number) == category)
        self.assertRaises(KeyError, GlobalFigureManager.get_category,
                          fig2_number)
        self.assertTrue(fig1_number == 1 and fig2_number == 2)
Exemplo n.º 19
0
def GenerateScript(InputWorkspace, filename):
    from mslice.scripting import generate_script
    _check_workspace_name(InputWorkspace)
    workspace_name = get_workspace_handle(InputWorkspace).name[2:]
    plot_handler = GlobalFigureManager.get_active_figure().plot_handler
    generate_script(ws_name=workspace_name, filename=filename, plot_handler=plot_handler)