예제 #1
0
    def test_mixed_reflectivity_model(self):
        # test that mixed area model works ok.

        # should be same as data generated from Motofit
        sio2 = SLD(3.47, name='SiO2')
        air = SLD(0, name='air')
        si = SLD(2.07, name='Si')

        s1 = air | sio2(100, 2) | si(0, 3)
        s2 = air | sio2(100, 2) | si(0, 3)

        mixed_model = MixedReflectModel([s1, s2], [0.4, 0.3], dq=0)
        assert_almost_equal(mixed_model(self.qvals), self.rvals * 0.7)

        # now try out the mixed model compared to sum of individual models
        # with smearing, but no background.
        s1 = air | sio2(100, 2) | si(0, 2)
        s2 = air | sio2(50, 3) | si(0, 1)

        mixed_model = MixedReflectModel([s1, s2], [0.4, 0.3], dq=5, bkg=0)
        indiv1 = ReflectModel(s1, bkg=0)
        indiv2 = ReflectModel(s2, bkg=0)

        assert_almost_equal(mixed_model(self.qvals),
                            (0.4 * indiv1(self.qvals) +
                             0.3 * indiv2(self.qvals)))

        # now try out the mixed model compared to sum of individual models
        # with smearing, and background.

        mixed_model.bkg.value = 1e-7
        assert_almost_equal(mixed_model(self.qvals),
                            (0.4 * indiv1(self.qvals) +
                             0.3 * indiv2(self.qvals) +
                             1e-7))
예제 #2
0
    def test_mixed_model(self):
        # test for MixedReflectModel
        air = SLD(0, name="air")
        sio2 = SLD(3.47, name="SiO2")
        si = SLD(2.07, name="Si")

        structure1 = air | sio2(100, 2) | si(0, 3)
        structure2 = air | sio2(50, 3) | si(0, 5)

        # this is out theoretical calculation
        mixed_model_y = 0.4 * structure1.reflectivity(self.qvals)
        mixed_model_y += 0.6 * structure2.reflectivity(self.qvals)

        mixed_model = MixedReflectModel([structure1, structure2], [0.4, 0.6],
                                        bkg=0,
                                        dq=0)

        assert_equal(mixed_model.scales, np.array([0.4, 0.6]))
        assert mixed_model.dq.value == 0

        assert_allclose(mixed_model_y, mixed_model(self.qvals), atol=1e-13)

        # test repr of MixedReflectModel
        q = repr(mixed_model)
        r = eval(q)
        assert_equal(r.scales, np.array([0.4, 0.6]))
        assert r.dq.value == 0

        assert_allclose(mixed_model_y, r(self.qvals), atol=1e-13)
예제 #3
0
    def test_mixed_model(self):
        # test for MixedReflectModel
        air = SLD(0, name='air')
        sio2 = SLD(3.47, name='SiO2')
        si = SLD(2.07, name='Si')

        structure1 = air | sio2(100, 2) | si(0, 3)
        structure2 = air | sio2(50, 3) | si(0, 5)

        # this is out theoretical calculation
        mixed_model_y = 0.4 * structure1.reflectivity(self.qvals)
        mixed_model_y += 0.6 * structure2.reflectivity(self.qvals)

        mixed_model = MixedReflectModel([structure1, structure2], [0.4, 0.6],
                                        bkg=0, dq=0)

        assert_equal(mixed_model.scales, np.array([0.4, 0.6]))
        assert_(mixed_model.dq.value == 0)

        assert_equal(mixed_model_y, mixed_model(self.qvals))
예제 #4
0
    def insert_structure(self, row, structure):
        n = StructureNode(structure, self._model, self)

        data_object_node = find_data_object(self.index)
        data_object = data_object_node.data_object
        orig_model = data_object.model

        if len(self.structures) == 1:
            self._model.beginInsertRows(self.index, row, row)
            new_structures = [self.structures[0], structure]
            new_model = MixedReflectModel(new_structures,
                                          bkg=orig_model.bkg,
                                          dq=orig_model.dq)
            data_object.model = new_model
            data_object_node.set_reflect_model(new_model,
                                               constdq_q=self.constantdq_q)
            return

        # already a mixed model
        # we can't insert at a lower place than the 4rd row
        row = max(row, 4)
        self._model.beginInsertRows(self.index, row, row)

        # insert the structure
        orig_model.structures.insert(row - STRUCT_OFFSET, structure)
        v = 1 / len(orig_model.structures)
        sf = possibly_create_parameter(v, name="scale")
        orig_model.scales.insert(row - STRUCT_OFFSET, sf)

        self.insertChild(row, n)
        self._model.endInsertRows()

        # insert a scale factor
        self._model.beginInsertRows(
            self.child(0).index, row - STRUCT_OFFSET, row - STRUCT_OFFSET)
        # add a scale factor
        n = ParNode(sf, self._model, self.child(0))
        self.child(0).insertChild(row - STRUCT_OFFSET, n)
        self._model.endInsertRows()