예제 #1
0
    def test_func_interface(self):
        xr = xrd.XRDCalculator()

        # Test that functions and function arguments are properly
        # accepted/rejected
        # Case 1:
        # Wrong kind of function

        def bad_func(x):
            return x

        self.assertRaisesRegexp(ValueError,
                                "Invalid peak_func passed to set_peak_func",
                                xr.set_peak_func, bad_func)

        # Case 2:
        # Right function, wrong arguments

        def good_func(x, w, a, b, c=0.2):
            return x * w * a * b * c

        bad_args = [0]
        self.assertRaisesRegexp(
            ValueError, """Invalid number of peak_f_args passed to
                                    set_peak_func""", xr.set_peak_func,
            good_func, bad_args)
        # Case 3:
        # All good
        good_args = [0, 0]
        try:
            xr.set_peak_func(peak_func=good_func, peak_f_args=good_args)
        except:
            self.fail("Good function not accepted")
예제 #2
0
    def test_powder_peaks(self):
        xr = xrd.XRDCalculator()

        abc = [[3, 5, 10], [np.pi / 2, np.pi / 2, np.pi / 2]]
        peaks_nosym = xr.powder_peaks(latt_abc=abc)
        peaks_sym = xr.powder_peaks(latt_abc=abc, n=230, o=1)

        # A very crude test for now
        self.assertTrue(len(peaks_nosym.theta2) >= len(peaks_sym.theta2))
예제 #3
0
    def test_lebail_fit(self):
        xr = xrd.XRDCalculator()

        # Define a fake experimental spectrum to fit
        peak_n = 3
        th2_axis = np.linspace(0, np.pi, 1000)

        xpeaks = XraySpectrum(
            np.random.random(peak_n) * np.pi, [], [], [],
            np.random.random(peak_n) * 3.0 + 1.0, xr.lambdax)

        # Build a simulated spectrum
        xpeaks_exp_mock, simul_peaks = xr.spec_simul(xpeaks, th2_axis)
        # Now clear the intensities
        np.copyto(xpeaks.intensity, np.ones(peak_n))
        # And carry out the leBail fit
        xpeaks, simul_spec, simul_peaks, rwp = xr.lebail_fit(
            xpeaks, xpeaks_exp_mock)

        self.assertAlmostEqual(rwp, 0.0)