Quantity

class astropy.units.quantity.Quantity(value, unit)[source] [edit on github]

Bases: object

A Quantity represents a number with some associated unit.

Parameters:

value : number, Quantity object, or sequence of Quantity objects.

The numerical value of this quantity in the units given by unit. If a Quantity or sequence of them, creates a new Quantity object, converting to unit units as needed.

unit : UnitBase instance, str

An object that represents the unit associated with the input value. Must be an UnitBase object or a string parseable by the units package.

Raises:

TypeError :

If the value provided is not a Python numeric type.

TypeError :

If the unit provided is not either a Unit object or a parseable string unit.

Attributes Summary

cgs Returns a copy of the current Quantity instance with CGS units.
isscalar True if the value of this quantity is a scalar, or False if it is an array-like object.
si Returns a copy of the current Quantity instance with SI units.
unit A UnitBase object representing the unit of this quantity.
value The numerical value of this quantity.

Methods Summary

copy() Return a copy of this Quantity instance
decompose([bases]) Generates a new Quantity with the units decomposed.
to(unit[, equivalencies]) Returns a new Quantity object with the specified units.

Attributes Documentation

cgs None[source]

Returns a copy of the current Quantity instance with CGS units. The value of the resulting object will be scaled.

isscalar None[source]

True if the value of this quantity is a scalar, or False if it is an array-like object.

Note

This is subtly different from numpy.isscalar in that numpy.isscalar returns False for a zero-dimensional array (e.g. np.array(1)), while this is True in that case.

si None[source]

Returns a copy of the current Quantity instance with SI units. The value of the resulting object will be scaled.

unit None[source]

A UnitBase object representing the unit of this quantity.

value None[source]

The numerical value of this quantity.

Methods Documentation

copy()[source] [edit on github]

Return a copy of this Quantity instance

decompose(bases=[])[source] [edit on github]

Generates a new Quantity with the units decomposed. Decomposed units have only irreducible units in them (see astropy.units.UnitBase.decompose).

Parameters:

bases : sequence 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 UnitsException if it’s not possible to do so.

Returns:

newq : Quantity

A new object equal to this quantity with units decomposed.

to(unit, equivalencies=[])[source] [edit on github]

Returns a new Quantity object with the specified units.

Parameters:

unit : UnitBase instance, str

An object that represents the unit to convert to. Must be an UnitBase object or a string parseable by the units package.

equivalencies : list of equivalence pairs, optional

A list of equivalence pairs to try if the units are not directly convertible. See Equivalencies.

Page Contents