Unit registry#

class ansys.units.unit_registry.UnitRegistry(config='cfg.yaml', other: dict | None = None)#

Bases: object

A representation of valid Unit instances.

All base and derived units loaded from the configuration file, cfg.yaml, on package initialization are provided by default.

Parameters:
config: str, optional

Path of a YAML configuration file, which can be a custom file, and defaults to the provided file, cfg.yaml. Custom configuration files must match the format of the default configuration file.

other: dict, optional

Dictionary for additional units.

Examples

>>> from ansys.units import UnitRegistry, Unit
>>> ureg = UnitRegistry()
>>> assert ureg.kg == Unit(units="kg")
>>> fps = Unit("ft s^-1")
>>> ureg.foot_per_sec = fps
exception ansys.units.unit_registry.UnitAlreadyRegistered(name: str)#

Bases: ValueError

Raised when a unit has previously been registered.