sample.flayer - Functional layers¶
Functional magnetism profile. |
|
Generic profile function |
|
Find all magnetism objects in the stack and set their anchors. |
- class refl1d.sample.flayer.FunctionalMagnetism(profile=None, tol=0.001, name=None, start=None, end=None, thickness=None, pars=None, **kw)[source]¶
Bases:
BaseMagnetism
Functional magnetism profile.
Parameters:
profile the profile function, suitably parameterized
tol is the tolerance for considering values equal
refl1d.sample.magnetism.BaseMagnetism
parametersThe 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.- BASE_PARS = ('extent', 'dead_below', 'dead_above', 'interface_below', 'interface_above')¶
- dead_above: Parameter | Literal[None]¶
- dead_below: Parameter | Literal[None]¶
- extent: float¶
- interface_above: Parameter | Literal[None]¶
- interface_below: Parameter | Literal[None]¶
- magnetic = True¶
- name: str¶
- pars: Dict[str, Parameter] = None¶
- profile: Callable¶
- set_anchor(stack: Stack, index: str | int)[source]¶
Rebuild thickness calculation whenever the sample stack changes. Called from
set_magnetism_anchors()
.
- set_layer_name(name)¶
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.
- thickness: Parameter = None¶
- to_dict()¶
- tol: float = 0.001¶
- class refl1d.sample.flayer.FunctionalProfile(thickness=0, interface=0, profile=None, tol=0.001, magnetism=None, name=None, start=None, end=None, pars=None, **kw)[source]¶
Bases:
Layer
Generic profile function
Parameters:
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. z is guaranteed to be increasing, with step size 2*z[0]. The remaining profile arguments are added as fittable parameters to the layer.
The profile parameters can be initialized using key=value arguments to to FunctionalProfile. If the value is a sequence, then a list of parameters will be created, one for each sequence element. These will be converted to numpy vectors prior to calling the profile function. If no value is supplied, the parameter will use the default name=value from the profile function.
The attributes start and end are the SLD at at the start and end of the profile respectively. The rho and irho attributes for these SLDs can be used in parameter expressions for other layers. Note that each one is implemented as a separate call to the profile function, using z=0 for start and z=thickness for end.
Within the profile function 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
- constraints()¶
Constraints
- find(z)¶
Find the layer at depth z.
Returns layer, start, end
- interface: Constant = None¶
- property ismagnetic¶
- layer_parameters()¶
- magnetism: BaseMagnetism | None = None¶
- name: str = ''¶
- parameters()[source]¶
Returns a dictionary of parameters specific to the layer. These will be added to the dictionary containing interface, thickness and magnetism parameters.
- pars: Dict[str, Parameter] = None¶
- penalty()¶
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.
- profile: Callable = None¶
- thickness: Parameter¶
- tol: float = 0¶
- refl1d.sample.flayer.set_magnetism_anchors(stack)[source]¶
Find all magnetism objects in the stack and set their anchors.
This sets the total thickness, which is required to expected magnetism at the end of the profile. This function needs to be called for samples that have FunctionalMagnetism layers after the sample is built, and whenever the sample structure is changed.