Unit#

class ansys.units.unit.Unit(units: str | None = None, config: dict | None = None, dimensions: Dimensions | None = None, system: UnitSystem | str | None = None, table: dict | None = None, copy_from: Unit | None = None)#

Bases: object

A class containing the string name and dimensions of a unit.

Parameters:
units: str, optional

Name of the unit or string chain of combined units

config: dict, optional

dictionary of unit properties

dimensions: Dimensions, optional

An instance of the Dimensions class.

system: str, optional

Define the unit system for base units of dimension, default is SI.

table: dict, optional

A dictionary of api table keys from the cfg.yaml and exponent values.

copy_from: Unit, optional

A previous instance of Unit.

Examples

>>> from ansys.units import Unit, Quantity
>>> fps = Unit("ft s^-1")
>>> fps.name
'ft s^-1'
>>> fps.dimensions
{'LENGTH': 1.0, 'TIME': -1.0}
>>> speed = Quantity(value=5, units=fps)
>>> speed
Quantity (5.0, "ft s^-1")
Attributes:
name

The unit string.

si_units

The unit string in SI units.

si_scaling_factor

The scaling factor used to convert to SI units.

si_offset

The offset used to convert to SI units.

dimensions

Then units base dimensions.

compatible_units() set[str]#

Get all units with the same dimensions.

Returns:
set

A set of unit objects.

convert(system: UnitSystem) Unit#

Convert a unit into the unit system.

Parameters:
systemUnitSystem

Unit system to convert to.

Returns:
Unit

Unit object converted into the unit system.

Examples

>>> ur = UnitRegistry()
>>> speed_si = Unit(units= ur.m / ur.s)
>>> bt = UnitSystem(system="BT")
>>> speed_bt = speed_si.convert(bt)
property dimensions: Dimensions#

Then units base dimensions.

property name: str#

The unit string.

property si_offset: float#

The offset used to convert to SI units.

property si_scaling_factor: float#

The scaling factor used to convert to SI units.

property si_units: str#

The unit string in SI units.

exception ansys.units.unit.ProhibitedTemperatureOperation#

Bases: TypeError

Raised when two absolute temperatures are added.

exception ansys.units.unit.IncorrectUnits(unit1, unit2)#

Bases: ValueError

Raised when the specified units are incorrect.

exception ansys.units.unit.InconsistentDimensions#

Bases: ValueError

Raised when units have inconsistent base dimensions.

exception ansys.units.unit.UnconfiguredUnit(unit)#

Bases: ValueError

Raised when the specified unit is unconfigured.

exception ansys.units.unit.UnknownTableItem(item)#

Bases: ValueError

Raised when a quantity table item is undefined.