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
orpd.Series
) – Quantity object to check.unit (
str
, optional) –q
must be compatible withunit
. Use defaultunit=''
for dimensionless quantity.min_limit (
float
, optional) –q
must be >=min_limit
, wheremin_limit
is interpreted as Quantity inunit
, soQ(min_limit, 'unit')
max_limit (
float
, optional) –q
must be <=max_limit
, wheremax_limit
is interpreted as Quantity inunit
, soQ(max_limit, 'unit')
none_allowed (
bool
, optional) – If False: Will raise ValueError ifq
is None.max_ndim (
int
, optional, default0
) – Maximum allowed numpy ndim ofq
. Set max_ndim==0 to enforceq
as scalar, max_ndim==1 for vector, etc.
- Returns:
Input
q
converted tounit
, ifq
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 ifq
is not compatible withunit
.ValueError – If
q
is outsidemin_limit
|max_limit
.