def_unit

astropy.units.core.def_unit(s, represents=None, register=None, doc=None, format=None, prefixes=False, exclude_prefixes=[]) [edit on github][source]

Factory function for defining new units.

Parameters :

names : str or list of str

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 : UnitBase instance, optional

The unit that this named unit represents. If not provided, a new IrreducibleUnit is created.

register : boolean, optional

When True, also register the unit in the standard unit namespace. Default is False.

doc : str, optional

A docstring describing the unit.

format : dict, 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'}

prefixes : bool, optional

When True, generate all of the SI prefixed versions of the unit as well. For example, for a given unit m, will generate mm, cm, km, etc. Default is False. This function always returns the base unit object, even if multiple scaled versions of the unit were created.

exclude_prefixes : list of str, optional

If any of the SI prefixes need to be excluded, they may be listed here. For example, Pa can be interpreted either as “petaannum” or “Pascal”. Therefore, when defining the prefixes for a, exclude_prefixes should be set to ["P"].

Returns :

unit : UnitBase object

The newly-defined unit, or a matching unit that was already defined.

Page Contents