Exemplo n.º 1
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])
 def load(cls, list_paths):
     """
     Creates a new interpolation runner that can interpolate kratios that were
     measured in experiments with different values of the same parameters.
     Note: Interpolation is only available for experiments with 2 parameters.
     
     :arg list_paths: a list of paths to experiment files.
     """
     
     list_experiments = []
     for path in list_paths:
         list_experiments.append(Experiment.load(path))
         
     return cls(list_experiments)
Exemplo n.º 3
0
    def load(cls, list_paths):
        """
        Creates a new interpolation runner that can interpolate kratios that were
        measured in experiments with different values of the same parameters.
        Note: Interpolation is only available for experiments with 2 parameters.
        
        :arg list_paths: a list of paths to experiment files.
        """

        list_experiments = []
        for path in list_paths:
            list_experiments.append(Experiment.load(path))

        return cls(list_experiments)
Exemplo n.º 4
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


param2 = Parameter(setter2, 200e-9, 150e-9, 250e-9)

inclusion_material = Material('CrC', {26: 0.95, 6: 0.05})
geometry = Inclusion(pure(26), inclusion_material, 200e-9)
exp = Experiment(geometry, [meas1], [param1, param2])

runner = LocalRunner(NISTMonte, '/tmp', nbprocesses=1)

optimizer = LevenbergMarquardtOptimzier()
reconstructor = Reconstructor(runner, optimizer, exp)
print reconstructor.reconstruct()
Exemplo n.º 5
0
class TestExperiment(TestCase):

    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])

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

    def testreference_kratios(self):
        kratios = self.exp.reference_kratios
        self.assertEqual(1, len(kratios))
        self.assertAlmostEqual(0.2470, kratios[0], 4)

    def testparameters_initial_values(self):
        vals = self.exp.parameters_initial_values
        self.assertEqual(1, len(vals))
        self.assertAlmostEqual(100e-9, vals[0], 13)

    def testparameters_constraints(self):
        constraints = self.exp.parameters_constraints
        self.assertEqual(1, len(constraints))
        self.assertAlmostEqual(10e-9, constraints[0][0], 13)
        self.assertAlmostEqual(500e-9, constraints[0][1], 13)

    def testcreate_standard_options(self):
        list_options = self.exp.create_standard_options()
        self.assertEqual(1, len(list_options))
        self.assertEqual('0+Cu Ka', list_options[0].name)

    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)

    def testcreate_geometry(self):
        values = [200e-9]
        geometry = self.exp.create_geometry(values)
        self.assertAlmostEqual(200e-9, geometry.layers[0].thickness_m, 13)

    def testcreate_unknown_options(self):
        list_values = [(200e-9,), (250e-9,)]
        list_options = self.exp.create_unknown_options(list_values)
        self.assertEqual(2, len(list_options))

        unkoptions = list_options[0]
        self.assertAlmostEqual(200e-9, unkoptions.geometry.layers[0].thickness_m, 13)

        unkoptions = list_options[1]
        self.assertAlmostEqual(250e-9, unkoptions.geometry.layers[0].thickness_m, 13)

    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)