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


Python AlgorithmFactory.subscribe方法代码示例

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


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

示例1: test_python_alg_can_use_other_python_alg_through_simple_api

# 需要导入模块: from mantid.api import AlgorithmFactory [as 别名]
# 或者: from mantid.api.AlgorithmFactory import subscribe [as 别名]
    def test_python_alg_can_use_other_python_alg_through_simple_api(self):
        class SimpleAPIPythonAlgorithm1(PythonAlgorithm):
            def PyInit(self):
                pass
            def PyExec(self):
                from mantid.simpleapi import SimpleAPIPythonAlgorithm2
                SimpleAPIPythonAlgorithm2()
        class SimpleAPIPythonAlgorithm2(PythonAlgorithm):
            def PyInit(self):
                pass
            def PyExec(self):
                pass

        AlgorithmFactory.subscribe(SimpleAPIPythonAlgorithm1)
        AlgorithmFactory.subscribe(SimpleAPIPythonAlgorithm2)
        # ---------------------------------------------------------
        alg1 = SimpleAPIPythonAlgorithm1()
        alg1.initialize()
        # Puts function in simpleapi globals
        simpleapi_alg1_func = simpleapi._create_algorithm_function("SimpleAPIPythonAlgorithm1", 1, alg1)
        alg2 = SimpleAPIPythonAlgorithm1()
        alg2.initialize()
        # Puts function in simpleapi globals
        simpleapi._create_algorithm_function("SimpleAPIPythonAlgorithm2", 1, alg2)
        try:
            simpleapi_alg1_func()
        except RuntimeError as exc:
            self.fail("Running algorithm 2 from 1 failed: " + str(exc))
开发者ID:rosswhitfield,项目名称:mantid,代码行数:30,代码来源:SimpleAPITest.py

示例2: get_gui_algorithm_name

# 需要导入模块: from mantid.api import AlgorithmFactory [as 别名]
# 或者: from mantid.api.AlgorithmFactory import subscribe [as 别名]
def get_gui_algorithm_name(facility):
    if facility is SANSFacility.ISIS:
        algorithm_name = "SANSGuiDataProcessorAlgorithm"
        AlgorithmFactory.subscribe(SANSGuiDataProcessorAlgorithm)
    else:
        raise RuntimeError("The facility is currently not supported")
    return algorithm_name
开发者ID:DanNixon,项目名称:mantid,代码行数:9,代码来源:sans_data_processor_gui_algorithm.py

示例3: test_that_selector_is_refreshed_on_alg_load

# 需要导入模块: from mantid.api import AlgorithmFactory [as 别名]
# 或者: from mantid.api.AlgorithmFactory import subscribe [as 别名]
    def test_that_selector_is_refreshed_on_alg_load(self):
        widget = AlgorithmSelectorWidgetMock()
        widget.refresh = mock.MagicMock()
        widget.observeUpdate(True)
        AlgorithmFactory.subscribe(ToyAlgorithm)

        self.assertTrue(widget.refresh.call_count == 1,
                        "We expect the widget to be refreshed when the Algorithm Factory "
                        "subscribes to a new algorithm. refresh was called "
                        "{} times after subscription.".format(widget.refresh.call_count))
开发者ID:mantidproject,项目名称:mantid,代码行数:12,代码来源:observer_test.py

示例4: test_can_toggle_algorithm_factory_notifications

# 需要导入模块: from mantid.api import AlgorithmFactory [as 别名]
# 或者: from mantid.api.AlgorithmFactory import subscribe [as 别名]
    def test_can_toggle_algorithm_factory_notifications(self):
        widget = AlgorithmSelectorWidgetMock()
        widget.refresh = mock.MagicMock()
        widget.observeUpdate(True)
        widget.observeUpdate(False)

        AlgorithmFactory.subscribe(ToyAlgorithm)

        self.assertTrue(widget.refresh.call_count == 0,
                        "We expect the widget to be refreshed when the Algorithm Factory "
                        "subscribes to a new algorithm. refresh was called "
                        "{} times after subscription.".format(widget.refresh.call_count))
开发者ID:mantidproject,项目名称:mantid,代码行数:14,代码来源:observer_test.py

示例5: test_class_can_override_standard_algorithm_methods

# 需要导入模块: from mantid.api import AlgorithmFactory [as 别名]
# 或者: from mantid.api.AlgorithmFactory import subscribe [as 别名]
    def test_class_can_override_standard_algorithm_methods(self):
        class TestDataProcessor(DataProcessorAlgorithm):
            def version(self):
                return 2
            def PyInit(self):
                pass
            def PyExec(self):
                pass
        # end v2 alg

        AlgorithmFactory.subscribe(TestDataProcessor)
        assertRaisesNothing(self, AlgorithmManager.createUnmanaged, "TestDataProcessor", 2)
开发者ID:AlistairMills,项目名称:mantid,代码行数:14,代码来源:DataProcessorAlgorithmTest.py

示例6: setUp

# 需要导入模块: from mantid.api import AlgorithmFactory [as 别名]
# 或者: from mantid.api.AlgorithmFactory import subscribe [as 别名]
 def setUp(self):
     if self.__class__._registered is None:
         self.__class__._registered = True
         AlgorithmFactory.subscribe(TestPyAlgDefaultAttrs)
         AlgorithmFactory.subscribe(TestPyAlgOverriddenAttrs)
         AlgorithmFactory.subscribe(TestPyAlgIsRunningReturnsNonBool)
         AlgorithmFactory.subscribe(CancellableAlg)
开发者ID:AlistairMills,项目名称:mantid,代码行数:9,代码来源:PythonAlgorithmTraitsTest.py

示例7: test_explicit_store_in_ADS

# 需要导入模块: from mantid.api import AlgorithmFactory [as 别名]
# 或者: from mantid.api.AlgorithmFactory import subscribe [as 别名]
    def test_explicit_store_in_ADS(self):
        class SimpleAPIPythonAlgorithm5(PythonAlgorithm):
            def PyInit(self):
                pass

            def PyExec(self):
                from mantid.simpleapi import CreateSampleWorkspace
                workspaceInADS = CreateSampleWorkspace(StoreInADS=True)
                assert(workspaceInADS)
        AlgorithmFactory.subscribe(SimpleAPIPythonAlgorithm5)

        alg = SimpleAPIPythonAlgorithm5()
        alg.initialize()
        alg.execute()
        self.assertTrue('workspaceInADS' in mtd)
开发者ID:mantidproject,项目名称:mantid,代码行数:17,代码来源:SimpleAPITest.py

示例8: test_python_alg_can_use_other_python_alg_through_simple_api

# 需要导入模块: from mantid.api import AlgorithmFactory [as 别名]
# 或者: from mantid.api.AlgorithmFactory import subscribe [as 别名]
    def test_python_alg_can_use_other_python_alg_through_simple_api(self):
        """
        Runs a test in a separate process as it requires a reload of the
        whole mantid module 
        """
        src = """
from mantid.api import PythonAlgorithm, AlgorithmFactory
import mantid.simpleapi as api
from mantid.simpleapi import *

class %(name)s(PythonAlgorithm):

    def PyInit(self):
        pass
    def PyExec(self):
        %(execline1)s
        %(execline2)s
        
AlgorithmFactory.subscribe(%(name)s)
"""
        name1 = "SimpleAPIPythonAlgorithm1"
        name2 = "SimpleAPIPythonAlgorithm2"
        src1 = src % {"name":name1,"execline1":name2+"()","execline2":"api."+name2+"()"}
        src2 = src % {"name":name2,"execline1":"pass","execline2":"pass"}
        a = TemporaryPythonAlgorithm(name1,src1)
        b = TemporaryPythonAlgorithm(name2,src2)
        import subprocess
        # Try to use algorithm 1 to run algorithm 2
        cmd = sys.executable + ' -c "from mantid.simpleapi import %(name)s;%(name)s()"' % {'name':name1}
        try:
            subprocess.check_call(cmd,shell=True)
        except subprocess.CalledProcessError, exc:
            self.fail("Error occurred running one Python algorithm from another: %s" % str(exc))
开发者ID:BigShows,项目名称:mantid,代码行数:35,代码来源:SimpleAPITest.py

示例9: test_validate_inputs_with_errors_stops_algorithm

# 需要导入模块: from mantid.api import AlgorithmFactory [as 别名]
# 或者: from mantid.api.AlgorithmFactory import subscribe [as 别名]
 def test_validate_inputs_with_errors_stops_algorithm(self):
     class ValidateInputsTest(PythonAlgorithm):
         def PyInit(self):
             self.declareProperty("Prop1", 1.0)
             self.declareProperty("Prop2", 2.0)
         def validateInputs(self):
             return {"Prop1":"Value is less than Prop2"}
         def PyExec(self):
             pass
     AlgorithmFactory.subscribe(ValidateInputsTest)
     # ---------------------------------------------------------
     alg_obj = ValidateInputsTest()
     alg_obj.initialize()
     
     simpleapi_func = simpleapi._create_algorithm_function("ValidateInputsTest", 1, alg_obj)
     # call
     self.assertRaises(RuntimeError, simpleapi_func, Prop1=2.5, Prop2=3.5)
开发者ID:rosswhitfield,项目名称:mantid,代码行数:19,代码来源:SimpleAPITest.py

示例10: test_optional_workspaces_are_ignored_if_not_present_in_output_even_if_given_as_input

# 需要导入模块: from mantid.api import AlgorithmFactory [as 别名]
# 或者: from mantid.api.AlgorithmFactory import subscribe [as 别名]
    def test_optional_workspaces_are_ignored_if_not_present_in_output_even_if_given_as_input(self):
        # Test algorithm
        from mantid.api import (
            AlgorithmManager,
            PropertyMode,
            PythonAlgorithm,
            MatrixWorkspaceProperty,
            WorkspaceFactory,
        )
        from mantid.kernel import Direction

        class OptionalWorkspace(PythonAlgorithm):
            def PyInit(self):
                self.declareProperty(MatrixWorkspaceProperty("RequiredWorkspace", "", Direction.Output))
                self.declareProperty(
                    MatrixWorkspaceProperty("OptionalWorkspace", "", Direction.Output, PropertyMode.Optional)
                )

            def PyExec(self):
                ws = WorkspaceFactory.create("Workspace2D", NVectors=1, YLength=1, XLength=1)
                ws.dataY(0)[0] = 5
                self.setProperty("RequiredWorkspace", ws)
                self.getLogger().notice("done!")

        AlgorithmFactory.subscribe(OptionalWorkspace)

        # temporarily attach it to simpleapi module
        name = "OptionalWorkspace"
        algm_object = AlgorithmManager.createUnmanaged(name, 1)
        algm_object.initialize()
        simpleapi._create_algorithm_function(name, 1, algm_object)  # Create the wrapper

        # Call with no optional output specified
        result = simpleapi.OptionalWorkspace(RequiredWorkspace="required")
        self.assertTrue(isinstance(result, MatrixWorkspace))
        self.assertAlmostEqual(5, result.readY(0)[0], places=12)
        mtd.remove("required")

        # Call with both outputs specified
        result = simpleapi.OptionalWorkspace(RequiredWorkspace="required", OptionalWorkspace="optional")
        self.assertTrue(isinstance(result, MatrixWorkspace))
        self.assertAlmostEqual(5, result.readY(0)[0], places=12)
        mtd.remove("required")

        # Tidy up simple api function
        del simpleapi.OptionalWorkspace
开发者ID:tyronerees,项目名称:mantid,代码行数:48,代码来源:SimpleAPITest.py

示例11: test_later_store_in_ADS

# 需要导入模块: from mantid.api import AlgorithmFactory [as 别名]
# 或者: from mantid.api.AlgorithmFactory import subscribe [as 别名]
    def test_later_store_in_ADS(self):
        from mantid.api import MatrixWorkspaceProperty
        from mantid.kernel import Direction

        class SimpleAPIPythonAlgorithm6(PythonAlgorithm):
            def PyInit(self):
                self.declareProperty(MatrixWorkspaceProperty("OutputWorkspace", "", Direction.Output))

            def PyExec(self):
                from mantid.simpleapi import CreateSampleWorkspace
                workspaceNotInADS = CreateSampleWorkspace(StoreInADS=False)
                assert(workspaceNotInADS)
                self.setProperty("OutputWorkspace", workspaceNotInADS)
        AlgorithmFactory.subscribe(SimpleAPIPythonAlgorithm6)

        alg = SimpleAPIPythonAlgorithm6()
        alg.initialize()
        alg.setPropertyValue("OutputWorkspace", "out")
        alg.execute()
        self.assertTrue('out' in mtd)
        mtd.remove('out')
开发者ID:mantidproject,项目名称:mantid,代码行数:23,代码来源:SimpleAPITest.py

示例12: range

# 需要导入模块: from mantid.api import AlgorithmFactory [as 别名]
# 或者: from mantid.api.AlgorithmFactory import subscribe [as 别名]
        for i in range(10):
            ndens = (self._number_density/total_mass)*1e6
            xst = self.free_xst(self._masses, scatter_length)
            attenuation_length = ndens*xst*1e-28

            dmur = 2*attenuation_length*self._thickness
            trans_guess = math.exp(-dmur)
            self._number_density = ((1-self._transmission_guess)/(1-trans_guess))*self._number_density
            # Add guesses to output workspaces
            density_guesses_tbl_ws.addRow([str(i+1), self._number_density])
            trans_guesses_tbl_ws.addRow([str(i+1), trans_guess])

        self.setProperty("DensityWorkspace", density_guesses_tbl_ws)
        self.setProperty("TransmissionWorkspace", trans_guesses_tbl_ws)


    def free_xst(self, Mass, scatter_length):
        """
        Analytic expression for integration of PDCS over E1 and solid angle
        """
        # Neutron rest mass(u) / Mass
        xs_masses = 1.00867/Mass
        scatter_len_sq = np.square(scatter_length)
        cross_section = np.divide((self.FOUR_PI * scatter_len_sq),(np.square(xs_masses+1)))
        xs_sum = sum(cross_section)
        return xs_sum


AlgorithmFactory.subscribe(VesuvioThickness)
开发者ID:liyulun,项目名称:mantid,代码行数:31,代码来源:VesuvioThickness.py

示例13: open

# 需要导入模块: from mantid.api import AlgorithmFactory [as 别名]
# 或者: from mantid.api.AlgorithmFactory import subscribe [as 别名]
	#calculate chi^2
	soeName = self.getPropertyValue("ResidualsWorkspace")
	if (len(soeName)>0): 
		mantid.simpleapi.SignalOverError(__w1-__w2,OutputWorkspace=soeName)	
		self.setProperty("ResidualsWorkspace",soeName) 
		__soe=mantid.mtd[soeName]
	else:
		__soe=mantid.simpleapi.SignalOverError(__w1-__w2)
	__soe2=__soe*__soe
	__soe2=mantid.simpleapi.ReplaceSpecialValues(__soe2,0,0,0,0)
	
	data=__soe2.extractY()
	chisquared=numpy.sum(data)

	#write out the Dakota chi squared file
	f = open(fout,'w')
	f.write(str(chisquared)+' obj_fn\n')
	f.close()

        self.setProperty("ChiSquared",chisquared)
  	

	#cleanup	
	mantid.simpleapi.DeleteWorkspace(__w1.getName())
	mantid.simpleapi.DeleteWorkspace(__w2.getName())
	mantid.simpleapi.DeleteWorkspace(__soe2.getName())
	if (len(soeName)==0): 
   		mantid.simpleapi.DeleteWorkspace(__soe.getName())
    
AlgorithmFactory.subscribe(DakotaChiSquared)
开发者ID:AlistairMills,项目名称:mantid,代码行数:32,代码来源:DakotaChiSquared.py

示例14: _plot_result

# 需要导入模块: from mantid.api import AlgorithmFactory [as 别名]
# 或者: from mantid.api.AlgorithmFactory import subscribe [as 别名]
            save_alg.setProperty("Filename", path)
            save_alg.execute()

    def _plot_result(self, workspaces):
        from IndirectImport import import_mantidplot
        mp = import_mantidplot()
        mp.plotSpectrum(workspaces,0)

    def _create_ws(self, output_ws, x, y, unit):
        create_alg = self.createChildAlgorithm("CreateWorkspace", enableLogging = False)
        create_alg.setProperty("OutputWorkspace", output_ws)
        create_alg.setProperty("DataX", x)
        create_alg.setProperty("DataY", y)
        create_alg.setProperty("Nspec", 1)
        create_alg.setProperty("UnitX", 'MomentumTransfer')
        create_alg.execute()
        mtd.addOrReplace(output_ws, create_alg.getProperty("OutputWorkspace").value)
        if unit == 'angle':
            unitx = mtd[output_ws].getAxis(0).setUnit("Label")
            unitx.setLabel('2theta', 'deg')

    def _group_ws(self, input_ws, output_ws):
        group_alg = self.createChildAlgorithm("GroupWorkspaces", enableLogging=False)
        group_alg.setProperty("InputWorkspaces", input_ws)
        group_alg.setProperty("OutputWorkspace", output_ws)
        group_alg.execute()
        mtd.addOrReplace(output_ws, group_alg.getProperty("OutputWorkspace").value)


AlgorithmFactory.subscribe(MuscatElasticReactor)          # Register algorithm with Mantid
开发者ID:mantidproject,项目名称:scriptrepository,代码行数:32,代码来源:MuscatElasticReactor.py

示例15: RuntimeError

# 需要导入模块: from mantid.api import AlgorithmFactory [as 别名]
# 或者: from mantid.api.AlgorithmFactory import subscribe [as 别名]
        crop_alg.setProperty("XMin", xmin)
        crop_alg.setProperty("XMax", xmax)
        crop_alg.execute()
        out_ws = crop_alg.getProperty("OutputWorkspace").value
        # add logs
        num_spectra = out_ws.getNumberHistograms()
        run_obj = out_ws.getRun()
        min_values = [xmin]*num_spectra
        max_values = [xmax]*num_spectra
        if run_obj.hasProperty('MDNorm_low'):
            #TODO: when handling of masking bins is implemented, number of spectra will be different
            #      than the number of limits
            try:
                min_values = numpy.maximum(min_values, run_obj.getProperty('MDNorm_low').value).tolist()
            except ValueError:
                raise RuntimeError("Could not compare old and new values for 'MDNorm_low' log. "+
                                   "Make sure the length of the old data is equal to the number of spectra")
        run_obj.addProperty('MDNorm_low', min_values, True)
        if run_obj.hasProperty('MDNorm_high'):
            try:
                max_values = numpy.minimum(max_values, run_obj.getProperty('MDNorm_high').value).tolist()
            except ValueError:
                raise RuntimeError("Could not compare old and new values for 'MDNorm_high' log. "+
                                   "Make sure the length of the old data is equal to the number of spectra")
        run_obj.addProperty('MDNorm_high', [xmax]*num_spectra, True)
        run_obj.addProperty('MDNorm_spectra_index', numpy.arange(num_spectra).tolist(), True)
        self.setProperty('OutputWorkspace', out_ws)

# Register algorithm with Mantid.
AlgorithmFactory.subscribe(CropWorkspaceForMDNorm)
开发者ID:samueljackson92,项目名称:mantid,代码行数:32,代码来源:CropWorkspaceForMDNorm.py


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