unyt.unit_registry module

A registry for units that can be added to and modified.

unyt.unit_registry.cached_sympify(u)[source]

Successive loads of unit systems produce the same calls to sympify in UnitRegistry.from_json. Even within a single load, this is a net improvement because there will often be a few cache hits

class unyt.unit_registry.UnitRegistry(add_default_symbols=True, lut=None, unit_system=None)[source]

Bases: object

A registry for unit symbols

property unit_system_id

This is a unique identifier for the unit registry created from a FNV hash. It is needed to register a dataset’s code unit system in the unit system registry.

property prefixable_units
add(symbol, base_value, dimensions, tex_repr=None, offset=None, prefixable=False)[source]

Add a symbol to this registry.

Parameters:
  • symbol (str) – The name of the unit

  • base_value (float) – The scaling from the units value to the equivalent SI unit with the same dimensions

  • dimensions (expr) – The dimensions of the unit

  • tex_repr (str, optional) – The LaTeX representation of the unit. If not provided a LaTeX representation is automatically generated from the name of the unit.

  • offset (float, optional) – If set, the zero-point offset to apply to the unit to convert to SI. This is mostly used for units like Farhenheit and Celcius that are not defined on an absolute scale.

  • prefixable (bool) – If True, then SI-prefix versions of the unit will be created along with the unit itself.

remove(symbol)[source]

Remove the entry for the unit matching symbol.

Parameters:

symbol (str) – The name of the unit symbol to remove from the registry.

modify(symbol, base_value)[source]

Change the base value of a unit symbol. Useful for adjusting code units after parsing parameters.

Parameters:
  • symbol (str) – The name of the symbol to modify

  • base_value (float) – The new base_value for the symbol.

keys()[source]

Print out the units contained in the lookup table.

to_json()[source]

Returns a json-serialized version of the unit registry

classmethod from_json(json_text)[source]

Returns a UnitRegistry object from a json-serialized unit registry

Parameters:

json_text (str) – A string containing a json represention of a UnitRegistry

list_same_dimensions(unit_object)[source]

Return a list of base unit names that this registry knows about that are of equivalent dimensions to unit_object.

unyt.unit_registry.default_unit_registry = <unyt.unit_registry._NonModifiableUnitRegistry object>

The default unit registry