Ejemplo n.º 1
0
    def parse(self, element):
        tmpmodel = _ModelXMLHandler.parse(self, element)

        subelement = element.find('{http://pymontecarlo.sf.net}model')
        if subelement is None:
            raise ValueError("Element 'model' not found")
        base_model = self._parse_handlers('pymontecarlo.fileformat.options.model', subelement)

        model = UserDefinedMassAbsorptionCoefficientModel(base_model,
                                                          tmpmodel.reference)

        for subelement in element.iter('mac'):
            absorber = int(subelement.get('absorber'))

            if 'energy' in subelement.attrib:
                energy_or_transition = float(subelement.get('energy'))
            else:
                z = int(subelement.get('z'))
                src = int(subelement.get('src'))
                dest = int(subelement.get('dest'))
                energy_or_transition = Transition(z, src, dest)

            mac_m2_kg = float(subelement.text)
            model.add(absorber, energy_or_transition, mac_m2_kg)

        return model
Ejemplo n.º 2
0
class TestUserDefinedMassAbsorptionCoefficientModel(TestCase):

    def setUp(self):
        TestCase.setUp(self)

        self.m = UserDefinedMassAbsorptionCoefficientModel(MASS_ABSORPTION_COEFFICIENT.henke1993)
        self.m.add(29, 8.904e3, 200)

    def tearDown(self):
        TestCase.tearDown(self)

    def testskeleton(self):
        self.assertIs(MASS_ABSORPTION_COEFFICIENT.henke1993, self.m.base_model)
        self.assertAlmostEqual(200.0, self.m.defined_macs[(29, 8.904e3)], 4)
Ejemplo n.º 3
0
class TestUserDefinedMassAbsorptionCoefficientModelXMLHandler(unittest.TestCase):

    def setUp(self):
        unittest.TestCase.setUp(self)

        self.h = UserDefinedMassAbsorptionCoefficientModelXMLHandler()

        self.obj = UserDefinedMassAbsorptionCoefficientModel(MASS_ABSORPTION_COEFFICIENT.henke1993, 'ref1')
        self.obj.add(29, 8.904e3, 200)
        self.obj.add(29, Transition(29, siegbahn='Ka1'), 201)

        etree.register_namespace('mc', 'http://pymontecarlo.sf.net')
        source = BytesIO(b'<mc:userDefinedMassAbsorptionCoefficientModel xmlns:mc="http://pymontecarlo.sf.net" name="user defined mass absorption coefficient" reference="ref1" type="mass absorption coefficient"><mc:model name="Henke 1993" reference="B.L. Henke, E.M. Gullikson and J.C. Davis (1993). X-ray interactions: photoabsorption, scattering, transmission, and reflection at E=50-30000 eV, Z=1-92, Atomic Data and Nuclear Data Tables, 54, pp. 181-342" type="mass absorption coefficient" /><mac absorber="29" energy="8904.0">200</mac><mac absorber="29" z="29" src="4" dest="1">201</mac></mc:userDefinedMassAbsorptionCoefficientModel>')
        self.element = etree.parse(source).getroot()

    def tearDown(self):
        unittest.TestCase.tearDown(self)

    def testcan_parse(self):
        self.assertTrue(self.h.can_parse(self.element))

    def testparse(self):
        obj = self.h.parse(self.element)

        self.assertEqual('user defined mass absorption coefficient', obj.name)
        self.assertEqual('ref1', obj.reference)
        self.assertEqual(MASS_ABSORPTION_COEFFICIENT, obj.type)

        self.assertIs(MASS_ABSORPTION_COEFFICIENT.henke1993, obj.base_model)

        self.assertEqual(2, len(obj.defined_macs))
        self.assertAlmostEqual(200.0, obj.defined_macs[(29, 8.904e3)], 4)
        self.assertAlmostEqual(201.0, obj.defined_macs[(29, Transition(29, siegbahn='Ka1'))], 4)

    def testcan_convert(self):
        self.assertTrue(self.h.can_convert(self.obj))

    def testconvert(self):
        element = self.h.convert(self.obj)

        self.assertEqual('user defined mass absorption coefficient', element.get('name'))
        self.assertEqual(str(MASS_ABSORPTION_COEFFICIENT), element.get('type'))

        subelement = element.find('{http://pymontecarlo.sf.net}model')
        self.assertEqual('Henke 1993', subelement.get('name'))

        subelements = list(element.iter('mac'))
        self.assertEqual(2, len(subelements))
Ejemplo n.º 4
0
    def setUp(self):
        unittest.TestCase.setUp(self)

        self.h = UserDefinedMassAbsorptionCoefficientModelXMLHandler()

        self.obj = UserDefinedMassAbsorptionCoefficientModel(MASS_ABSORPTION_COEFFICIENT.henke1993, 'ref1')
        self.obj.add(29, 8.904e3, 200)
        self.obj.add(29, Transition(29, siegbahn='Ka1'), 201)

        etree.register_namespace('mc', 'http://pymontecarlo.sf.net')
        source = BytesIO(b'<mc:userDefinedMassAbsorptionCoefficientModel xmlns:mc="http://pymontecarlo.sf.net" name="user defined mass absorption coefficient" reference="ref1" type="mass absorption coefficient"><mc:model name="Henke 1993" reference="B.L. Henke, E.M. Gullikson and J.C. Davis (1993). X-ray interactions: photoabsorption, scattering, transmission, and reflection at E=50-30000 eV, Z=1-92, Atomic Data and Nuclear Data Tables, 54, pp. 181-342" type="mass absorption coefficient" /><mac absorber="29" energy="8904.0">200</mac><mac absorber="29" z="29" src="4" dest="1">201</mac></mc:userDefinedMassAbsorptionCoefficientModel>')
        self.element = etree.parse(source).getroot()
Ejemplo n.º 5
0
    def setUp(self):
        TestCase.setUp(self)

        self.m = UserDefinedMassAbsorptionCoefficientModel(MASS_ABSORPTION_COEFFICIENT.henke1993)
        self.m.add(29, 8.904e3, 200)