Esempio n. 1
0
    def setUpClass(cls):
        x = np.linspace(0, 99, 100)
        y = x * 1
        e = y * 0 + 2
        cls.m_workspace = wrap_workspace(
            CreateWorkspace(x, y, e, OutputWorkspace="m_ws"), 'm_ws')

        sim_workspace = CreateSimulationWorkspace(Instrument='MAR',
                                                  BinParams=[-10, 1, 10],
                                                  UnitX='DeltaE',
                                                  OutputWorkspace='ws1')
        AddSampleLog(sim_workspace,
                     LogName='Ei',
                     LogText='3.',
                     LogType='Number')
        cls.px_workspace = ConvertToMD(InputWorkspace=sim_workspace,
                                       OutputWorkspace="ws1",
                                       QDimensions='|Q|',
                                       dEAnalysisMode='Direct',
                                       MinValues='-10,0,0',
                                       MaxValues='10,6,500',
                                       SplitInto='50,50')
        cls.px_workspace_clone = CloneWorkspace(
            InputWorkspace=cls.px_workspace,
            OutputWorkspace='ws2',
            StoreInADS=False)
        cls.px_workspace = wrap_workspace(cls.px_workspace, 'ws1')
        cls.px_workspace_clone = wrap_workspace(cls.px_workspace_clone, 'ws2')
Esempio n. 2
0
    def test_remove_multiple_workspaces(self, delete_ws_mock):
        self.presenter = WorkspaceManagerPresenter(self.view)
        # Create a view that reports 3 selected workspaces on calls to get_workspace_selected
        workspace1 = wrap_workspace(
            CloneWorkspace(self.m_workspace.raw_ws, OutputWorkspace='file1'),
            'file1')
        workspace2 = wrap_workspace(
            CloneWorkspace(self.m_workspace.raw_ws, OutputWorkspace='file2'),
            'file2')
        self.view.get_workspace_selected = mock.Mock(
            return_value=[workspace1, workspace2])

        self.presenter.notify(Command.RemoveSelectedWorkspaces)
        self.view.get_workspace_selected.assert_called_once_with()
        delete_calls = [call(workspace1), call(workspace2)]
        delete_ws_mock.assert_has_calls(delete_calls, any_order=True)
        assert (self.view.display_loaded_workspaces.called)
Esempio n. 3
0
 def create_workspace(self, name):
     workspace = CreateSampleWorkspace(OutputWorkspace=name, NumBanks=1, BankPixelWidth=5, XMin=0.1,
                                       XMax=3.1, BinWidth=0.1, XUnit='DeltaE')
     AddSampleLog(Workspace=workspace, LogName='Ei', LogText='3.', LogType='Number')
     sim_scattering_data = np.arange(0, 1.5, 0.002).reshape(30, 25).transpose()
     for i in range(workspace.getNumberHistograms()):
         workspace.setY(i, sim_scattering_data[i])
     workspace = wrap_workspace(workspace, name)
     workspace.is_PSD = False
     workspace.limits['MomentumTransfer'] = [0.1, 3.1, 0.1]
     workspace.limits['|Q|'] = [0.1, 3.1, 0.1]
     workspace.limits['DeltaE'] = [-10, 15, 1]
     workspace.e_fixed = 10
     return workspace
Esempio n. 4
0
    def test_remove_workspace(self, delete_ws_mock):
        self.presenter = WorkspaceManagerPresenter(self.view)
        # Create a workspace that reports a single selected workspace on calls to get_workspace_selected
        workspace_to_be_removed = wrap_workspace(
            CloneWorkspace(self.m_workspace.raw_ws, OutputWorkspace='file1'),
            'file1')
        self.view.get_workspace_selected = mock.Mock(
            return_value=[workspace_to_be_removed])
        self.view.display_loaded_workspaces = mock.Mock()

        self.presenter.notify(Command.RemoveSelectedWorkspaces)
        self.view.get_workspace_selected.assert_called_once_with()
        delete_ws_mock.assert_called_once_with(workspace_to_be_removed)
        self.view.display_loaded_workspaces.assert_called_once()
Esempio n. 5
0
 def create_pixel_workspace(self, name):
     sim_workspace = CreateSimulationWorkspace(Instrument='MAR', BinParams=[-10, 1, 10],
                                               UnitX='DeltaE', OutputWorkspace=name)
     AddSampleLog(sim_workspace, LogName='Ei', LogText='3.', LogType='Number')
     sim_workspace = ConvertToMD(InputWorkspace=sim_workspace, OutputWorkspace=name, QDimensions='|Q|',
                                 dEAnalysisMode='Direct', MinValues='-10,0,0', MaxValues='10,6,500',
                                 SplitInto='50,50')
     workspace = wrap_workspace(sim_workspace, name)
     workspace.is_PSD = True
     workspace.limits['MomentumTransfer'] = [0.1, 3.1, 0.1]
     workspace.limits['|Q|'] = [0.1, 3.1, 0.1]
     workspace.limits['DeltaE'] = [-10, 15, 1]
     workspace.e_fixed = 10
     workspace.ef_defined = True
     return workspace
Esempio n. 6
0
    def alg_wrapper(*args, **kwargs):
        output_name = ''
        if 'InputWorkspace' in kwargs:
            kwargs['InputWorkspace'] = _name_or_wrapper_to_workspace(
                kwargs['InputWorkspace'])
        elif len(args) > 0:
            args = (_name_or_wrapper_to_workspace(args[0]), ) + args[1:]
        if 'OutputWorkspace' in kwargs:
            output_name = kwargs['OutputWorkspace']
        store = kwargs.pop('store', True)

        result = algorithm(*args, StoreInADS=False, **kwargs)
        if isinstance(result, Workspace):
            result = wrap_workspace(result, output_name)
            if store:
                add_workspace(result, output_name)
        return result
Esempio n. 7
0
    def alg_wrapper(*args, **kwargs):
        output_name = ''
        if 'InputWorkspace' in kwargs:
            kwargs['InputWorkspace'] = _name_or_wrapper_to_workspace(kwargs['InputWorkspace'])
        elif len(args) > 0:
            args = (_name_or_wrapper_to_workspace(args[0]),) + args[1:]
        if 'OutputWorkspace' in kwargs:
            output_name = kwargs['OutputWorkspace']
        store = kwargs.pop('store', True)
        for ws in [k for k in kwargs.keys() if isinstance(kwargs[k], MsliceWorkspace)]:
            if 'Input' not in ws and 'Output' not in ws:
                kwargs[ws] = _name_or_wrapper_to_workspace(kwargs[ws])
        args = tuple([_name_or_wrapper_to_workspace(arg) if isinstance(arg, MsliceWorkspace) else arg for arg in args])

        result = algorithm(*args, StoreInADS=False, **kwargs)
        if isinstance(result, Workspace):
            result = wrap_workspace(result, output_name)
            if store:
                add_workspace(result, output_name)
                from mslice.app import is_gui
                if is_gui():
                    from mslice.app.presenters import get_slice_plotter_presenter
                    get_slice_plotter_presenter().update_displayed_workspaces()
        return result