UnrecognizedUnit#
- class astropy.units.UnrecognizedUnit(st, doc=None, format=None, namespace=None)[source]#
Bases:
IrreducibleUnit
A unit that did not parse correctly. This allows for round-tripping it as a string, but no unit operations actually work on it.
- Parameters:
- st
str
The name of the unit.
- st
Methods Summary
get_format_name
(format)Get a name for this unit that is specific to a particular format.
is_equivalent
(other[, equivalencies])Returns
True
if this unit is equivalent toother
.is_unity
()Returns
True
if the unit is unscaled and dimensionless.to_string
([format])Output the unit in the given format as a string.
Methods Documentation
- get_format_name(format)[source]#
Get a name for this unit that is specific to a particular format.
Uses the dictionary passed into the
format
kwarg in the constructor.
- is_equivalent(other, equivalencies=None)[source]#
Returns
True
if this unit is equivalent toother
.- Parameters:
- other
Unit
,str
, ortuple
The unit to convert to. If a tuple of units is specified, this method returns true if the unit matches any of those in the tuple.
- equivalencies
list
oftuple
A list of equivalence pairs to try if the units are not directly convertible. See Equivalencies. This list is in addition to possible global defaults set by, e.g.,
set_enabled_equivalencies
. UseNone
to turn off all equivalencies.
- other
- Returns:
- to_string(format=None)[source]#
Output the unit in the given format as a string.
- Parameters:
- format
astropy.units.format.Base
instance orstr
The name of a format or a formatter object. If not provided, defaults to the generic format.
- **kwargs
Further options forwarded to the formatter. Currently recognized is
fraction
, which can take the following values:
- format
- Raises:
TypeError
If
format
is of the wrong type.ValueError
If
format
orfraction
are not recognized.
Examples
>>> import astropy.units as u >>> kms = u.Unit('km / s') >>> kms.to_string() # Generic uses fraction='inline' by default 'km / s' >>> kms.to_string('latex') # Latex uses fraction='multiline' by default '$\\mathrm{\\frac{km}{s}}$' >>> print(kms.to_string('unicode', fraction=False)) km s⁻¹ >>> print(kms.to_string('unicode', fraction='inline')) km / s >>> print(kms.to_string('unicode', fraction='multiline')) km ── s