def_unit¶
- astropy.units.def_unit(s, represents=None, doc=None, format=None, prefixes=False, exclude_prefixes=[], namespace=None)[source]¶
Factory function for defining new units.
- Parameters:
- s
strorlistofstr The name of the unit. If a list, the first element is the canonical (short) name, and the rest of the elements are aliases.
- represents
UnitBaseinstance, optional The unit that this named unit represents. If not provided, a new
IrreducibleUnitis created.- doc
str, optional A docstring describing the unit.
- format
dict, optional A mapping to format-specific representations of this unit. For example, for the
Ohmunit, it might be nice to have it displayed as\Omegaby thelatexformatter. In that case,formatargument should be set to:{'latex': r'\Omega'}
- prefixesbool or
list, optional When
True, generate all of the SI prefixed versions of the unit as well. For example, for a given unitm, will generatemm,cm,km, etc. When a list, it is a list of prefix definitions of the form:(short_names, long_tables, factor)
Default is
False. This function always returns the base unit object, even if multiple scaled versions of the unit were created.- exclude_prefixes
listofstr, optional If any of the SI prefixes need to be excluded, they may be listed here. For example,
Pacan be interpreted either as “petaannum” or “Pascal”. Therefore, when defining the prefixes fora,exclude_prefixesshould be set to["P"].- namespace
dict, optional When provided, inject the unit (and all of its aliases and prefixes), into the given namespace dictionary.
- s
- Returns:
- unit
UnitBase The newly-defined unit, or a matching unit that was already defined.
- unit