Ejemplo n.º 1
0
def resolution_test(slabs, data):
    stk = Stack()
    for i, slab in enumerate(slabs[::-1]):
        m = SLD(f"layer {i}", rho=slab[1], irho=slab[2])
        stk |= m(thickness=slab[0], interface=slab[-1])

    probe = QProbe(Q=data[:, 0], dQ=data[:, 3])
    probe.oversample(21, seed=1)

    try:
        M = Experiment(stk, probe)
        _, R = M.reflectivity()
        np.testing.assert_allclose(R, data[:, 1], rtol=0.033)
    except AssertionError:
        # Probe oversampling did not work.
        # make our own oversampling with a linearly spaced array
        warnings.warn(
            "QProbe oversampling didn't work. Trying linearly spaced points",
            RuntimeWarning,
        )
        argmin = np.argmin(data[:, 0])
        argmax = np.argmax(data[:, 0])

        probe.calc_Qo = np.linspace(
            data[argmin, 0] - 3.5 * data[argmin, 3],
            data[argmax, 0] + 3.5 * data[argmax, 3],
            21 * len(data),
        )
        M = Experiment(stk, probe)

        _, R = M.reflectivity()
        np.testing.assert_allclose(R, data[:, 1], rtol=0.033)
Ejemplo n.º 2
0
    def calculate_reflectivity(self, model_description, q, q_resolution=0.025):
        """
        Reflectivity calculation using refl1d

        :param model_description: dict that holds parameters for the
                                  theoretical Refl1D model.

            Example dict for paramters:
            {
                'back_sld': 2.07,
                'back_roughness': 1.0,
                'front_sld': 0,
                'scale': 1,
                'background': 0
                'layers': [{
                    'thickness': 10,
                    'sld': 3.5,
                    'isld': 0,
                    'roughness': 2}]
            }
        :param q: Momentum transfer (Q) to use to calculate the model
        :param q_resolution: Momentum transfer resolution to multiply by Q
        :return: Calculate reflectivity of the theoretical model
        """
        from refl1d.names import \
            Experiment, \
            Parameter, \
            QProbe, \
            Slab, \
            SLD

        zeros = np.zeros(len(q))
        dq = q_resolution * q
        # The QProbe object represents the beam
        probe = QProbe(q, dq, data=(zeros, zeros))
        sample = Slab(material=SLD(name='back',
                                   rho=model_description['back_sld']),
                      interface=model_description['back_roughness'])

        # Add each layer
        for i, layer in enumerate(model_description['layers']):
            sample = sample | Slab(material=SLD(
                name='layer%s' % i, rho=layer['sld'], irho=layer['isld']),
                                   thickness=layer['thickness'],
                                   interface=layer['roughness'])
        sample = sample | Slab(
            material=SLD(name='front', rho=model_description['front_sld']))
        probe.background = Parameter(value=model_description['background'],
                                     name='background')
        expt = Experiment(probe=probe, sample=sample)
        q, r = expt.reflectivity()
        return model_description['scale'] * r
Ejemplo n.º 3
0
def test():
    import warnings
    # TODO: hard-code target output rather than relying on refl1d on the path
    try:
        from refl1d.names import silicon, air, QProbe, Experiment
    except ImportError:
        warnings.warn("Not testing Fresnel since refl1d is not on path")
        return

    # Rough silicon with an anomolously large absorbtion
    fresnel = Fresnel(rho=2.07, irho=0, sigma=20)

    sample = silicon(0, 20) | air
    Q = np.linspace(0, 5, 11)
    probe = QProbe(Q, Q * 0.02)
    m = Experiment(sample=sample, probe=probe)
    Rf = fresnel(Q)
    Rm = m.reflectivity()
    #print numpy.vstack((Q,Rf,Rm)).T

    # This is failing because reflectometry.model1d is failing; why that
    # is so has not yet been determined.
    relerr = np.linalg.norm((Rf - Rm) / Rm)
    assert relerr < 1e-10, "relative error is %g" % relerr
Ejemplo n.º 4
0
def test():
    import warnings
    # TODO: hard-code target output rather than relying on refl1d on the path
    try:
        from refl1d.names import silicon, air, QProbe, Experiment
    except ImportError:
        warnings.warn("Not testing Fresnel since refl1d is not on path")
        return

    # Rough silicon with an anomolously large absorbtion
    fresnel = Fresnel(rho=2.07, irho=0, sigma=20)

    sample =  silicon(0,20) | air
    Q = np.linspace(0, 5, 11)
    probe = QProbe(Q, Q*0.02)
    m = Experiment(sample=sample, probe=probe)
    Rf = fresnel(Q)
    Rm = m.reflectivity()
    #print numpy.vstack((Q,Rf,Rm)).T

    # This is failing because reflectometry.model1d is failing; why that
    # is so has not yet been determined.
    relerr = np.linalg.norm((Rf-Rm)/Rm)
    assert relerr < 1e-10, "relative error is %g"%relerr