flayer - Functional layers

FunctionalMagnetism Functional magnetism profile.
FunctionalProfile Generic profile function
class refl1d.flayer.FunctionalMagnetism(profile=None, tol=0.001, name=None, **kw)[source]

Bases: refl1d.magnetism.BaseMagnetism

Functional magnetism profile.


profile the profile function, suitably parameterized

tol is the tolerance for considering values equal

refl1d.magnetism.BaseMagnetism parameters

The profile function takes a depth vector z and returns a magnetism vector rhoM. For magnetic twist, return a pair of vectors (rhoM, thetaM). Constants can be returned for rhoM or thetaM. If thetaM is not provided it defaults to thetaM=270.

See FunctionalProfile for a description of the the profile function.

RESERVED = ('profile', 'tol', 'name', 'extent', 'dead_below', 'dead_above', 'interface_below', 'interface_above')
magnetic = True
render(probe, slabs, thickness, anchor, sigma)[source]
set_anchor(stack, index)[source]

Update the names of the magnetic parameters with the name of the layer if it has not already been set. This is necessary since we don’t know the layer name until after we have constructed the magnetism object.

class refl1d.flayer.FunctionalProfile(thickness=0, interface=0, profile=None, tol=0.001, magnetism=None, name=None, **kw)[source]

Bases: refl1d.model.Layer

Generic profile function


thickness the thickness of the layer

interface the roughness of the surface [not implemented]

profile the profile function, suitably parameterized

tol is the tolerance for considering values equal

magnetism magnetic profile associated with the layer

name is the layer name

The profile function takes a depth vector z returns a density vector rho. For absorbing profiles, return complex vector rho + irho*1j.

Fitting parameters are the available named arguments to the function. The first argument is a depth vector, which is the array of depths at which the profile is to be evaluated. It is guaranteed to be increasing, with step size 2*z[0].

Initial values for the function parameters can be given using name=value. These values can be scalars or fitting parameters. The function will be called with the current parameter values as arguments. The layer thickness can be computed as layer_thickness().

There is no mechanism for querying the larger profile to determine the value of the rho at the layer boundaries. If needed, this information will have to be communicated through shared parameters. For example:

L1 = SLD('L1', rho=2.07)
L3 = SLD('L3', rho=4)
def linear(z, rhoL, rhoR):
    rho = z * (rhoR-rhoL)/(z[-1]-z[0]) + rhoL
    return rho
profile = FunctionalProfile(100, 0, profile=linear,
                            rhoL=L1.rho, rhoR=L3.rho)
sample = L1 | profile | L3
RESERVED = ('thickness', 'interface', 'profile', 'tol', 'magnetism', 'name')



Find the layer at depth z.

Returns layer, start, end

interface = None
name = None

Returns a dictionary of parameters specific to the layer. These will be added to the dictionary containing interface, thickness and magnetism parameters.


Return a penalty value associated with the layer. This should be zero if the parameters are valid, and increasing as the parameters become more invalid. For example, if total volume fraction exceeds unity, then the penalty would be the amount by which it exceeds unity, or if z values must be sorted, then penalty would be the amount by which they are unsorted.

Note that penalties are handled separately from any probability of seeing a combination of layer parameters; the final solution to the problem should not include any penalized points.

render(probe, slabs)[source]

Use the probe to render the layer into a microslab representation.

thickness = None

Return a dictionary representation of the Slab object