コード例 #1
0
ファイル: base.py プロジェクト: liyulun/mantid
    def skip(self):
        """
        Override and return a string depending on whether the directive
        should be skipped. If empty then the directive should be processed
        otherwise the string should contain the error message
        The default is to skip (and warn) if the algorithm is not known.

        Returns:
          str: Return error mesage string if the directive should be skipped
        """
        from mantid.api import AlgorithmFactory, FunctionFactory

        name, version = self.algorithm_name(), self.algorithm_version()
        msg = ""
        if version is None: # it is a fit function
            if name in FunctionFactory.getFunctionNames():
                return ""
            else:
                msg = "No fit function '%s', skipping directive" % name
        else:
            if AlgorithmFactory.exists(name, version):
                return ""
            else:
                msg = "No algorithm '%s' version '%d', skipping directive" % (name, version)

        # warn the user
        if len(msg) > 0:
            env = self.state.document.settings.env
            env.app.verbose(msg)
        return msg
コード例 #2
0
    def skip(self):
        """
        Override and return a string depending on whether the directive
        should be skipped. If empty then the directive should be processed
        otherwise the string should contain the error message
        The default is to skip (and warn) if the algorithm is not known.

        Returns:
          str: Return error message string if the directive should be skipped
        """
        from mantid.api import FunctionFactory

        name, version = self.algorithm_name(), self.algorithm_version()
        msg = ""
        if version is None:  # it is a fit function
            if name in FunctionFactory.getFunctionNames():
                return ""
            else:
                msg = "No fit function '%s', skipping directive" % name
        else:
            if AlgorithmFactory.exists(name, version):
                return ""
            else:
                msg = "No algorithm '%s' version '%d', skipping directive" % (
                    name, version)

        # warn the user
        if len(msg) > 0:
            logger = get_logger(__name__, self.state.document.settings.env.app)
            logger.verbose(msg)
        return msg
コード例 #3
0
ファイル: convertLinks.py プロジェクト: martyngigg/alg2rst
def genNewLinks(links, algNames, pageName):
    
    repLinks = []
    
    for link in links:

        link = link.replace('`', '')
        link = link.replace('<', '')
        link = link.replace('>', '')
        link = link.replace('__', '')
        link = link.split()

        #Check length of link
        if len(link) > 2:
            print 'Unlikely to be an algorithm link with multiple words in it'
            repLinks.append(None)
            links_todo[pageName].append(link)      
        else:            
            name = link[0]
            if "-v" in name:
                name = name[:-3]
            #Check if the link is a concept
            print "Checking for",name
            if (AlgorithmFactory.exists(name)):
                newLink = ':ref:`algm-'+ name +'`'
                repLinks.append(newLink)
            else:
                #These are links that aren't algorithms but are single words links, likely to be links to concepts or similar
                print 'Not found in algorithm list'
                repLinks.append(None)
                links_todo[pageName].append(link)
    
    return repLinks
コード例 #4
0
ファイル: test_mantid.py プロジェクト: scipp/scippneutron
def make_dynamic_algorithm_without_fileproperty(alg_name):
    from mantid.api import PythonAlgorithm, AlgorithmFactory,\
        WorkspaceProperty, WorkspaceFactory
    from mantid.kernel import Direction
    # Loader without FileProperty
    if AlgorithmFactory.exists(alg_name):
        return

    class Alg(PythonAlgorithm):
        def PyInit(self):
            self.declareProperty("Filename", "")
            self.declareProperty(
                WorkspaceProperty(name="OutputWorkspace",
                                  defaultValue="",
                                  direction=Direction.Output))

        def PyExec(self):
            self.setProperty("OutputWorkspace", WorkspaceFactory.createTable())

    Alg.__name__ = alg_name
    AlgorithmFactory.subscribe(Alg)
    importlib.reload(sys.modules["mantid.simpleapi"])
コード例 #5
0
        self.valid_matrix = {
            u'_diffrn_orient_matrix_ub_11': u'-0.03',
            u'_diffrn_orient_matrix_ub_12': u'0.13',
            u'_diffrn_orient_matrix_ub_13': u'0.31',
            u'_diffrn_orient_matrix_ub_21': u'0.01',
            u'_diffrn_orient_matrix_ub_22': u'-0.31',
            u'_diffrn_orient_matrix_ub_23': u'0.14',
            u'_diffrn_orient_matrix_ub_31': u'0.34',
            u'_diffrn_orient_matrix_ub_32': u'0.02',
            u'_diffrn_orient_matrix_ub_33': u'0.02'
        }

    def test_getUBMatrix_invalid(self):
        for key in self.valid_matrix:
            tmp = self.valid_matrix.copy()
            del tmp[key]

            self.assertRaises(RuntimeError,
                              self.builder._getUBMatrix,
                              cifData=tmp)

    def test_getUBMatrix_correct(self):
        self.assertEqual(self.builder._getUBMatrix(self.valid_matrix),
                         '-0.03,0.13,0.31,0.01,-0.31,0.14,0.34,0.02,0.02')


if __name__ == '__main__':
    # Only test if algorithm is registered (PyCifRW dependency).
    if AlgorithmFactory.exists("LoadCIF"):
        unittest.main()
コード例 #6
0
        calTable.addRow([22, 2490.42282292])
        calTable.addRow([23, 2490.49334316])
        calTable.addRow([24, 2498.83911141])
        calTable.addRow([25, 2498.85314962])
        calTable.addRow([26, 2498.89526313])
        calTable.addRow([27, 2498.96544859])
        calTable.addRow([28, 2507.31101837])
        calTable.addRow([29, 2507.32498986])
        calTable.addRow([30, 2507.36690322])
        calTable.addRow([31, 2507.43675513])

        ws = mtd["testWS"]
        startPos = ws.getInstrument().getComponentByName(component).getPos()
        startRot = ws.getInstrument().getComponentByName(component).getRotation().getEulerAngles("YZX") #YZX
        AlignComponents(CalibrationTable="calTable",
                        Workspace="testWS",
                        ComponentList=component,
                        AlphaRotation=True)
        ws = mtd["testWS"]
        endPos = ws.getInstrument().getComponentByName(component).getPos()
        endRot = ws.getInstrument().getComponentByName(component).getRotation().getEulerAngles("YZX") #YZX
        self.assertEqual(startPos, endPos)
        self.assertAlmostEqual(endRot[0],45.0,places=0)
        self.assertEqual(startRot[1], endRot[1])
        self.assertEqual(startRot[2], endRot[2])

if __name__ == "__main__":
    # Only test is Algorithm is loaded
    if AlgorithmFactory.exists("AlignComponents"):
        unittest.main()
コード例 #7
0
        calTable.addRow([25, 2498.85314962])
        calTable.addRow([26, 2498.89526313])
        calTable.addRow([27, 2498.96544859])
        calTable.addRow([28, 2507.31101837])
        calTable.addRow([29, 2507.32498986])
        calTable.addRow([30, 2507.36690322])
        calTable.addRow([31, 2507.43675513])

        ws = mtd["testWS"]
        startPos = ws.getInstrument().getComponentByName(component).getPos()
        startRot = ws.getInstrument().getComponentByName(
            component).getRotation().getEulerAngles("YZX")  #YZX
        AlignComponents(CalibrationTable="calTable",
                        Workspace="testWS",
                        ComponentList=component,
                        AlphaRotation=True)
        ws = mtd["testWS"]
        endPos = ws.getInstrument().getComponentByName(component).getPos()
        endRot = ws.getInstrument().getComponentByName(
            component).getRotation().getEulerAngles("YZX")  #YZX
        self.assertEqual(startPos, endPos)
        self.assertAlmostEqual(endRot[0], 45.0, places=0)
        self.assertEqual(startRot[1], endRot[1])
        self.assertEqual(startRot[2], endRot[2])


if __name__ == "__main__":
    # Only test is Algorithm is loaded
    if AlgorithmFactory.exists("AlignComponents"):
        unittest.main()
コード例 #8
0
ファイル: LoadCIFTest.py プロジェクト: rosswhitfield/mantid
class UBMatrixBuilderTest(unittest.TestCase):
    def setUp(self):
        self.builder = UBMatrixBuilder()
        self.valid_matrix = {
            u"_diffrn_orient_matrix_ub_11": u"-0.03",
            u"_diffrn_orient_matrix_ub_12": u"0.13",
            u"_diffrn_orient_matrix_ub_13": u"0.31",
            u"_diffrn_orient_matrix_ub_21": u"0.01",
            u"_diffrn_orient_matrix_ub_22": u"-0.31",
            u"_diffrn_orient_matrix_ub_23": u"0.14",
            u"_diffrn_orient_matrix_ub_31": u"0.34",
            u"_diffrn_orient_matrix_ub_32": u"0.02",
            u"_diffrn_orient_matrix_ub_33": u"0.02",
        }

    def test_getUBMatrix_invalid(self):
        for key in self.valid_matrix:
            tmp = self.valid_matrix.copy()
            del tmp[key]

            self.assertRaises(RuntimeError, self.builder._getUBMatrix, cifData=tmp)

    def test_getUBMatrix_correct(self):
        self.assertEqual(self.builder._getUBMatrix(self.valid_matrix), "-0.03,0.13,0.31,0.01,-0.31,0.14,0.34,0.02,0.02")


if __name__ == "__main__":
    # Only test if algorithm is registered (PyCifRW dependency).
    if AlgorithmFactory.exists("LoadCIF"):
        unittest.main()
コード例 #9
0
 def test_exists_returns_correct_value_for_given_args(self):
     self.assertTrue(AlgorithmFactory.exists('ConvertUnits'))  #any version
     self.assertTrue(AlgorithmFactory.exists('ConvertUnits',
                                             1))  #any version
     self.assertTrue(
         not AlgorithmFactory.exists('ConvertUnits', 100))  #any version
コード例 #10
0
 def test_exists_returns_correct_value_for_given_args(self):
     self.assertTrue(AlgorithmFactory.exists('ConvertUnits')) #any version
     self.assertTrue(AlgorithmFactory.exists('ConvertUnits', 1)) #any version
     self.assertTrue(not AlgorithmFactory.exists('ConvertUnits', 100)) #any version