Skip to content

Equation¤

Equation dataclass ¤

Equation(
    value: Evaluable,
    uncertainty: Evaluable,
    unit: str,
    degree_freedom: float = float("inf"),
    comment: str = "",
)

Represents the equation element in an equipment register.

Parameters:

Name Type Description Default
value Evaluable

The equation to evaluate to calculate the corrected value.

required
uncertainty Evaluable

The equation to evaluate to calculate the standard uncertainty.

required
unit str

The unit of the measured quantity.

required
degree_freedom float

The degrees of freedom.

float('inf')
comment str

A comment to associate with the equation.

''

comment class-attribute instance-attribute ¤

comment: str = ''

A comment associated with the equation.

degree_freedom class-attribute instance-attribute ¤

degree_freedom: float = float('inf')

The degrees of freedom.

uncertainty instance-attribute ¤

uncertainty: Evaluable

The equation to evaluate to calculate the standard uncertainty.

unit instance-attribute ¤

unit: str

The unit of the measured quantity.

value instance-attribute ¤

value: Evaluable

The equation to evaluate to calculate the corrected value.

from_xml classmethod ¤

from_xml(element: Element[str]) -> Equation

Convert an XML element into an Equation instance.

Parameters:

Name Type Description Default
element Element[str]

An equation XML element from an equipment register.

required

Returns:

Type Description
Equation

The Equation instance.

to_xml ¤

to_xml() -> Element[str]

Convert the Equation class into an XML element.

Returns:

Type Description
Element[str]

The Equation as an XML element.

Evaluable dataclass ¤

Evaluable(
    equation: str,
    variables: tuple[str, ...],
    ranges: dict[str, Range] = dict(),
)

Represents the <value> and <uncertainty> XML elements in an equation.

Parameters:

Name Type Description Default
equation str

The string representation of the equation to evaluate.

required
variables tuple[str, ...]

The names of the variables in the equation.

required
ranges dict[str, Range]

The numeric range for each variable that the equation is valid for. The keys are the variable names.

dict()

equation instance-attribute ¤

equation: str

The string representation of the equation to evaluate.

ranges class-attribute instance-attribute ¤

ranges: dict[str, Range] = field(default_factory=dict)

The numeric range for each variable that the equation is valid for. The keys are the variable names.

variables instance-attribute ¤

variables: tuple[str, ...]

The names of the variables in the equation.

__call__ ¤

__call__(
    *, check_range: bool = True, **data: ArrayLike
) -> NDArray[float64]

Evaluate the equation.

Parameters:

Name Type Description Default
data ArrayLike

A mapping of variable names to value(s) to evaluate the equation with.

{}
check_range bool

Whether to check that the data is within the allowed range(s).

True

Returns:

Type Description
NDArray[float64]

The equation evaluated.

Range ¤

Bases: NamedTuple

The numeric range for each variable that an equation is valid for.

Parameters:

Name Type Description
minimum float

Minimum value in range.

maximum float

Maximum value in range.

maximum instance-attribute ¤

maximum: float

Maximum value in range.

minimum instance-attribute ¤

minimum: float

Minimum value in range.

check_within_range ¤

check_within_range(value: float | ArrayLike) -> None

Check that the value(s) is(are) within the range.

Parameters:

Name Type Description Default
value float | ArrayLike

The value(s) to check.

required

Raises:

Type Description
ValueError

If value is not within the range.