CompositeUnit#

class astropy.units.CompositeUnit(scale: Complex, bases: Sequence[UnitBase], powers: Sequence[Real], decompose: bool = False, decompose_bases: Collection[UnitBase] = (), _error_check: Literal[True] = True)[source]#
class astropy.units.CompositeUnit(scale: UnitScale, bases: Sequence[UnitBase], powers: Sequence[UnitPower], decompose: bool = False, decompose_bases: Collection[UnitBase] = (), _error_check: Literal[False] = False)

Bases: UnitBase

Create a composite unit using expressions of previously defined units.

Direct use of this class is not recommended. Instead use the factory function Unit and arithmetic operators to compose units.

Parameters:
scalenumber

A scaling factor for the unit.

basessequence of UnitBase

A sequence of units this unit is composed of.

powerssequence of numbers

A sequence of powers (in parallel with bases) for each of the base units.

Raises:
UnitScaleError

If the scale is zero.

Attributes Summary

bases

The bases of the composite unit.

powers

The powers of the bases of the composite unit.

scale

The scale of the composite unit.

Methods Summary

decompose([bases])

Return a unit object composed of only irreducible units.

is_unity()

Check whether the unit is unscaled and dimensionless.

Attributes Documentation

bases#

The bases of the composite unit.

powers#

The powers of the bases of the composite unit.

scale#

The scale of the composite unit.

Methods Documentation

decompose(bases: Collection[UnitBase] = ()) CompositeUnit[source]#

Return a unit object composed of only irreducible units.

Parameters:
basessequence of UnitBase, optional

The bases to decompose into. When not provided, decomposes down to any irreducible units. When provided, the decomposed result will only contain the given units. This will raises a UnitsError if it’s not possible to do so.

Returns:
unitCompositeUnit

New object containing only irreducible unit objects.

is_unity() bool[source]#

Check whether the unit is unscaled and dimensionless.