sasdata.quantities.quantity module

class sasdata.quantities.quantity.Add(a: Operation, b: Operation)

Bases: BinaryOperation

evaluate(variables: dict[int, T]) T

Evaluate this operation

serialisation_name = 'add'
class sasdata.quantities.quantity.AdditiveIdentity

Bases: ConstantBase

evaluate(variables: dict[int, T]) T

Evaluate this operation

serialisation_name = 'zero'
summary(indent_amount: int = 0, indent='  ')

Summary of the operation tree

class sasdata.quantities.quantity.BinaryOperation(a: Operation, b: Operation)

Bases: Operation

class sasdata.quantities.quantity.Constant(value)

Bases: ConstantBase

evaluate(variables: dict[int, T]) T

Evaluate this operation

serialisation_name = 'constant'
summary(indent_amount: int = 0, indent='  ')

Summary of the operation tree

class sasdata.quantities.quantity.ConstantBase

Bases: Operation

class sasdata.quantities.quantity.DerivedQuantity(value: QuantityType, units: Unit, history: QuantityHistory)

Bases: Quantity, Generic

property has_variance
to_units_of(new_units: Unit) Quantity[QuantityType]
property variance: Quantity

Get the variance of this object

class sasdata.quantities.quantity.Div(a: Operation, b: Operation)

Bases: BinaryOperation

evaluate(variables: dict[int, T]) T

Evaluate this operation

serialisation_name = 'div'
class sasdata.quantities.quantity.Dot(a: Operation, b: Operation)

Bases: BinaryOperation

Dot product - backed by numpy’s dot method

evaluate(variables: dict[int, T]) T

Evaluate this operation

serialisation_name = 'dot'
class sasdata.quantities.quantity.Inv(a: Operation)

Bases: UnaryOperation

evaluate(variables: dict[int, T]) T

Evaluate this operation

serialisation_name = 'reciprocal'
class sasdata.quantities.quantity.MatMul(a: Operation, b: Operation)

Bases: BinaryOperation

Matrix multiplication, using __matmul__ dunder

evaluate(variables: dict[int, T]) T

Evaluate this operation

serialisation_name = 'matmul'
class sasdata.quantities.quantity.Mul(a: Operation, b: Operation)

Bases: BinaryOperation

evaluate(variables: dict[int, T]) T

Evaluate this operation

serialisation_name = 'mul'
class sasdata.quantities.quantity.MultiplicativeIdentity

Bases: ConstantBase

evaluate(variables: dict[int, T]) T

Evaluate this operation

serialisation_name = 'one'
summary(indent_amount: int = 0, indent='  ')

Summary of the operation tree

class sasdata.quantities.quantity.NamedQuantity(name: str, value: QuantityType, units: Unit, standard_error: QuantityType | None = None)

Bases: Quantity, Generic

property string_repr
to_units_of(new_units: Unit) NamedQuantity[QuantityType]
with_standard_error(standard_error: Quantity)
class sasdata.quantities.quantity.Neg(a: Operation)

Bases: UnaryOperation

evaluate(variables: dict[int, T]) T

Evaluate this operation

serialisation_name = 'neg'
class sasdata.quantities.quantity.Operation

Bases: object

derivative(variable: str | int | Variable, simplify=True)
static deserialise(data: str) Operation
static deserialise_json(json_data: dict) Operation
evaluate(variables: dict[int, T]) T

Evaluate this operation

serialisation_name = 'unknown'
serialise() str
summary(indent_amount: int = 0, indent: str = '  ')

Summary of the operation tree

class sasdata.quantities.quantity.Pow(a: Operation, power: float)

Bases: Operation

evaluate(variables: dict[int, T]) T

Evaluate this operation

serialisation_name = 'pow'
summary(indent_amount: int = 0, indent='  ')

Summary of the operation tree

class sasdata.quantities.quantity.Quantity(value: QuantityType, units: Unit, standard_error: QuantityType | None = None, hash_seed='')

Bases: Generic

as_h5(group: Group, name: str)

Add this data onto a group as a dataset under the given name

explicitly_formatted(unit_string: str) str

Returns quantity as a string with specific unit formatting

Performs any necessary unit conversions, but maintains the exact unit formatting provided by the user. This can be useful if you have a power expressed in horsepower and you want it expressed as “745.7 N m/s” and not as “745.7 W”.

property has_variance
hash_value

Hash based on value and uncertainty for data, -1 if it is a derived hash value

in_si()
in_si_with_standard_error()
in_units_of(units: Unit) QuantityType

Get this quantity in other units

in_units_of_with_standard_error(units)
static parse(number_or_string: str | ArrayLike, unit: str, absolute_temperature: False)
standard_deviation() Quantity
property string_repr
to_units_of(new_units: Unit) Quantity[QuantityType]
units

Units of this data

value

Numerical value of this data, in the specified units

property variance: Quantity

Get the variance of this object

variance_in_units_of(units: Unit) QuantityType

Get the variance of quantity in other units

with_standard_error(standard_error: Quantity)
class sasdata.quantities.quantity.QuantityHistory(operation_tree: Operation, references: dict[int, Quantity])

Bases: object

Class that holds the information for keeping track of operations done on quantities

static apply_operation(operation: type[Operation], *histories: QuantityHistory, **extra_parameters) QuantityHistory

Apply an operation to the history

This is slightly unsafe as it is possible to attempt to apply an n-ary operation to a number of trees other than n, but it is relatively concise. Because it is concise we’ll go with this for now and see if it causes any problems down the line. It is a private static method to discourage misuse.

has_variance()
jacobian() list[Operation]

Derivative of this quantity’s operation history with respect to each of the references

summary()
static variable(quantity: Quantity)

Create a history that starts with the provided data

variance_propagate(quantity_units: Unit, covariances: dict[slice(tuple[int, int], 'Quantity', None)] = {})

Do standard error propagation to calculate the uncertainties associated with this quantity

Parameters:
  • quantity_units – units in which the output should be calculated

  • covariances – off diagonal entries for the covariance matrix

class sasdata.quantities.quantity.Sub(a: Operation, b: Operation)

Bases: BinaryOperation

evaluate(variables: dict[int, T]) T

Evaluate this operation

serialisation_name = 'sub'
class sasdata.quantities.quantity.TensorDot(a: Operation, b: Operation, a_index: int, b_index: int)

Bases: Operation

evaluate(variables: dict[int, T]) T

Evaluate this operation

serialisation_name = 'tensor_product'
class sasdata.quantities.quantity.Transpose(a: Operation, axes: tuple[int] | None = None)

Bases: Operation

Transpose operation - as per numpy

evaluate(variables: dict[int, T]) T

Evaluate this operation

serialisation_name = 'transpose'
class sasdata.quantities.quantity.UnaryOperation(a: Operation)

Bases: Operation

exception sasdata.quantities.quantity.UnitError

Bases: Exception

Errors caused by unit specification not being correct

class sasdata.quantities.quantity.Variable(name_or_hash_value: int | str | tuple[int, str])

Bases: Operation

evaluate(variables: dict[int, T]) T

Evaluate this operation

serialisation_name = 'variable'
summary(indent_amount: int = 0, indent: str = '  ')

Summary of the operation tree

sasdata.quantities.quantity.dot(a: Quantity[ArrayLike] | ArrayLike, b: Quantity[ArrayLike] | ArrayLike)

Dot product of two arrays or two array based quantities

sasdata.quantities.quantity.hash_and_name(hash_or_name: int | str)

Infer the name of a variable from a hash, or the hash from the name

Note: hash_and_name(hash_and_name(number)[1]) is not the identity

however: hash_and_name(hash_and_name(number)) is

sasdata.quantities.quantity.hash_data_via_numpy(*data: ArrayLike)
sasdata.quantities.quantity.tensordot(a: Quantity[ArrayLike] | ArrayLike, b: Quantity[ArrayLike] | ArrayLike, a_index: int, b_index: int)

Tensor dot product - equivalent to contracting two tensors, such as

A_{i0, i1, i2, i3…} and B_{j0, j1, j2…}

e.g. if a_index is 1 and b_index is zero, it will be the sum

C_{i0, i2, i3 …, j1, j2 …} = sum_k A_{i0, k, i2, i3 …} B_{k, j1, j2 …}

(I think, have to check what happens with indices TODO!)

sasdata.quantities.quantity.transpose(a: Quantity[ArrayLike] | ArrayLike, axes: tuple | None = None)

Transpose an array or an array based quantity, can also do reordering of axes