pynbody.units.IrreducibleUnit#
- class pynbody.units.IrreducibleUnit(st)[source]#
Bases:
UnitBaseRepresents a unit which cannot be further simplified.
Methods
copy()Shortcut for
copy.copy(unit)using python's copy moduledimensional_project(basis_units)Work out how to express the dimensions of this unit relative to the specified list of basis units.
Returns the dimensionality of the Unit object.
dimensionless_constant(**substitutions)If this unit is dimensionless, return its scalar quantity.
in_units(*a, **kw)Alias for ratio
irrep()Return a unit equivalent to this one in terms of the currently defined :class:`IrreducibleUnit`s
Returns True if the unit is dimensionless, False otherwise.
latex()Returns a LaTeX representation of this unit.
ratio(other, **substitutions)Get the conversion ratio between this Unit and another specified unit.
simplify()Return a simplified version of the unit.
- copy()#
Shortcut for
copy.copy(unit)using python’s copy module
- dimensional_project(basis_units)#
Work out how to express the dimensions of this unit relative to the specified list of basis units.
This is used by the framework when making inferences about sensible units to use in various situations.
For example, you can represent a length as an energy divided by a force:
>>> Unit("23 kpc").dimensional_project(["J", "N"]) array([1, -1], dtype=object)
However it’s not possible to represent a length by energy alone:
>>> Unit("23 kpc").dimensional_project(["J"]) UnitsException: Basis units do not span dimensions of specified unit
This function also doesn’t know what to do if the result is ambiguous:
>>> Unit("23 kpc").dimensional_project(["J", "N", "kpc"]) UnitsException: Basis units are not linearly independent
- dimensionality_as_string()#
Returns the dimensionality of the Unit object.
Example
> pynbody.units.Unit(“3e8 m s**-1 yr”).dimensionality_as_string() ‘m^1’
- dimensionless_constant(**substitutions)[source]#
If this unit is dimensionless, return its scalar quantity.
Direct use of this function is not recommended. It is generally better to use the ratio function instead.
Provide keyword arguments to set values for named IrreducibleUnits – see the
ratio()function for more information.
- in_units(*a, **kw)#
Alias for ratio
- irrep()[source]#
Return a unit equivalent to this one in terms of the currently defined :class:`IrreducibleUnit`s
Two units are equivalent if they have the same
irrep.
- is_dimensionless()#
Returns True if the unit is dimensionless, False otherwise.
- latex()[source]#
Returns a LaTeX representation of this unit.
Prefactors are converted into exponent notation. Named units by default are represented by the string ‘mathrm{unit_name}’, although this can be overriden in the pynbody configuration files or by setting unit_name._latex.
- ratio(other, **substitutions)#
Get the conversion ratio between this Unit and another specified unit.
- Parameters:
other (Unit or str) – The other unit to convert to.
substitutions (dict) – Substitutions to make for units in the conversion. For example, if the unit is a comoving distance, you can specify the scale factor a. More generally, you can specify a valuable for any IrreducibleUnit.
Notes
Usage examples:
>>> 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
- simplify()#
Return a simplified version of the unit.