Units

The two main functions for working with units are uparse and u_str:

DynamicQuantities.UnitsParse.@u_strMacro
u"[unit expression]"

Parse a string containing an expression of units and return the corresponding Quantity object with Float64 value. For example, u"km/s^2" would be parsed to Quantity(1000.0, length=1, time=-2).

Note that inside this expression, you also have access to the Constants module. So, for example, u"Constants.c^2 * Hz^2" would evaluate to the quantity corresponding to the speed of light multiplied by Hertz, squared.

source
DynamicQuantities.UnitsParse.uparseFunction
uparse(s::AbstractString)

Parse a string containing an expression of units and return the corresponding Quantity object with Float64 value. For example, uparse("m/s") would be parsed to Quantity(1.0, length=1, time=-1).

Note that inside this expression, you also have access to the Constants module. So, for example, uparse("Constants.c^2 * Hz^2") would evaluate to the quantity corresponding to the speed of light multiplied by Hertz, squared.

source

Available units

The base SI units are as follows. You can either use the @u_str macro like 1.5u"m", or simply import these explicitly from the package with using DynamicQuantities: m.

DynamicQuantities.Units.sConstant

Time in seconds. Available variants: fs, ps, ns, μs (/us), ms, min (/minute), h (/hr), day (/d), wk, yr, kyr, Myr, Gyr.

source

Derived units

Several derived SI units are available as well:

DynamicQuantities.Units.SConstant

Electrical conductance, electric susceptance, and electric admittance in siemens. Available variants: nS, μS (/uS), mS, kS, MS, GS.

source
DynamicQuantities.Units.radConstant

Angle in radians. Note that the SI definition is simply 1 rad = 1, so use symbolic units to avoid this. Available variants: nrad, μrad (/urad), mrad, deg, arcmin, arcsec, μarcsec (/uarcsec), marcsec.

source
DynamicQuantities.Units.ΩConstant

Resistance in Ohms. Available variant: nΩ, μΩ (/uΩ), , , , . Also available is ASCII ohm (with variants nohm, μohm (/uohm), mohm, kohm, Mohm, Gohm).

source

Custom Units

You can define custom units with the @register_unit macro:

DynamicQuantities.@register_unitMacro
@register_unit symbol value

Register a new unit under the given symbol to have a particular value.

Example

julia> @register_unit MyVolt 1.5u"V"

This will register a new unit MyVolt with a value of 1.5u"V". You can then use this unit in your calculations:

julia> x = 20us"MyVolt^2"
20.0 MyVolt²

julia> y = 2.5us"A"
2.5 A

julia> x * y^2 |> us"W^2"
281.25 W²

julia> x * y^2 |> us"W^2" |> sqrt |> uexpand
16.77050983124842 m² kg s⁻³
source