pynbody.units.CompositeUnit#

class pynbody.units.CompositeUnit(scale, bases, powers)[source]#

Bases: UnitBase

Methods

copy()

Create a copy which is 'shallow' in the sense that it references exactly the same underlying base units, but where the list of those units can be manipulated separately.

dimensional_project(basis_units)

Work out how to express the dimensions of this unit relative to the specified list of basis units.

dimensionality_as_string()

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 new unit which represents this unit expressed solely in terms of IrreducibleUnit bases.

is_dimensionless()

Returns true if this unit actually translates into a scalar quantity.

latex()

Returns a LaTeX representation of this unit.

ratio(other, **substitutions)

Get the conversion ratio between this Unit and another specified unit.

simplify

__init__(scale, bases, powers)[source]#

Initialize a composite unit.

Direct use of this function is not recommended. Instead use the factory function Unit(…).

copy()[source]#

Create a copy which is ‘shallow’ in the sense that it references exactly the same underlying base units, but where the list of those units can be manipulated separately.

dimensional_project(basis_units)[source]#

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 new unit which represents this unit expressed solely in terms of IrreducibleUnit bases.

is_dimensionless()[source]#

Returns true if this unit actually translates into a scalar quantity.

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.

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