Skip to content

limits

SLD_LIMITS = (-1.0, 10.0) module-attribute

SCALE_LIMITS = (0.0, 10.0) module-attribute

apply_default_limits(parameter, kind)

Apply default min/max to a parameter if current bounds are infinite.

Parameters:

Name Type Description Default
parameter Parameter

The parameter to adjust.

required
kind str

One of 'thickness', 'roughness', 'sld', 'isld', 'rho_m', 'scale'.

required
Source code in src/easyreflectometry/limits.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def apply_default_limits(parameter: Parameter, kind: str) -> None:
    """Apply default min/max to a parameter if current bounds are infinite.

    Parameters
    ----------
    parameter : Parameter
        The parameter to adjust.
    kind : str
        One of 'thickness', 'roughness', 'sld', 'isld', 'rho_m', 'scale'.
    """
    if not parameter.independent:
        return

    if kind in ('thickness', 'roughness'):
        _apply_percentage_limits(parameter)
    elif kind in ('sld', 'isld', 'rho_m'):
        # A magnetic SLD is an SLD: same physical scale, same default window.
        _apply_fixed_limits(parameter, *SLD_LIMITS)
    elif kind == 'scale':
        _apply_fixed_limits(parameter, *SCALE_LIMITS)

_apply_percentage_limits(parameter)

Set min to 50% and max to 200% of the current value, only if current bounds are inf.

Source code in src/easyreflectometry/limits.py
34
35
36
37
38
39
40
41
42
def _apply_percentage_limits(parameter: Parameter) -> None:
    """Set min to 50% and max to 200% of the current value, only if current bounds are inf."""
    value = parameter.value
    if value == 0.0:
        return
    if np.isinf(parameter.min):
        parameter.min = 0.5 * value
    if np.isinf(parameter.max):
        parameter.max = 2.0 * value

_apply_fixed_limits(parameter, low, high)

Set fixed min/max, only if current bounds are inf.

Source code in src/easyreflectometry/limits.py
45
46
47
48
49
50
def _apply_fixed_limits(parameter: Parameter, low: float, high: float) -> None:
    """Set fixed min/max, only if current bounds are inf."""
    if np.isinf(parameter.min) and low <= parameter.value:
        parameter.min = low
    if np.isinf(parameter.max) and high >= parameter.value:
        parameter.max = high