assert_quantity

Contents

assert_quantity#

class brainunit.math.assert_quantity(q, mantissa, unit=None)#

Assert that a Quantity has a certain mantissa and unit.

When unit is None the function checks that q is unitless and that its numeric value matches mantissa. When unit is given the function additionally checks that the dimensions agree and that the value expressed in unit matches mantissa.

Parameters:
  • q (saiunit.Quantity | Array | ndarray | bool | number | bool | int | float | complex) – The quantity to check.

  • mantissa (Array | ndarray | bool | number | bool | int | float | complex) – The expected numeric value.

  • unit (saiunit.Unit) – The expected unit.

Raises:

AssertionError – If the value or the unit does not match.

Examples

>>> import saiunit as u
>>> u.assert_quantity(u.Quantity(1, u.mV), 1, u.mV)