sasdata.quantities.quantity module

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

Bases: BinaryOperation

__doc__ = None
__firstlineno__ = 506
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ()
_clean_ab(a, b)
_derivative(hash_value: int) Operation

Get the derivative of this operation

static _deserialise(parameters: dict) Operation
_self_cls() type

Own class

_summary_open()

First line of summary

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

Evaluate this operation

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

Bases: ConstantBase

__annotations__ = {}
__doc__ = None
__eq__(other)

Return self==value.

__firstlineno__ = 236
__hash__ = None
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ()
_derivative(hash_value: int) Operation

Get the derivative of this operation

static _deserialise(parameters: dict) Operation
_serialise_parameters() dict[str, Any]
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

__annotations__ = {}
__doc__ = None
__eq__(other)

Return self==value.

__firstlineno__ = 476
__hash__ = None
__init__(a: Operation, b: Operation)
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ('a', 'b')
_clean()

Clean up this operation - i.e. remove silly things like 1*x

_clean_ab(a, b)
static _deserialise_ab(parameters) tuple[Operation, Operation]
_self_cls() type

Own class

_serialise_parameters() dict[str, Any]
_summary_components() list[Operation]
class sasdata.quantities.quantity.Constant(value)

Bases: ConstantBase

__annotations__ = {}
__doc__ = None
__eq__(other)

Return self==value.

__firstlineno__ = 298
__hash__ = None
__init__(value)
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ('value',)
_clean()

Clean up this operation - i.e. remove silly things like 1*x

_derivative(hash_value: int)

Get the derivative of this operation

static _deserialise(parameters: dict) Operation
_serialise_parameters() dict[str, Any]
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

__annotations__ = {}
__doc__ = None
__firstlineno__ = 233
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ()
class sasdata.quantities.quantity.DerivedQuantity(value: QuantityType, units: Unit, history: QuantityHistory)

Bases: Quantity, Generic

__annotations__ = {}
__doc__ = None
__firstlineno__ = 1446
__init__(value: QuantityType, units: Unit, history: QuantityHistory)
__module__ = 'sasdata.quantities.quantity'
__orig_bases__ = (sasdata.quantities.quantity.Quantity[QuantityType], typing.Generic[QuantityType])
__parameters__ = (QuantityType,)
__static_attributes__ = ('_has_variance', '_variance_cache', 'history')
__type_params__ = (QuantityType,)
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

__annotations__ = {}
__doc__ = None
__firstlineno__ = 679
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ()
_clean_ab(a, b)
_derivative(hash_value: int) Operation

Get the derivative of this operation

static _deserialise(parameters: dict) Operation
_self_cls() type

Own class

_summary_open()

First line of summary

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

__annotations__ = {}
__doc__ = "Dot product - backed by numpy's dot method"
__firstlineno__ = 854
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ()
_clean_ab(a, b)
_derivative(hash_value: int) Operation

Get the derivative of this operation

static _deserialise(parameters: dict) Operation
_summary_open()

First line of summary

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

Evaluate this operation

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

Bases: UnaryOperation

__annotations__ = {}
__doc__ = None
__eq__(other)

Return self==value.

__firstlineno__ = 435
__hash__ = None
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ()
_clean()

Clean up this operation - i.e. remove silly things like 1*x

_derivative(hash_value: int) Operation

Get the derivative of this operation

static _deserialise(parameters: dict) Operation
_summary_open()

First line of summary

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

__annotations__ = {}
__doc__ = 'Matrix multiplication, using __matmul__ dunder'
__firstlineno__ = 882
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ()
_clean_ab(a, b)
_derivative(hash_value: int) Operation

Get the derivative of this operation

static _deserialise(parameters: dict) Operation
_summary_open()

First line of summary

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

Evaluate this operation

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

Bases: BinaryOperation

__annotations__ = {}
__doc__ = None
__firstlineno__ = 609
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ()
_clean_ab(a, b)
_derivative(hash_value: int) Operation

Get the derivative of this operation

static _deserialise(parameters: dict) Operation
_self_cls() type

Own class

_summary_open()

First line of summary

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

Evaluate this operation

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

Bases: ConstantBase

__annotations__ = {}
__doc__ = None
__eq__(other)

Return self==value.

__firstlineno__ = 266
__hash__ = None
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ()
_derivative(hash_value: int)

Get the derivative of this operation

static _deserialise(parameters: dict) Operation
_serialise_parameters() dict[str, Any]
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

__annotations__ = {}
__doc__ = None
__firstlineno__ = 1409
__init__(name: str, value: QuantityType, units: Unit, standard_error: QuantityType | None = None)
__module__ = 'sasdata.quantities.quantity'
__orig_bases__ = (sasdata.quantities.quantity.Quantity[QuantityType], typing.Generic[QuantityType])
__parameters__ = (QuantityType,)
__repr__()

Return repr(self).

__static_attributes__ = ('name',)
__type_params__ = (QuantityType,)
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

__annotations__ = {}
__doc__ = None
__eq__(other)

Return self==value.

__firstlineno__ = 399
__hash__ = None
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ()
_clean()

Clean up this operation - i.e. remove silly things like 1*x

_derivative(hash_value: int)

Get the derivative of this operation

static _deserialise(parameters: dict) Operation
_summary_open()

First line of summary

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

Evaluate this operation

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

Bases: object

__annotations__ = {}
__dict__ = mappingproxy({'__module__': 'sasdata.quantities.quantity', '__firstlineno__': 130, 'serialisation_name': 'unknown', 'summary': <function Operation.summary>, '_summary_open': <function Operation._summary_open>, '_summary_components': <function Operation._summary_components>, 'evaluate': <function Operation.evaluate>, '_derivative': <function Operation._derivative>, '_clean': <function Operation._clean>, 'derivative': <function Operation.derivative>, 'deserialise': <staticmethod(<function Operation.deserialise>)>, 'deserialise_json': <staticmethod(<function Operation.deserialise_json>)>, '_deserialise': <staticmethod(<function Operation._deserialise>)>, 'serialise': <function Operation.serialise>, '_serialise_json': <function Operation._serialise_json>, '_serialise_parameters': <function Operation._serialise_parameters>, '__eq__': <function Operation.__eq__>, '__static_attributes__': (), '__dict__': <attribute '__dict__' of 'Operation' objects>, '__weakref__': <attribute '__weakref__' of 'Operation' objects>, '__doc__': None, '__hash__': None, '__annotations__': {}})
__doc__ = None
__eq__(other: Operation)

Return self==value.

__firstlineno__ = 130
__hash__ = None
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ()
__weakref__

list of weak references to the object

_clean()

Clean up this operation - i.e. remove silly things like 1*x

_derivative(hash_value: int) Operation

Get the derivative of this operation

static _deserialise(parameters: dict) Operation
_serialise_json() dict[str, Any]
_serialise_parameters() dict[str, Any]
_summary_components() list[Operation]
_summary_open()

First line of summary

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

__annotations__ = {}
__doc__ = None
__eq__(other)

Return self==value.

__firstlineno__ = 744
__hash__ = None
__init__(a: Operation, power: float)
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ('a', 'power')
_clean() Operation

Clean up this operation - i.e. remove silly things like 1*x

_derivative(hash_value: int) Operation

Get the derivative of this operation

static _deserialise(parameters: dict) Operation
_serialise_parameters() dict[str, Any]
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

__add__(other: Self | ArrayLike) Self
__annotations__ = {}
__dict__ = mappingproxy({'__module__': 'sasdata.quantities.quantity', '__firstlineno__': 1084, '__type_params__': (QuantityType,), '__init__': <function Quantity.__init__>, 'with_standard_error': <function Quantity.with_standard_error>, 'has_variance': <property object>, 'variance': <property object>, 'standard_deviation': <function Quantity.standard_deviation>, 'in_units_of': <function Quantity.in_units_of>, 'to_units_of': <function Quantity.to_units_of>, 'variance_in_units_of': <function Quantity.variance_in_units_of>, 'in_si': <function Quantity.in_si>, 'in_units_of_with_standard_error': <function Quantity.in_units_of_with_standard_error>, 'in_si_with_standard_error': <function Quantity.in_si_with_standard_error>, 'explicitly_formatted': <function Quantity.explicitly_formatted>, '__eq__': <function Quantity.__eq__>, '__mul__': <function Quantity.__mul__>, '__rmul__': <function Quantity.__rmul__>, '__matmul__': <function Quantity.__matmul__>, '__rmatmul__': <function Quantity.__rmatmul__>, '__truediv__': <function Quantity.__truediv__>, '__rtruediv__': <function Quantity.__rtruediv__>, '__add__': <function Quantity.__add__>, '__neg__': <function Quantity.__neg__>, '__sub__': <function Quantity.__sub__>, '__rsub__': <function Quantity.__rsub__>, '__pow__': <function Quantity.__pow__>, '_array_repr_format': <staticmethod(<function Quantity._array_repr_format>)>, '__repr__': <function Quantity.__repr__>, 'parse': <staticmethod(<function Quantity.parse>)>, 'string_repr': <property object>, 'as_h5': <function Quantity.as_h5>, '__static_attributes__': ('_hash_seed', '_variance', 'hash_value', 'history', 'units', 'value'), '__orig_bases__': (typing.Generic[QuantityType],), '__dict__': <attribute '__dict__' of 'Quantity' objects>, '__weakref__': <attribute '__weakref__' of 'Quantity' objects>, '__doc__': None, '__hash__': None, '__parameters__': (QuantityType,), '__annotations__': {}})
__doc__ = None
__eq__(other: Self) bool | ndarray

Return self==value.

__firstlineno__ = 1084
__hash__ = None
__init__(value: QuantityType, units: Unit, standard_error: QuantityType | None = None, hash_seed='')
__matmul__(other: ArrayLike | Self)
__module__ = 'sasdata.quantities.quantity'
__mul__(other: ArrayLike | Self) Self
__neg__()
__orig_bases__ = (typing.Generic[QuantityType],)
__parameters__ = (QuantityType,)
__pow__(other: int | float)
__repr__()

Return repr(self).

__rmatmul__(other: ArrayLike | Self)
__rmul__(other: ArrayLike | Self)
__rsub__(other: Self | ArrayLike) Self
__rtruediv__(other: float | Self) Self
__static_attributes__ = ('_hash_seed', '_variance', 'hash_value', 'history', 'units', 'value')
__sub__(other: Self | ArrayLike) Self
__truediv__(other: float | Self) Self
__type_params__ = (QuantityType,)
__weakref__

list of weak references to the object

static _array_repr_format(arr: ndarray)

Format the array

_hash_seed

Retain this for copying operations

_variance

Contains the variance if it is data driven

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

__dict__ = mappingproxy({'__module__': 'sasdata.quantities.quantity', '__firstlineno__': 994, '__doc__': 'Class that holds the information for keeping track of operations done on quantities ', '__init__': <function QuantityHistory.__init__>, 'jacobian': <function QuantityHistory.jacobian>, '_recalculate': <function QuantityHistory._recalculate>, 'variance_propagate': <function QuantityHistory.variance_propagate>, 'variable': <staticmethod(<function QuantityHistory.variable>)>, 'apply_operation': <staticmethod(<function QuantityHistory.apply_operation>)>, 'has_variance': <function QuantityHistory.has_variance>, 'summary': <function QuantityHistory.summary>, '__static_attributes__': ('operation_tree', 'reference_key_list', 'references', 'si_reference_values'), '__dict__': <attribute '__dict__' of 'QuantityHistory' objects>, '__weakref__': <attribute '__weakref__' of 'QuantityHistory' objects>, '__annotations__': {}})
__doc__ = 'Class that holds the information for keeping track of operations done on quantities '
__firstlineno__ = 994
__init__(operation_tree: Operation, references: dict[int, Quantity])
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ('operation_tree', 'reference_key_list', 'references', 'si_reference_values')
__weakref__

list of weak references to the object

_recalculate()

Recalculate the value of this object - primary use case is for testing

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

__annotations__ = {}
__doc__ = None
__firstlineno__ = 557
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ()
_clean_ab(a, b)
_derivative(hash_value: int) Operation

Get the derivative of this operation

static _deserialise(parameters: dict) Operation
_self_cls() type

Own class

_summary_open()

First line of summary

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

__annotations__ = {}
__doc__ = None
__firstlineno__ = 923
__init__(a: Operation, b: Operation, a_index: int, b_index: int)
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ('a', 'a_index', 'b', 'b_index')
static _deserialise(parameters: dict) Operation
_serialise_parameters() dict[str, Any]
_summary_open()

First line of summary

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

__annotations__ = {}
__doc__ = 'Transpose operation - as per numpy'
__eq__(other)

Return self==value.

__firstlineno__ = 805
__hash__ = None
__init__(a: Operation, axes: tuple[int] | None = None)
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ('a', 'axes')
_clean()

Clean up this operation - i.e. remove silly things like 1*x

_derivative(hash_value: int) Operation

Get the derivative of this operation

static _deserialise(parameters: dict) Operation
_serialise_parameters() dict[str, Any]
_summary_open()

First line of summary

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

Evaluate this operation

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

Bases: Operation

__annotations__ = {}
__doc__ = None
__firstlineno__ = 385
__init__(a: Operation)
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ('a',)
_serialise_parameters() dict[str, Any]
_summary_components() list[Operation]
exception sasdata.quantities.quantity.UnitError

Bases: Exception

Errors caused by unit specification not being correct

__doc__ = 'Errors caused by unit specification not being correct '
__firstlineno__ = 963
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ()
__weakref__

list of weak references to the object

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

Bases: Operation

__annotations__ = {}
__doc__ = None
__eq__(other)

Return self==value.

__firstlineno__ = 347
__hash__ = None
__init__(name_or_hash_value: int | str | tuple[int, str])
__module__ = 'sasdata.quantities.quantity'
__static_attributes__ = ('hash_value', 'name')
_derivative(hash_value: int) Operation

Get the derivative of this operation

static _deserialise(parameters: dict) Operation
_serialise_parameters() dict[str, Any]
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