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.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: 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_ofGet the dimension of an object
unxt.unitsUnit specifications can also use dimension expressions
- 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.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.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
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[AbstractParametricQuantity], /) PhysicalType
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
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