sunpeek.common.unit_uncertainty.check_quantity#

sunpeek.common.unit_uncertainty.check_quantity(q, unit='', min_limit=-inf, max_limit=inf, none_allowed=False, max_ndim=0)#

Check that q is a valid pint Quantity object.

Parameters:
  • q (pint Quantity or pd.Series) – Quantity object to check.

  • unit (str, optional) – q must be compatible with unit. Use default unit='' for dimensionless quantity.

  • min_limit (float, optional) – q must be >= min_limit, where min_limit is interpreted as Quantity in unit, so Q(min_limit, 'unit')

  • max_limit (float, optional) – q must be <= max_limit, where max_limit is interpreted as Quantity in unit, so Q(max_limit, 'unit')

  • none_allowed (bool, optional) – If False: Will raise ValueError if q is None.

  • max_ndim (int, optional, default 0) – Maximum allowed numpy ndim of q. Set max_ndim==0 to enforce q as scalar, max_ndim==1 for vector, etc.

Returns:

Input q converted to unit, if q passes all tests / conditions.

Return type:

pint Quantity

Raises:
  • TypeError – If q is not a scalar pint Quantity or None and none_allowed==False, or if q is not compatible with unit.

  • ValueError – If q is outside min_limit | max_limit.