示例#1
0
    def testfrom_string(self):
        self.assertEqual(from_string('Al Ka1'), Transition(13, siegbahn='Ka1'))
        self.assertEqual(from_string('Al K-L3'), Transition(13,
                                                            siegbahn='Ka1'))
        self.assertEqual(from_string('Al Ka'), Ka(13))
        self.assertEqual(from_string('Al K-L(2,3)'), Ka(13))
        self.assertEqual(from_string('Al K'), K_family(13))

        self.assertRaises(ValueError, from_string, 'Al K a1')
        self.assertRaises(ValueError, from_string, 'Al Kc1')
示例#2
0
    def testadd_kratio(self):
        standard = Material('U90', {92: 0.9, 49: 0.1})
        self.m.add_kratio(La(92), 0.5, standard=standard)

        self.assertTrue(self.m.has_kratio(La(92)))
        self.assertAlmostEqual(0.5, self.m.get_kratios()[1], 4)

        self.m.add_kratio(Ka(13), 0.2, unc=0.125)

        self.assertTrue(self.m.has_kratio(Ka(13)))
        self.assertAlmostEqual(0.2, self.m.get_kratios()[0], 4)

        self.assertRaises(ValueError, self.m.add_kratio, La(92), 0.1)
        self.assertRaises(ValueError, self.m.add_kratio, Ka(14), -0.1)
示例#3
0
    def testgroup(self):
        # Ka
        transitions = Ka(79)
        self.assertEqual(2, len(transitions))

        # Kb
        transitions = Kb(79)
        self.assertEqual(5, len(transitions))

        # La
        transitions = La(79)
        self.assertEqual(2, len(transitions))

        # Lb
        transitions = Lb(79)
        self.assertEqual(11, len(transitions))

        # Lg
        transitions = Lg(79)
        self.assertEqual(9, len(transitions))

        # Ma
        transitions = Ma(79)
        self.assertEqual(2, len(transitions))

        # Mb
        transitions = Mb(79)
        self.assertEqual(1, len(transitions))

        # Mg
        transitions = Mg(79)
        self.assertEqual(1, len(transitions))
示例#4
0
    def setUp(self):
        unittest.TestCase.setUp(self)

        iterator_class = Heinrich1972Iterator
        convergor_class = CompositionConvergor
        calculator_class = SimpleCalculator
        worker_class = Worker

        options = Options('PAP')
        options.beam.energy_eV = 20000
        options.limits.add(ShowersLimit(100))

        detector = PhotonIntensityDetector((radians(50), radians(55)),
                                           (0.0, radians(360.0)))

        self.m = Measurement(options, options.geometry.body, detector)
        self.m.add_kratio(Ka(29), 0.2470)
        self.m.add_rule(ElementByDifferenceRule(79))

        self.outputdir = tempfile.mkdtemp()

        self.runner = Runner(worker_class,
                             iterator_class,
                             convergor_class,
                             calculator_class,
                             self.outputdir,
                             limit=0.1)
示例#5
0
    def setUp(self):
        TestCase.setUp(self)

        baseops = Options()
        baseops.detectors['xray'] = PhotonIntensityDetector((0, 1), (0, 3))

        self.m = Measurement(baseops)
        self.m.add_kratio(Ka(29), 0.2470, 0.004)
示例#6
0
    def testextract_kratios(self):
        list_values = [(200e-9,), (250e-9,)]
        list_options = self.exp.create_unknown_options(list_values)

        intensities = create_intensity_dict(Ka(29), et=(4.0, 0.0))
        results1 = Results(list_options[0],
                           {'xray': PhotonIntensityResult(intensities)})

        intensities = create_intensity_dict(Ka(29), et=(8.0, 0.0))
        results2 = Results(list_options[1],
                           {'xray': PhotonIntensityResult(intensities)})

        intensities = self.exp.extract_unknown_intensities([results1, results2])

        self.assertEqual(2, len(intensities))
        self.assertAlmostEqual(4.0, intensities[0][0], 4)
        self.assertAlmostEqual(8.0, intensities[1][0], 4)
示例#7
0
    def testextract_unknown_intensities(self):
        unkgeometry = Substrate(pure(49))
        options = self.m.create_unknown_options('meas', unkgeometry)

        intensities = create_intensity_dict(Ka(29), et=(4.0, 0.0))
        results = Results(options, {'xray': PhotonIntensityResult(intensities)})

        unkintensities = self.m.extract_unknown_intensities(results)

        self.assertEqual(1, len(unkintensities))
        self.assertAlmostEqual(4.0, unkintensities[0], 4)
示例#8
0
    def testextract_standard_intensities(self):
        list_options = self.exp.create_standard_options()
        stdoptions = list_options[0]

        intensities = create_intensity_dict(Ka(29), et=(8.0, 0.0))
        stdresults = Results(stdoptions,
                             {'xray': PhotonIntensityResult(intensities)})

        stdintensities = self.exp.extract_standard_intensities([stdresults])

        self.assertEqual(1, len(stdintensities))
        self.assertAlmostEqual(8.0, stdintensities[0], 4)
示例#9
0
    def testadd_kratio(self):
        standard = Sphere(Material('U90', {92: 0.9, 49: 0.1}), 1e-6)
        self.m.add_kratio(La(92), 0.5, standard=standard)

        self.assertTrue(self.m.has_kratio(92))
        self.assertEqual('U90', self.m.get_standards()[92].material.name)
        self.assertAlmostEqual(0.5, self.m.get_kratios()[92][0], 4)
        self.assertAlmostEqual(0.0, self.m.get_kratios()[92][1], 4)
        self.assertIn(La(92), self.m.get_transitions())

        self.m.add_kratio(Ka(13), 0.2, unc=0.125)

        self.assertTrue(self.m.has_kratio(13))
        self.assertEqual('Aluminium', self.m.get_standards()[13].material.name)
        self.assertAlmostEqual(0.2, self.m.get_kratios()[13][0], 4)
        self.assertAlmostEqual(0.125, self.m.get_kratios()[13][1], 4)
        self.assertIn(Ka(13), self.m.get_transitions())

        self.assertRaises(ValueError, self.m.add_kratio, Ka(92), 0.1)
        self.assertRaises(ValueError, self.m.add_kratio, Ka(79), 0.1)
        self.assertRaises(ValueError, self.m.add_kratio, Ka(14), -0.1)
示例#10
0
    def testextract_standard_intensities(self):
        list_options = self.m.create_standard_options('std')
        stdoptions = list_options[0]

        intensities = create_intensity_dict(Ka(29), et=(8.0, 0.0))
        results = {'xray': PhotonIntensityResult(intensities)}
        stdresults = Results(stdoptions, results)

        dict_results = {'std+Cu Ka': stdresults}
        stdintensities = self.m.extract_standard_intensities('std', dict_results)

        self.assertEqual(1, len(stdintensities))
        self.assertAlmostEqual(8.0, stdintensities[0], 4)
示例#11
0
    def setUp(self):
        TestCase.setUp(self)

        options = Options('PAP')
        options.beam.energy_eV = 20000

        detector = PhotonIntensityDetector((radians(50.0), radians(55)),
                                           (0.0, radians(360.0)))

        self.m = Measurement(options, options.geometry.body, detector)

        self.m.add_kratio(Ka(29), 0.2470, 0.004)
        self.m.add_rule(ElementByDifferenceRule(79))
示例#12
0
    def setUp(self):
        TestCase.setUp(self)

        geometry = MultiLayers(pure(29))
        geometry.add_layer(Material("AuPd", {79: 0.5, 46: 0.5}), 100e-9)

        baseops = Options()
        baseops.detectors['xray'] = PhotonIntensityDetector((0, 1), (0, 3))
        meas = Measurement(baseops)
        meas.add_kratio(Ka(29), 0.2470, 0.004)

        getter = lambda geometry: geometry.layers[0].thickness_m
        setter = lambda geometry, val: setattr(geometry.layers[0], 'thickness_m', val)
        param = Parameter(getter, setter, 100e-9, 10e-9, 500e-9)

        self.exp = Experiment(geometry, [meas], [param])
示例#13
0
    def testfrom_xml(self):
        element = self.m.to_xml()
        m = Measurement.from_xml(element)

        self.assertAlmostEqual(20000, m.options.beam.energy_eV, 4)
        self.assertEqual(m.unknown_body, m.options.geometry.body)
        self.assertAlmostEqual(0.434867, m.detector.solidangle_sr, 4)

        transitions = m.get_transitions()
        self.assertEqual(1, len(transitions))
        self.assertIn(Ka(29), transitions)

        kratios = m.get_kratios()
        self.assertEqual(1, len(kratios))
        self.assertAlmostEqual(0.247, kratios[29][0], 4)
        self.assertAlmostEqual(0.004, kratios[29][1], 4)

        standards = m.get_standards()
        self.assertEqual(1, len(standards))
        self.assertEqual('Copper', standards[29].material.name)

        rules = m.get_rules()
        self.assertEqual(1, len(rules))
示例#14
0
 def testhas_kratio(self):
     self.assertTrue(self.m.has_kratio(Ka(29)))
     self.assertFalse(self.m.has_kratio(La(29)))
示例#15
0
    def testget_transitions(self):
        transitions = self.m.get_transitions()

        self.assertEqual(1, len(transitions))
        self.assertIn(Ka(29), transitions)
示例#16
0
 def testremove_kratio(self):
     self.m.remove_kratio(Ka(29))
     self.assertFalse(self.m.has_kratio(Ka(29)))
     self.assertEqual(0, len(self.m.get_kratios()))
示例#17
0
from pymontecarlo.reconstruction.experiment import Experiment
from pymontecarlo.reconstruction.measurement import Measurement
from pymontecarlo.reconstruction.parameter import Parameter
from pymontecarlo.reconstruction.reconstructor import Reconstructor

from pymontecarlo.input import Inclusion, pure, Material, Options, ShowersLimit, PhotonIntensityDetector, composition_from_formula

baseops = Options()
baseops.beam.energy_eV = 10e3
baseops.beam.diameter_m = 50e-9
baseops.detectors['xray'] = PhotonIntensityDetector.annular(
    radians(40.0), radians(5.0))
baseops.limits.add(ShowersLimit(1000))

meas1 = Measurement(baseops)
meas1.add_kratio(Ka(6),
                 0.5,
                 standard=Material('Fe3C', composition_from_formula('Fe3C')))


def setter1(geometry, val):
    geometry.inclusion_material.composition = {26: val, 6: '?'}


param1 = Parameter(setter1, 0.95, 0.0, 1.0)


def setter2(geometry, val):
    geometry.inclusion_diameter_m = val