unxt.dims#

Working with dimensions.

The main features are:

  • unxt.dims.dimension: a function to construct a dimension object.

  • unxt.dims.dimension_of: a function to get the dimensions of an object.

unxt.dims.dimension(obj: Any, /)#

Construct the dimension.

Note

This function uses multiple dispatch. Dispatches made in other modules may not be included in the rendered docs. To see the full range of options, execute unxt.dims.dimension.methods in an interactive Python session.

unxt.dims.dimension(obj: PhysicalType, /) PhysicalType
Parameters:

obj (Any)

Return type:

Any

Construct dimension from a dimension object.

Examples

>>> import unxt as u
>>> import astropy.units as apyu
>>> length = apyu.get_physical_type("length")
>>> length
PhysicalType('length')
>>> u.dimension(length) is length
True
unxt.dims.dimension(obj: str, /) PhysicalType
Parameters:

obj (Any)

Return type:

Any

Construct dimension from a string.

The string can be: 1. A simple dimension name (e.g., “length”, “time”, “mass”) 2. A multi-word dimension name (e.g., “amount of substance”, “absement”) 3. A mathematical expression using , /, and * operators

Mathematical Expressions:

Expressions are evaluated using operator precedence (PEMDAS): - ** (exponentiation, highest precedence) - * and / (multiplication and division, equal precedence, left-to-right)

Parentheses are supported for grouping and for dimension names with spaces.

Operators Supported: - * : Multiplication (e.g., “length * time”) - / : Division (e.g., “length / time”) - ** : Exponentiation (e.g., “length**2”)

Unsupported Operators: - + and - are NOT supported as operators since dimensions are invariant

under addition and subtraction. They are treated as part of dimension names.

Rules for Dimension Names in Expressions: - Single-word names don’t need parentheses: “length * time” - Multi-word names MUST be parenthesized: “(amount of substance) * time” - Parenthesized single-word names are allowed: “(length) / (time)” - Whitespace is flexible: “length / time”, “length/time”, “length / time**2”

Examples

>>> from unxt.dims import dimension

Simple dimension names:

>>> dimension("length")
PhysicalType('length')
>>> dimension("time")
PhysicalType('time')
>>> dimension("mass")
PhysicalType('mass')

Multi-word dimension names:

>>> dimension("amount of substance")
PhysicalType('amount of substance')

Mathematical expressions with single-word names:

>>> dimension("length / time")
PhysicalType({'speed', 'velocity'})
>>> dimension("length**2")
PhysicalType('area')
>>> dimension("length * mass / time**2")
PhysicalType('force')

Parenthesized expressions:

>>> dimension("(length) / (time)")
PhysicalType({'speed', 'velocity'})

Expressions with multi-word dimension names:

>>> dimension("(amount of substance) / (time)")
PhysicalType('catalytic activity')

Mixed expressions (multi-word with parentheses, single-word without):

>>> dimension("length * (amount of substance)")
PhysicalType('unknown')
>>> dimension("(absement) / (time)")
PhysicalType('length')

See also

dimension_of

Get the dimension of an object

unxt.units

Unit specifications can also use dimension expressions

Parameters:

obj (Any)

Return type:

Any

unxt.dims.dimension_of(obj: Any, /)#

Return the dimension of the given units.

Note

This function uses multiple dispatch. Dispatches made in other modules may not be included in the rendered docs. To see the full range of options, execute unxt.dimension_of.methods in an interactive Python session.

unxt.dims.dimension_of(obj: Any, /) NoneType
Parameters:

obj (Any)

Return type:

Any

Most objects have no dimension.

Examples

>>> from unxt.dims import dimension_of
>>> print(dimension_of(1))
None
>>> print(dimension_of("length"))
None
unxt.dims.dimension_of(obj: PhysicalType, /) PhysicalType
Parameters:

obj (Any)

Return type:

Any

Return the dimension of the given units.

Examples

>>> from unxt.dims import dimension, dimension_of
>>> dimension_of(dimension("length"))
PhysicalType('length')
unxt.dims.dimension_of(obj: type, /) NoReturn
Parameters:

obj (Any)

Return type:

Any

Get the dimension of a type.

Examples

>>> import unxt as u
>>> try:
...     u.dimension_of(u.quantity.BareQuantity)
... except ValueError as e:
...     print(e)
Cannot get the dimension of <class 'unxt._src.quantity.unchecked.BareQuantity'>.
unxt.dims.dimension_of(obj: Unit | UnitBase | CompositeUnit, /) PhysicalType
Parameters:

obj (Any)

Return type:

Any

Return the dimensions of the given units.

Examples

>>> import unxt as u
>>> u.dimension_of(u.unit("km"))
PhysicalType('length')
unxt.dims.dimension_of(obj: AbstractQuantity, /) PhysicalType
Parameters:

obj (Any)

Return type:

Any

Return the dimension of a quantity.

Examples

>>> import unxt as u
>>> q = u.Q(1, "m")
>>> u.dimension_of(q)
PhysicalType('length')
unxt.dims.dimension_of(obj: type[AbstractParametricQuantity], /) PhysicalType
Parameters:

obj (Any)

Return type:

Any

Return the dimension of a quantity.

Examples

>>> import unxt as u
>>> try:
...     u.dimension_of(u.Quantity)
... except Exception as e:
...     print(e)
can only get dimensions from parametrized Quantity -- Quantity[dim].
>>> u.dimension_of(u.Quantity["length"])
PhysicalType('length')
unxt.dims.dimension_of(obj: type[AbstractAngle], /) PhysicalType
Parameters:

obj (Any)

Return type:

Any

Get the dimension of an angle class.

Examples

>>> import unxt as u
>>> u.dimension_of(u.Angle)
PhysicalType('angle')
unxt.dims.dimension_of(obj: Quantity, /) PhysicalType
Parameters:

obj (Any)

Return type:

Any

Return the dimension of a quantity.

Examples

>>> import unxt as u
>>> import astropy.units as apyu
>>> q = apyu.Quantity(1, "m")
>>> u.dimension_of(q)
PhysicalType('length')
Parameters:

obj (Any)

Return type:

Any

unxt.dims.AbstractDimension#

alias of PhysicalType