Symbolic Dimensions

Whereas u"..." will automatically convert all units to the same base SI units, us"..." will not. This uses the SymbolicDimensions type, which is a subtype of AbstractDimensions that stores the dimensions symbolically. This is useful for keeping track of the original units and constants in a user-entered expression.

The two main functions for working with symbolic units are sym_uparse and us_str:

DynamicQuantities.@us_strMacro
us"[unit expression]"

Parse a string containing an expression of units and return the corresponding Quantity object with Float64 value. However, unlike the regular u"..." macro, this macro uses SymbolicDimensions for the dimension type, which means that all units and constants are stored symbolically and will not automatically expand to SI units. For example, us"km/s^2" would be parsed to Quantity(1.0, SymbolicDimensions, km=1, s=-2).

Note that inside this expression, you also have access to the Constants module. So, for example, us"Constants.c^2 * Hz^2" would evaluate to Quantity(1.0, SymbolicDimensions, c=2, Hz=2). However, note that due to namespace collisions, a few physical constants are automatically converted.

source
DynamicQuantities.SymbolicUnits.sym_uparseFunction
sym_uparse(raw_string::AbstractString)

Parse a string containing an expression of units and return the corresponding Quantity object with Float64 value. However, that unlike the regular u"..." macro, this macro uses SymbolicDimensions for the dimension type, which means that all units and constants are stored symbolically and will not automatically expand to SI units. For example, sym_uparse("km/s^2") would be parsed to Quantity(1.0, SymbolicDimensions, km=1, s=-2).

Note that inside this expression, you also have access to the Constants module. So, for example, sym_uparse("Constants.c^2 * Hz^2") would evaluate to Quantity(1.0, SymbolicDimensions, c=2, Hz=2). However, note that due to namespace collisions, a few physical constants are automatically converted.

source

You can also access these from the exported modules SymbolicUnits for the units and SymbolicConstants. The same units and constants are available as for u"...", simply in the symbolic form.

To convert a quantity to its regular base SI units, use uexpand:

DynamicQuantities.uexpandFunction
uexpand(q::UnionAbstractQuantity{<:Any,<:AbstractSymbolicDimensions})

Expand the symbolic units in a quantity to their base SI form. In other words, this converts a quantity with AbstractSymbolicDimensions to one with Dimensions. The opposite of this function is uconvert, for converting to specific symbolic units, or, e.g., convert(Quantity{<:Any,<:AbstractSymbolicDimensions}, q), for assuming SI units as the output symbols.

source

To convert a quantity in regular base SI units to corresponding symbolic units, use uconvert:

DynamicQuantities.uconvertFunction
uconvert(qout::UnionAbstractQuantity{<:Any, <:AbstractSymbolicDimensions}, q::UnionAbstractQuantity{<:Any, <:Dimensions})

Convert a quantity q with base SI units to the symbolic units of qout, for q and qout with compatible units. Mathematically, the result has value q / uexpand(qout) and units dimension(qout).

You can also use |> as a shorthand for uconvert:

julia> q = 1u"m/s^2" |> us"km/h^2"
12960.0 km h⁻²
source
uconvert(qout::UnionAbstractQuantity{<:Any, <:AbstractSymbolicDimensions})

Create a function that converts an input quantity q with base SI units to the symbolic units of qout, i.e a function equivalent to q -> uconvert(qout, q).

source