当前位置: 首页>>代码示例>>Python>>正文


Python api.AlgorithmManager类代码示例

本文整理汇总了Python中mantid.api.AlgorithmManager的典型用法代码示例。如果您正苦于以下问题:Python AlgorithmManager类的具体用法?Python AlgorithmManager怎么用?Python AlgorithmManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AlgorithmManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_strip_special_values

    def test_strip_special_values(self):
        create_alg = AlgorithmManager.create('CreateWorkspace')
        create_alg.setChild(True)
        create_alg.initialize()
        create_alg.setProperty('DataX', range(0, 10))
        y_data = np.array([1] * 7)
        y_data = np.append(y_data, [np.nan])
        y_data = np.append(y_data, [np.inf])
        create_alg.setProperty('DataY', y_data)
        create_alg.setProperty('NSpec', 1)
        create_alg.setProperty('UnitX', 'MomentumTransfer')
        create_alg.setPropertyValue('OutputWorkspace', 'out_ws')
        create_alg.execute()
        single_spectra_input = create_alg.getProperty('OutputWorkspace').value

        alg = AlgorithmManager.create('SANSStitch')
        alg.setChild(True)
        alg.initialize()
        alg.setProperty('Mode', 'Both')
        alg.setProperty('HABCountsSample', single_spectra_input)
        alg.setProperty('LABCountsSample', single_spectra_input)
        alg.setProperty('HABNormSample', single_spectra_input)
        alg.setProperty('LABNormSample', single_spectra_input)
        alg.setProperty('OutputWorkspace', 'dummy_name')
        # This would throw at the point of fitting in NaNs or infs where present
        alg.execute()
开发者ID:mducle,项目名称:mantid,代码行数:26,代码来源:SANSStitchTest.py

示例2: test_AlgorithmID_compares_by_value

 def test_AlgorithmID_compares_by_value(self):
     alg = AlgorithmManager.createUnmanaged('Load')
     id = alg.getAlgorithmID()
     self.assertEquals(id, id) # equals itself
     alg2 = AlgorithmManager.createUnmanaged('Load')
     id2 = alg2.getAlgorithmID()
     self.assertNotEqual(id2, id)
开发者ID:mantidproject,项目名称:mantid,代码行数:7,代码来源:AlgorithmTest.py

示例3: setUp

 def setUp(self):
     if self._integration is None:
         self.__class__._integration = AlgorithmManager.createUnmanaged("Integration")
         self.__class__._integration.initialize()
     if self._mask_dets is None:
         self.__class__._mask_dets = AlgorithmManager.createUnmanaged("MaskDetectors")
         self.__class__._mask_dets.initialize()
开发者ID:BigShows,项目名称:mantid,代码行数:7,代码来源:PropertyWithValueTest.py

示例4: test_workspace_entries_must_be_q1d

    def test_workspace_entries_must_be_q1d(self):
        # create an input workspace that has multiple spectra
        create_alg = AlgorithmManager.create('CreateWorkspace')
        create_alg.setChild(True)
        create_alg.initialize()
        create_alg.setProperty('DataX', range(0, 1))
        create_alg.setProperty('DataY', [1, 2])
        create_alg.setProperty('NSpec', 2)  # Wrong number of spectra
        create_alg.setProperty('UnitX', 'MomentumTransfer')
        create_alg.setPropertyValue('OutputWorkspace', 'out_ws')
        create_alg.execute()
        multi_spectra_input = create_alg.getProperty('OutputWorkspace').value

        alg = AlgorithmManager.create('SANSStitch')
        alg.setChild(True)
        alg.initialize()
        alg.setProperty('Mode', 'Both')
        alg.setProperty('HABCountsSample', multi_spectra_input)
        alg.setProperty('LABCountsSample', multi_spectra_input)
        alg.setProperty('HABNormSample', multi_spectra_input)
        alg.setProperty('LABNormSample', multi_spectra_input)

        errors = alg.validateInputs()
        self.assertTrue('HABCountsSample' in errors)
        self.assertTrue('LABCountsSample' in errors)
        self.assertTrue('HABNormSample' in errors)
        self.assertTrue('LABNormSample' in errors)
开发者ID:mducle,项目名称:mantid,代码行数:27,代码来源:SANSStitchTest.py

示例5: test_can_workspaces_required_if_process_can

    def test_can_workspaces_required_if_process_can(self):
        # create an input workspace that has multiple spectra
        create_alg = AlgorithmManager.create('CreateWorkspace')
        create_alg.setChild(True)
        create_alg.initialize()
        create_alg.setProperty('DataX', range(0, 1))
        create_alg.setProperty('DataY', [1])
        create_alg.setProperty('NSpec', 1)
        create_alg.setProperty('UnitX', 'MomentumTransfer')
        create_alg.setPropertyValue('OutputWorkspace', 'out_ws')
        create_alg.execute()
        single_spectra_input = create_alg.getProperty('OutputWorkspace').value

        alg = AlgorithmManager.create('SANSStitch')
        alg.setChild(True)
        alg.initialize()
        alg.setProperty('Mode', 'Both')
        alg.setProperty('HABCountsSample', single_spectra_input)
        alg.setProperty('LABCountsSample', single_spectra_input)
        alg.setProperty('HABNormSample', single_spectra_input)
        alg.setProperty('LABNormSample', single_spectra_input)
        alg.setProperty('ProcessCan', True)  # Now can workspaces should be provided

        errors = alg.validateInputs()
        self.assertTrue('HABCountsCan' in errors)
        self.assertTrue('LABCountsCan' in errors)
        self.assertTrue('HABNormCan' in errors)
        self.assertTrue('LABNormCan' in errors)
开发者ID:mducle,项目名称:mantid,代码行数:28,代码来源:SANSStitchTest.py

示例6: test_scale_only

    def test_scale_only(self):
        create_alg = AlgorithmManager.create('CreateWorkspace')
        create_alg.setChild(True)
        create_alg.initialize()
        create_alg.setProperty('NSpec', 1)
        create_alg.setProperty('UnitX', 'MomentumTransfer')
        create_alg.setPropertyValue('OutputWorkspace', 'out_ws')
        create_alg.setProperty('DataX', range(0, 10))

        # HAB as linear function y=x+5
        create_alg.setProperty('DataY', range(5, 14))
        create_alg.execute()
        hab_workspace = create_alg.getProperty('OutputWorkspace').value

        # LAB as linear function y=x+0
        create_alg.setProperty('DataY', range(0, 9))
        create_alg.execute()
        lab_workspace= create_alg.getProperty('OutputWorkspace').value

        alg = AlgorithmManager.create('SANSFitShiftScale')
        alg.setChild(True)
        alg.initialize()
        alg.setProperty('Mode', 'ScaleOnly')
        alg.setProperty('HABWorkspace', hab_workspace)
        alg.setProperty('LABWorkspace', lab_workspace)
        alg.setProperty('ShiftFactor', -5.0)
        alg.setProperty('ScaleFactor', 7.2)

        alg.execute()

        out_shift_factor = alg.getProperty('OutShiftFactor').value
        out_scale_factor = alg.getProperty('OutScaleFactor').value

        self.assertEquals(out_scale_factor, 1.0)
        self.assertEquals(out_shift_factor, -5.0)
开发者ID:DanNixon,项目名称:mantid,代码行数:35,代码来源:SANSFitShiftScaleTest.py

示例7: test_scale_none

    def test_scale_none(self):
        create_alg = AlgorithmManager.create('CreateWorkspace')
        create_alg.setChild(True)
        create_alg.initialize()
        create_alg.setProperty('DataX', range(0, 10))
        create_alg.setProperty('DataY', [1] * 9)
        create_alg.setProperty('NSpec', 1)
        create_alg.setProperty('UnitX', 'MomentumTransfer')
        create_alg.setPropertyValue('OutputWorkspace', 'out_ws')
        create_alg.execute()
        single_spectra_input = create_alg.getProperty('OutputWorkspace').value

        in_scale_factor = 1.0
        in_shift_factor = 1.0
        alg = AlgorithmManager.create('SANSFitShiftScale')
        alg.setChild(True)
        alg.initialize()
        alg.setProperty('Mode', 'None')
        alg.setProperty('HABWorkspace', single_spectra_input)
        alg.setProperty('LABWorkspace', single_spectra_input)
        alg.setProperty('ShiftFactor', in_shift_factor)
        alg.setProperty('ScaleFactor', in_scale_factor)
        alg.execute()
        out_shift_factor = alg.getProperty('OutShiftFactor').value
        out_scale_factor = alg.getProperty('OutScaleFactor').value

        self.assertEquals(out_scale_factor, in_scale_factor)
        self.assertEquals(out_shift_factor, in_shift_factor)
开发者ID:DanNixon,项目名称:mantid,代码行数:28,代码来源:SANSFitShiftScaleTest.py

示例8: test_newestInstanceOf_returns_correct_instance

    def test_newestInstanceOf_returns_correct_instance(self):
        alg = AlgorithmManager.create("ConvertUnits")
        alg2 = AlgorithmManager.create("ConvertUnits")
        alg3 = AlgorithmManager.newestInstanceOf("ConvertUnits")

        self.assertEquals(alg2.getAlgorithmID(), alg3.getAlgorithmID())
        self.assertNotEqual(alg.getAlgorithmID(), alg3.getAlgorithmID())
开发者ID:rosswhitfield,项目名称:mantid,代码行数:7,代码来源:AlgorithmManagerTest.py

示例9: test_runningInstancesOf_returns_python_list

    def test_runningInstancesOf_returns_python_list(self):
        algs = AlgorithmManager.runningInstancesOf("ConvertUnits")
        self.assertTrue(isinstance(algs, list))

        import threading
        class AlgThread(threading.Thread):
            def __init__(self):
                threading.Thread.__init__(self)
                self.algorithm = AlgorithmManager.create("Pause")
            def run(self):
                self.algorithm.initialize()
                self.algorithm.setProperty("Duration", -1.0) #forever
                self.algorithm.execute()
        # end class
        pause_thread = AlgThread()
        try:
            pause_thread.start()
            while not pause_thread.algorithm.isRunning():
                pass
            # should now be running
            algs = AlgorithmManager.runningInstancesOf("Pause")
            self.assertTrue(isinstance(algs, list))
            self.assertEquals(1, len(algs))
        except:
            pause_thread.algorithm.cancel()
            pause_thread.join()
            raise
        finally:
            pause_thread.algorithm.cancel()
            pause_thread.join()
开发者ID:rosswhitfield,项目名称:mantid,代码行数:30,代码来源:AlgorithmManagerTest.py

示例10: validateInputs

 def validateInputs(self):
     issues = dict()
     loader = self.getPropertyValue('LoaderName')
     version = self.getProperty('LoaderVersion').value
     try:
         AlgorithmManager.createUnmanaged(loader, version)
     except RuntimeError:
         message = loader + '-v' + str(version) + ' is not registered with Mantid.'
         issues['LoaderName'] = message
         issues['LoaderVersion'] = message
     return issues
开发者ID:mantidproject,项目名称:mantid,代码行数:11,代码来源:LoadAndMerge.py

示例11: test_stitch_2d_restricted_to_none

    def test_stitch_2d_restricted_to_none(self):
        # create an input workspace that has multiple spectra
        create_alg = AlgorithmManager.create('CreateWorkspace')
        create_alg.setChild(True)
        create_alg.initialize()
        create_alg.setProperty('DataX', range(0, 1))
        create_alg.setProperty('DataY', [1,1])
        create_alg.setProperty('NSpec', 2)
        create_alg.setProperty('UnitX', 'MomentumTransfer')
        create_alg.setPropertyValue('OutputWorkspace', 'out_ws')
        create_alg.execute()
        double_spectra_input = create_alg.getProperty('OutputWorkspace').value

        # Basic algorithm setup
        alg = AlgorithmManager.create('SANSStitch')
        alg.setChild(True)
        alg.initialize()
        alg.setProperty('HABCountsSample', double_spectra_input)
        alg.setProperty('LABCountsSample', double_spectra_input)
        alg.setProperty('HABNormSample', double_spectra_input)
        alg.setProperty('LABNormSample', double_spectra_input)
        alg.setProperty('ProcessCan', False)
        alg.setProperty('ShiftFactor', 1.0)
        alg.setProperty('ScaleFactor', 0.0)

        # 2D inputs Should not be allowed for mode Both
        alg.setProperty('Mode', 'Both')
        errors = alg.validateInputs()
        self.assertTrue('HABCountsSample' in errors)
        self.assertTrue('LABCountsSample' in errors)
        self.assertTrue('HABNormSample' in errors)
        self.assertTrue('LABNormSample' in errors)

        # 2D inputs Should not be allowed for mode ScaleOnly
        alg.setProperty('Mode', 'ScaleOnly')
        errors = alg.validateInputs()
        self.assertTrue('HABCountsSample' in errors)
        self.assertTrue('LABCountsSample' in errors)
        self.assertTrue('HABNormSample' in errors)
        self.assertTrue('LABNormSample' in errors)

        # 2D inputs Should not be allowed for mode ShiftOnly
        alg.setProperty('Mode', 'ShiftOnly')
        errors = alg.validateInputs()
        self.assertTrue('HABCountsSample' in errors)
        self.assertTrue('LABCountsSample' in errors)
        self.assertTrue('HABNormSample' in errors)
        self.assertTrue('LABNormSample' in errors)

        # With no fitting 2D inputs are allowed
        alg.setProperty('Mode', 'None')
        errors = alg.validateInputs()
        self.assertEqual(0, len(errors))
开发者ID:mducle,项目名称:mantid,代码行数:53,代码来源:SANSStitchTest.py

示例12: test_scale_both_without_can_with_q_fit_range

    def test_scale_both_without_can_with_q_fit_range(self):
        create_alg = AlgorithmManager.create('CreateWorkspace')
        create_alg.setChild(True)
        create_alg.initialize()
        create_alg.setProperty('NSpec', 1)
        create_alg.setProperty('UnitX', 'MomentumTransfer')
        create_alg.setPropertyValue('OutputWorkspace', 'out_ws')
        create_alg.setProperty('DataX', range(0, 12))

        # HAB as linear function y=x+5
        hab_range = list(range(5, 16))
        hab_range[0] = 15000
        hab_range[9] = 15000
        create_alg.setProperty('DataY', hab_range)
        create_alg.execute()
        hab_workspace = create_alg.getProperty('OutputWorkspace').value

        # LAB as linear function y=x+0
        create_alg.setProperty('DataY', range(0, 11))
        create_alg.execute()
        lab_workspace= create_alg.getProperty('OutputWorkspace').value

        # FLAT NORM
        create_alg.setProperty('DataY', [1] * 11)
        create_alg.execute()
        flat_norm = create_alg.getProperty('OutputWorkspace').value

        alg = AlgorithmManager.create('SANSStitch')
        alg.setChild(True)
        alg.initialize()
        alg.setProperty('Mode', 'Both')
        alg.setProperty('HABCountsSample', hab_workspace)
        alg.setProperty('LABCountsSample', lab_workspace)
        alg.setProperty('HABNormSample', flat_norm)
        alg.setProperty('LABNormSample', flat_norm)
        alg.setProperty('OutputWorkspace', 'dummy_name')
        alg.setProperty('FitMin', 1)
        alg.setProperty('FitMax', 9)
        alg.execute()
        out_ws = alg.getProperty('OutputWorkspace').value
        out_shift_factor = alg.getProperty('OutShiftFactor').value
        out_scale_factor = alg.getProperty('OutScaleFactor').value
        self.assertEquals(out_scale_factor, 1.0)
        self.assertEquals(out_shift_factor, -5.0)

        out_ws = alg.getProperty('OutputWorkspace').value

        y_array = out_ws.readY(0)

        expected_y_array = [7497.5, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 7502, 10.0]  # We scale and shift to the back (lab) detectors

        self.assertTrue(all(map(lambda element: element in y_array, expected_y_array)),
                        msg='All data should be scaled and shifted to the LAB scale=1 shift=-5')
开发者ID:DanNixon,项目名称:mantid,代码行数:53,代码来源:SANSStitchTest.py

示例13: test_that_zero_merge_range_has_discrete_transition

    def test_that_zero_merge_range_has_discrete_transition(self):
            # This tests that if a merge_max or merge_min is specified greater than the overlap region of
            # the HAB and LAB the relevant value is set to the maximum value.
            create_alg = AlgorithmManager.create('CreateWorkspace')
            create_alg.setChild(True)
            create_alg.initialize()
            create_alg.setProperty('DataX', range(0, 10))
            create_alg.setProperty('DataY', [1] * 9)
            create_alg.setProperty('NSpec', 1)
            create_alg.setProperty('UnitX', 'MomentumTransfer')
            create_alg.setPropertyValue('OutputWorkspace', 'out_ws')
            create_alg.execute()
            single_spectra_input = create_alg.getProperty('OutputWorkspace').value
            create_alg.setProperty('DataY', [2] * 9)
            create_alg.execute()
            single_spectra_input_HAB = create_alg.getProperty('OutputWorkspace').value
            create_alg.setProperty('DataY', [0.5] * 9)
            create_alg.execute()
            smaller_single_spectra_input = create_alg.getProperty('OutputWorkspace').value

            alg = AlgorithmManager.create('SANSStitch')
            alg.setChild(True)
            alg.initialize()
            alg.setProperty('Mode', 'None')
            alg.setProperty('HABCountsSample', single_spectra_input_HAB)
            alg.setProperty('LABCountsSample', single_spectra_input)
            alg.setProperty('HABNormSample', single_spectra_input)
            alg.setProperty('LABNormSample', single_spectra_input)
            alg.setProperty('ProcessCan', True)
            alg.setProperty('HABCountsCan', smaller_single_spectra_input)
            alg.setProperty('LABCountsCan', smaller_single_spectra_input)
            alg.setProperty('HABNormCan', single_spectra_input)
            alg.setProperty('LABNormCan', single_spectra_input)
            alg.setProperty('OutputWorkspace', 'dummy_name')
            alg.setProperty('ShiftFactor', 0.0)
            alg.setProperty('ScaleFactor', 1.0)
            alg.setProperty('MergeMask', True)
            alg.setProperty('MergeMin', 5)
            alg.setProperty('MergeMax', 5)
            alg.execute()
            out_ws = alg.getProperty('OutputWorkspace').value

            self.assertTrue(isinstance(out_ws, MatrixWorkspace))

            y_array = out_ws.readY(0)

            expected_y_array = [0.5] * 5 + [1.5] * 4
            
            np.testing.assert_equal(y_array, expected_y_array)
开发者ID:mantidproject,项目名称:mantid,代码行数:49,代码来源:SANSStitchTest.py

示例14: test_scale_none_with_can_and_q_merge_range

    def test_scale_none_with_can_and_q_merge_range(self):
        create_alg = AlgorithmManager.create('CreateWorkspace')
        create_alg.setChild(True)
        create_alg.initialize()
        create_alg.setProperty('DataX', range(0, 10))
        create_alg.setProperty('DataY', [1] * 9)
        create_alg.setProperty('NSpec', 1)
        create_alg.setProperty('UnitX', 'MomentumTransfer')
        create_alg.setPropertyValue('OutputWorkspace', 'out_ws')
        create_alg.execute()
        single_spectra_input = create_alg.getProperty('OutputWorkspace').value
        create_alg.setProperty('DataY', [2] * 9)
        create_alg.execute()
        single_spectra_input_HAB = create_alg.getProperty('OutputWorkspace').value
        create_alg.setProperty('DataY', [0.5] * 9)
        create_alg.execute()
        smaller_single_spectra_input = create_alg.getProperty('OutputWorkspace').value

        alg = AlgorithmManager.create('SANSStitch')
        alg.setChild(True)
        alg.initialize()
        alg.setProperty('Mode', 'None')
        alg.setProperty('HABCountsSample', single_spectra_input_HAB)
        alg.setProperty('LABCountsSample', single_spectra_input)
        alg.setProperty('HABNormSample', single_spectra_input)
        alg.setProperty('LABNormSample', single_spectra_input)
        alg.setProperty('ProcessCan', True)
        alg.setProperty('HABCountsCan', smaller_single_spectra_input)
        alg.setProperty('LABCountsCan', smaller_single_spectra_input)
        alg.setProperty('HABNormCan', single_spectra_input)
        alg.setProperty('LABNormCan', single_spectra_input)
        alg.setProperty('OutputWorkspace', 'dummy_name')
        alg.setProperty('ShiftFactor', 0.0)
        alg.setProperty('ScaleFactor', 1.0)
        alg.setProperty('MergeMask', True)
        alg.setProperty('MergeMin', 2)
        alg.setProperty('MergeMax', 7)
        alg.execute()
        out_ws = alg.getProperty('OutputWorkspace').value

        self.assertTrue(isinstance(out_ws, MatrixWorkspace))

        y_array = out_ws.readY(0)

        expected_y_array = [0.5] * 2 + [1.0] * 5 + [1.5] * 2

        self.assertTrue(all(map(lambda element: element in y_array, expected_y_array)),
                        msg='can gets subtracted so expect 1 - 0.5 as output signal. Proves the can workspace gets used correctly.')
开发者ID:DanNixon,项目名称:mantid,代码行数:48,代码来源:SANSStitchTest.py

示例15: _load_workspace

    def _load_workspace(self, state):
        load_alg = AlgorithmManager.createUnmanaged("SANSLoad")
        load_alg.setChild(True)
        load_alg.initialize()

        state_dict = state.property_manager
        load_alg.setProperty("SANSState", state_dict)
        load_alg.setProperty("PublishToCache", False)
        load_alg.setProperty("UseCached", False)
        load_alg.setProperty("MoveWorkspace", False)
        load_alg.setProperty("SampleScatterWorkspace", EMPTY_NAME)
        load_alg.setProperty("SampleScatterMonitorWorkspace", EMPTY_NAME)
        if state.data.sample_transmission:
            load_alg.setProperty("SampleTransmissionWorkspace", EMPTY_NAME)
        if state.data.sample_direct:
            load_alg.setProperty("SampleDirectWorkspace", EMPTY_NAME)

        # Act
        load_alg.execute()
        self.assertTrue(load_alg.isExecuted())
        sample_scatter = load_alg.getProperty("SampleScatterWorkspace").value
        sample_scatter_monitor_workspace = load_alg.getProperty("SampleScatterMonitorWorkspace").value
        if state.data.sample_transmission:
            transmission_workspace = load_alg.getProperty("SampleTransmissionWorkspace").value
        else:
            transmission_workspace = None
        if state.data.sample_direct:
            direct_workspace = load_alg.getProperty("SampleDirectWorkspace").value
        else:
            direct_workspace = None
        return sample_scatter, sample_scatter_monitor_workspace, transmission_workspace, direct_workspace
开发者ID:stuartcampbell,项目名称:mantid,代码行数:31,代码来源:SANSBeamCentreFinderCoreTest.py


注:本文中的mantid.api.AlgorithmManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。