Пример #1
0
    def test_constant_smearing(self):
        # check that constant dq/q smearing is the same as point by point
        dqvals = 0.05 * self.qvals
        calc = reflect.reflectivity(self.qvals, self.coefs,
                              **{'dqvals': dqvals, 'quad_order': 'ultimate'})
        calc2 = reflect.reflectivity(self.qvals, self.coefs,
                               **{'dqvals': 5.})

        assert_allclose(calc, calc2, rtol=0.011)
Пример #2
0
def smearing_precision_comparison(maxorder=50):
    '''
    a quick script to see how the smeared reflectivity changes as a function of
    smearing precision
    '''
    # import q values and dqvalues from the smearing test
    theoretical = np.loadtxt(
        'refnx/analysis/test/smeared_theoretical.txt')
    qvals, rvals, dqvals = np.hsplit(theoretical, 3)
    qvals = qvals.flatten()
    dqvals = dqvals.flatten()

    # coefficients for the model
    a = np.zeros((12))
    a[0] = 1.
    a[1] = 1.
    a[4] = 2.07
    a[7] = 3
    a[8] = 100
    a[9] = 3.47
    a[11] = 2

    # setup an array for the smeared rvals.
    smeared_rvals = np.zeros((maxorder + 1, qvals.size))

    # now output all the smearing.
    t0 = time()
    smeared_rvals[0, :] = reflect.reflectivity(
        qvals, a, **{'dqvals': dqvals, 'quad_order': 'ultimate'})
    t1 = time()
    print('ultimate takes %f' % (t1 - t0))

    for idx in range(1, maxorder + 1):
        t0 = time()
        smeared_rvals[idx, :] = reflect.reflectivity(qvals,
                                                     a,
                                                     **{'dqvals': dqvals,
                                                        'quad_order': idx})
        t1 = time()
        print(idx, ' takes %f' % (t1 - t0))
    np.savetxt('smearing_comp', smeared_rvals.T)
Пример #3
0
    def test_smearedabeles(self):
        # test smeared reflectivity calculation with values generated from
        # Motofit (quadrature precsion order = 13)
        theoretical = np.loadtxt(os.path.join(path, 'smeared_theoretical.txt'))
        qvals, rvals, dqvals = np.hsplit(theoretical, 3)
        '''
        the order of the quadrature precision used to create these smeared
        values in Motofit was 13.
        Do the same here
        '''
        calc = reflect.reflectivity(qvals.flatten(), self.coefs,
                              **{'dqvals': dqvals.flatten(), 'quad_order': 13})

        assert_almost_equal(rvals.flatten(), calc)
Пример #4
0
    def test_smearedabeles_reshape(self):
        # test smeared reflectivity calculation with values generated from
        # Motofit (quadrature precsion order = 13)
        theoretical = np.loadtxt(os.path.join(path, 'smeared_theoretical.txt'))
        qvals, rvals, dqvals = np.hsplit(theoretical, 3)
        '''
        the order of the quadrature precision used to create these smeared
        values in Motofit was 13.
        Do the same here
        '''
        reshaped_q = np.reshape(qvals, (2, 250))
        reshaped_r = np.reshape(rvals, (2, 250))
        reshaped_dq = np.reshape(dqvals, (2, 250))
        calc = reflect.reflectivity(reshaped_q, self.coefs,
                              **{'dqvals': reshaped_dq, 'quad_order': 13})

        assert_almost_equal(calc, reshaped_r, 15)
Пример #5
0
    def test_abeles(self):
        # test reflectivity calculation with values generated from Motofit
        calc = reflect.reflectivity(self.qvals, self.coefs)

        assert_almost_equal(calc, self.rvals)
Пример #6
0
def reflect_fitfunc(q, params, *args):
    coefs = np.asfarray(list(params.valuesdict().values()))
    return np.log10(reflect.reflectivity(q, coefs, parallel=True))