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, /)#
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.methodsin an interactive Python session.- unxt.dims.dimension(obj: PhysicalType, /) PhysicalType
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
Construct dimension from a string.
The string can be:
A simple dimension name (e.g., ālengthā, ātimeā, āmassā)
A multi-word dimension name (e.g., āamount of substanceā, āabsementā)
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
unxt.dims.dimension_ofGet the dimension of an object
unxt.unitsUnit specifications can also use dimension expressions
- unxt.dims.dimension_of(obj, /)#
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.methodsin an interactive Python session.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
Return the dimension of the given units.
Examples
>>> from unxt.dims import dimension, dimension_of
>>> dimension_of(dimension("length")) PhysicalType('length')
Get the dimension of a type.
Examples
>>> import unxt as u
>>> try: ... u.dimension_of(u.quantity.Quantity) ... except ValueError as e: ... print(e) Cannot get the dimension of <class 'unxt._src.quantity.quantity.Quantity'>.
- unxt.dims.dimension_of(obj: UnitBase | FunctionUnitBase, /) PhysicalType
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
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[AbstractAngle], /) PhysicalType
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
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')
- unxt.dims.AbstractDimension#
alias of
PhysicalType