Пример #1
0
def test_background_polynomial():
    Rp.assemble_global_x()
    Rp.bkgd[0] = 1
    assert np.all(
        np.isclose(Rp.background_polynomial(),
                   np.ones(len(Rp.two_theta), dtype=float)))

    Rp.bkgd = np.array([1, 2, 3], dtype=float)
    assert np.all(
        np.isclose(Rp.background_polynomial(),
                   1.0 + 2.0 * Rp.two_theta + 3.0 * Rp.two_theta_powers[2, :]))

    Rp.bkgd = np.array([0, 0, 0], dtype=float)
    assert np.all(
        np.isclose(Rp.background_polynomial(),
                   np.zeros(len(Rp.two_theta), dtype=float)))
Пример #2
0
    def __init__(self, phase_list,
        rietveld_plot=None,
        bkgd_refine=False,
        store_intermediate_state=False,
        show_plots=False,
        factr=DEFAULT_FACTR,
        mask=None,
        iprint=DEFAULT_IPRINT,
        maxiter=DEFAULT_MAXITER,
        m=DEFAULT_M,
        pgtol=DEFAULT_PGTOL,
        epsilon=DEFAULT_EPSILON,
        method=DEFAULT_METHOD,
        display=DEFAULT_DISPLAY,
        # input_weights=None,
        # composition_cutoff=default_composition_cutoff,
        ):
        """
            Given some list of phases, an instance of the refinery is initialized
            to readily run a refinement process.
        """
        self.phase_list = phase_list
        self.rietveld_plot = rietveld_plot
        self.bkgd_refine = bkgd_refine
        self.store_intermediate_state = store_intermediate_state
        self.show_plots = show_plots
        self.factr = factr
        self.iprint = iprint
        self.maxiter = maxiter
        self.m = m
        self.pgtol = pgtol
        self.epsilon = epsilon
        self.method = method
        self.display = display
        # self.composition_cutoff = composition_cutoff

        self.weighted_sum_of_I_squared = np.sum(
            RietveldPhases.I**2/RietveldPhases.sigma**2)

        for key in refinement_parameters.keys:
            if key in ("labels", "values", "uround", "l_limits", "u_limits"):
                if len(self.phase_list) > 0:
                    # self.x = np.hstack((RietveldPhases.global_x,
                    #    np.hstack((x.phase_x for x in self.phase_list))))
                    if key == "uround":
                        # print(RietveldPhases.global_parameters.x[key])
                        # print([phase.phase_parameters.x[key]
                        #             for phase in self.phase_list])
                        tmp = np.concatenate((
                            RietveldPhases.global_parameters.x[key],
                            np.concatenate(
                                [phase.phase_parameters.x[key]
                                    for phase in self.phase_list], axis=0))
                            , axis=0)
                    else:
                        tmp = np.hstack((RietveldPhases.global_parameters.x[key],
        np.hstack((phase.phase_parameters.x[key] for phase in self.phase_list))))
                else:
                    RietveldPhases.assemble_global_x()
                    tmp = RietveldPhases.global_parameters.x[key]
            setattr(self, "x_" + key, tmp)
        self.x = self.x_values
            # for key in refinement_parameters.keys:
            #    setattr(self, key, RietveldPhases.global_parameters.x[key])

        if self.bkgd_refine:
            if len(self.phase_list) > 0:
                self.raw_profile_state = np.sum(x.phase_profile() for x in
                    self.phase_list)
            else:
                self.raw_profile_state = np.zeros(len(RietveldPhases.two_theta))

        self.global_mask = np.isin(np.array(xrange(len(self.x))),
            np.array(xrange(len(RietveldPhases.global_x))))
        self.bkgd_mask = self.make_mask(["bkgd"])
        self.global_mask_no_bkgd = np.logical_xor(
            self.global_mask, self.bkgd_mask)
        self.scale_mask = self.make_mask(["sca"])

        if mask is not None:
            self.mask = mask
        elif self.bkgd_refine:
            self.mask = self.bkgd_mask
        else:
            self.mask = np.zeros(len(self.x),dtype=bool)

        self.set_compositions()

        # self.composition_by_volume = np.zeros(len(self.phase_list))
        # if input_weights is not None:
        #    self.composition_by_weight = input_weights
        # else: self.composition_by_weight = 100*np.ones(len(self.phase_list))


        n=len(RietveldPhases.global_x)
        self.phase_masks = []
        self.global_and_phase_masks = []
        for phase in self.phase_list:
            self.phase_masks.append(np.isin(np.array(xrange(len(self.x))),
                np.array(xrange(n,n+len(phase.phase_x)))))
            self.global_and_phase_masks.append(np.logical_or(
                self.global_mask_no_bkgd, self.phase_masks[-1]))
            n+=len(phase.phase_x)

        self.update_state()
        if self.rietveld_plot is not None:
            self.rietveld_plot.setplotdata()
            self.rietveld_plot.updateplotprofile(self.total_profile_state,
                wse=self.relative_differences_state)
Пример #3
0
def test_set_bkgd_order(test_phase):
    Rp.global_parameters.set_bkgd_order(3)
    Rp.assemble_global_x()
    assert len(Rp.bkgd) == 3
    assert len(test_phase.bkgd) == 3