def test_micro_slab(self): # test micro-slab representation by calculating reflectivity from a # structure with default interfacial profiles for all the components. # Then specify an Erf interface for the slab and check that the # reflectivity signal is the same. sio2 = self.sio2(100, 5) d2o = self.d2o(0, 4) s = self.air | sio2 | d2o s.contract = -1 q = np.linspace(0.01, 0.5, 101) reflectivity = s.reflectivity(q) sio2.interfaces = Erf() d2o.interfaces = Erf() micro_slab_reflectivity = s.reflectivity(q) # Should be within 1% # How close the micro-slicing is to the Nevot-Croce is going to # depend on the exact system you look at, and what slice thickness # is used. assert_allclose(micro_slab_reflectivity, reflectivity, rtol=0.01) # test out user defined roughness type class Cauchy(Interface): def __call__(self, x, loc=0, scale=1): return cauchy.cdf(x, loc=loc, scale=scale) c = Cauchy() sio2.interfaces = c s.reflectivity(q) # imaginary part of micro slab should be calculated in same way as # real part fronting = SLD(1 + 1j) layer = SLD(4 + 4j) backing = SLD(6 + 6j) s = fronting | layer(100, 4) | backing(0, 4) s[1].interfaces = Erf() s[-1].interfaces = Erf() slabs = s.slabs() assert_almost_equal(slabs[:, 1], slabs[:, 2])
def test_interface(self): # can we set the interface property correctly c = self.sio2(10, 3) assert c.interfaces is None c.interfaces = Erf() assert isinstance(c.interfaces, Erf) c.interfaces = [Erf()] assert isinstance(c.interfaces, Erf) c.interfaces = None assert c.interfaces is None import pytest with pytest.raises(ValueError): c.interfaces = [1] # because len(c.slabs()) = 1 with pytest.raises(ValueError): c.interfaces = [Erf(), Erf()]
def test_erf(self): i = Erf() profile = i(self.x, scale=1.1, loc=-1.) assert_equal(profile, norm.cdf(self.x, scale=1.1, loc=-1.))