NamedUnit#

class astropy.units.NamedUnit(st: str | list[str] | tuple[list[str], list[str]], doc: str | None = None, format: Mapping[str, str] | None = None, namespace: MutableMapping[str, object] | None = None)[source]#

Bases: UnitBase

The base class of units that have a name.

Parameters:
ststr, list of str, 2-tuple

The name of the unit. If a list of strings, the first element is the canonical (short) name, and the rest of the elements are aliases. If a tuple of lists, the first element is a list of short names, and the second element is a list of long names; all but the first short name are considered “aliases”. Each name should be a valid Python identifier to make it easy to access, but this is not required.

namespacedict, optional

When provided, inject the unit, and all of its aliases, in the given namespace dictionary. If a unit by the same name is already in the namespace, a ValueError is raised.

docstr, optional

A docstring describing the unit.

formatdict, optional

A mapping to format-specific representations of this unit. For example, for the Ohm unit, it might be nice to have it displayed as \Omega by the latex formatter. In that case, format argument should be set to:

{'latex': r'\Omega'}
Raises:
ValueError

If any of the given unit names are already in the registry.

ValueError

If any of the given unit names are not valid Python tokens.

Attributes Summary

aliases

The aliases (long) names for the unit.

long_names

All the long names associated with the unit.

name

The canonical (short) name associated with the unit.

names

All the names associated with the unit.

short_names

All the short names associated with the unit.

Methods Summary

get_format_name(format)

Attributes Documentation

aliases#

The aliases (long) names for the unit.

long_names#

All the long names associated with the unit.

name#

The canonical (short) name associated with the unit.

names#

All the names associated with the unit.

short_names#

All the short names associated with the unit.

Methods Documentation

get_format_name(format)[source]#

Deprecated since version 7.0: The get_format_name function is deprecated and may be removed in a future version. Use to_string() instead.

Get a name for this unit that is specific to a particular format.

Uses the dictionary passed into the format kwarg in the constructor.

Parameters:
formatstr

The name of the format

Returns:
namestr

The name of the unit for the given format.