# profile - Model profile¶

 Microslabs Manage the micro slab representation of a model. blend blend function build_profile Convert a step profile to a smooth profile. compute_limited_sigma

Scattering length density profile.

In order to render a reflectometry model, the theory function calculator renders each layer in the model for each energy in the probe. For slab layers this is easy: just accumulate the slabs, with the 1-$$\sigma$$ Gaussian interface width between the slabs. For freeform or functional layers, this is more complicated. The rendering needs to chop each layer into microslabs and evaluate the profile at each of these slabs.

## Example¶

This example sets up a model which uses tanh to transition from silicon to gold in 20 Å with 2 Å steps.

First define the profile, and put in the substrate:

>>> S = Microslabs(nprobe=1, dz=2)
>>> S.clear()
>>> S.append(w=0, rho=2.07)


Next add the interface. This uses microslabs() to select the points at which the interface is evaluated, much like you would do when defining your own special layer type. Note that the points Pz are in the center of the micro slabs. The width of the final slab may be different. You do not need to use fixed width microslabs if you can more efficiently represent the profile with a smaller number of variable width slabs, but contract_profile() serves the same purpose with less work on your part.

>>> from numpy import tanh
>>> Pw, Pz = S.microslabs(20)
>>> print("widths = %s ..."%(" ".join("%g"%v for v in Pw[:5])))
widths = 2 2 2 2 2 ...
>>> print("centers = %s ..."%(" ".join("%g"%v for v in Pz[:5])))
centers = 1 3 5 7 9 ...
>>> rho = (1-tanh((Pz-10)/5))/2*(2.07-4.5)+4.5
>>> S.extend(w=Pw, rho=[rho])


Finally, add the incident medium and see the results. Note that rho is a matrix, with one column for each incident energy. We are only using one energy so we only show the first column.

>>> S.append(w=0, rho=4.5)
>>> print("width = %s ..."%(" ".join("%g"%v for v in S.w[:5])))
width = 0 2 2 2 2 ...
>>> print("rho = %s ..."%(" ".join("%.2f"%v for v in S.rho[0, :5])))
rho = 2.07 2.13 2.21 2.36 2.63 ...


Since irho and sigma were not specified, they will be zero.

>>> print("sigma = %s ..."%(" ".join("%g"%v for v in S.sigma[:5])))
sigma = 0 0 0 0 0 ...
>>> print("irho = %s ..."%(" ".join("%g"%v for v in S.irho[0, :5])))
irho = 0 0 0 0 0 ...

class refl1d.profile.Microslabs(nprobe, dz=1)[source]

Bases: object

Manage the micro slab representation of a model.

In order to compute reflectivity, we need a series of slabs with thickness, roughness and scattering potential for each slab. Because scattering potentials are probe dependent we store an array of potentials for each probe value.

Some slab models use non-uniform layers, and so need the additional parameter of dz for the step size within the layer.

The space for the slabs is saved even after reset, in preparation for a new set of slabs from different fitting parameters.

add_magnetism(anchor, w, rhoM=0, thetaM=270.0, sigma=0)[source]

Note that sigma is a pair (interface_below, interface_above) representing the magnetic roughness, which may be different from the nuclear roughness at the layer boundaries.

append(w=0, sigma=0, rho=0, irho=0)[source]

Extend the micro slab model with a single layer.

clear()[source]

Reset the slab model so that none are present.

extend(w=0, sigma=0, rho=0, irho=0)[source]

Extend the micro slab model with the given layers.

finalize(step_interfaces, dA)[source]

Rendering complete.

Call this method after the microslab model has been constructed, so any post-rendering processes can be completed.

In addition to clearing any width from the substrate and the surface surround, this will align magnetic and nuclear slabs, convert interfaces to step interfaces if desired, and merge slabs with similar scattering potentials to reduce computation time.

step_interfaces is True if interfaces should be rendered using slabs.

dA is the tolerance to use when deciding if similar layers can be merged.

irho

Absorption (10^-6 number density)

ismagnetic

True if there are magnetic materials in any slab

limited_sigma(limit=0)[source]

Limit the roughness by some fraction of layer thickness.

This function should be called before finalize(), but after all slabs have been added to the profile.

limit is the number of times sigma has to fit in the layers on either side of the interface. The returned sigma is truncated to min(wlow, whigh)/limit where wlow is the thickness of the layer below the interface, and whigh is the thickness above the interface. A limit value of 0 returns the original sigma. Although a gaussian inteface extends to infinity, in practice setting a limit of 3 allows the layer to reach its bulk value, with no cross talk between the interfaces. For very large roughnesses, the blending algorithm allows the sld beyond the interface to bleed through the entire layer and into the next. In this case the roughness should be the same on both sides of the layer to avoid artifacts at the interface.

Magnetic roughness is ignored for now.

magnetic_smooth_profile(dz=0.1)[source]

Return a profile representation of the magnetic microslab structure.

magnetic_step_profile()[source]

Return a step profile representation of the microslab structure.

Nevot-Croce interfaces are not represented.

microslabs(thickness=0)[source]

Return a set of microslabs for a layer of the given thickness.

The step size slabs.dz was defined when the Microslabs object was created.

This is a convenience function. Layer definitions can choose their own slices so long as the step size is approximately slabs.dz in the varying region.

Parameters: thickness : float | A Layer thickness widths: vector | A Microslab widths centers: vector | A Microslab centers
repeat(start=0, count=1, interface=0)[source]

Extend the model so that there are count versions of the slabs from start to the final slab.

This is equivalent to L.extend(L[start:]*(count-1)) for list L.

rho

Scattering length density (10^-6 number density)

sigma

rms roughness (A)

smooth_profile(dz=0.1)[source]

Return a smooth profile representation of the microslab structure

Nevot-Croce roughness is approximately represented, though the calculation is incorrect for layers with large roughness compared to the thickness.

The returned profile has uniform step size dz.

step_profile()[source]

Return a step profile representation of the microslab structure.

Nevot-Croce interfaces are not represented.

surface_sigma

roughness for the current top layer, or nan if substrate

thickness()[source]

Total thickness of the profile.

Note that thickness includes the thickness of the substrate and surface layers. Normally these will be zero, but the contract profile operation may result in large values for either.

w

Thickness (A)

refl1d.profile.blend(z, sigma, offset)[source]

blend function

Given a Gaussian roughness value, compute the portion of the neighboring profile you expect to find in the current profile at depth z.

refl1d.profile.build_profile(z, offset, roughness, value)[source]

Convert a step profile to a smooth profile.

z calculation points offset offset for each interface roughness roughness of each interface value target value for each slab max_rough limit the roughness to a fraction of the layer thickness

refl1d.profile.compute_limited_sigma(thickness, roughness, limit)[source]