pynbody.units.UnitBase#
- class pynbody.units.UnitBase[source]#
Bases:
object
Base class for units. To instantiate a unit, call the
pynbody.units.Unit()
factory function.Methods
Returns the dimensionality of the Unit object.
in_units
(*a, **kw)Alias for ratio
irrep
()Return a unit equivalent to this one (may be identical) but expressed in terms of the currently defined IrreducibleUnit instances.
ratio
(other, **substitutions)Get the conversion ratio between this Unit and another specified unit.
is_dimensionless
simplify
- dimensionality_as_string()[source]#
Returns the dimensionality of the Unit object.
Example
> pynbody.units.Unit(“3e8 m s**-1 yr”).dimensionality_as_string() ‘m^1’
- irrep()[source]#
Return a unit equivalent to this one (may be identical) but expressed in terms of the currently defined IrreducibleUnit instances.
- ratio(other, **substitutions)[source]#
Get the conversion ratio between this Unit and another specified unit.
Keyword arguments, if specified, give numerical substitutions for the named unit. This is most useful for specifying values for cosmological quantities like ‘a’ and ‘h’, but can also be used for any IrreducibleUnit.
>>> Unit("1 Mpc a").ratio("kpc", a=0.25) 250.0 >>> Unit("1 Mpc").ratio("Msol") UnitsException: not convertible >>> Unit("1 Mpc").ratio("Msol", kg=25.0, m=50.0) 3.1028701506345152e-08