parse_quantity

specsim.config.parse_quantity(quantity, dimensions=None)[source] [edit on github]

Parse a string containing a numeric value with optional units.

The result is a Quantity <astropy.units.Quantity object even when units are not present. Optional units are interpreted by astropy.units.Unit. Some valid examples:

1.23
1.23um
123 um / arcsec
1 electron/adu

Used by Configuration.get_constants().

Parameters:
quantitystr or astropy.units.Quantity

String to parse. If a quantity is provided, it is checked against the expected dimensions and passed through.

dimensionsstr or astropy.units.Unit or None

The units of the input quantity are expected to have the same dimensions as these units, if not None. Raises a ValueError if the input quantity is not convertible to dimensions.

Returns:
astropy.units.Quantity

If dimensions is not None, the returned quantity will be converted to its units.

Raises:
ValueError

Unable to parse quantity.