class astropy.units.PhysicalType(unit, physical_types)[source]#

Bases: object

Represents the physical type(s) that are dimensionally compatible with a set of units.

Instances of this class should be accessed through either get_physical_type or by using the physical_type attribute of units. This class is not intended to be instantiated directly in user code.

For a list of physical types, see astropy.units.physical.


The unit to be represented by the physical type.

physical_typesstr or set of str

A str representing the name of the physical type of the unit, or a set containing strings that represent one or more names of physical types.


A physical type will be considered equal to an equivalent PhysicalType instance (recommended) or a string that contains a name of the physical type. The latter method is not recommended in packages, as the names of some physical types may change in the future.

To maintain backwards compatibility, two physical type names may be included in one string if they are separated with a slash (e.g., "momentum/impulse"). String representations of physical types may include underscores instead of spaces.


PhysicalType instances may be accessed via the physical_type attribute of units.

>>> import astropy.units as u
>>> u.meter.physical_type

PhysicalType instances may also be accessed by calling get_physical_type. This function will accept a unit, a string containing the name of a physical type, or the number one.

>>> u.get_physical_type(u.m ** -3)
PhysicalType('number density')
>>> u.get_physical_type("volume")
>>> u.get_physical_type(1)

Some units are dimensionally compatible with multiple physical types. A pascal is intended to represent pressure and stress, but the unit decomposition is equivalent to that of energy density.

>>> pressure = u.get_physical_type("pressure")
>>> pressure
PhysicalType({'energy density', 'pressure', 'stress'})
>>> 'energy density' in pressure

Physical types can be tested for equality against other physical type objects or against strings that may contain the name of a physical type.

>>> area = (u.m ** 2).physical_type
>>> area == u.barn.physical_type
>>> area == "area"

Multiplication, division, and exponentiation are enabled so that physical types may be used for dimensional analysis.

>>> length = u.pc.physical_type
>>> area = ( ** 2).physical_type
>>> length * area
>>> area / length
>>> length ** 3

may also be performed using a string that contains the name of a physical type.

>>> "length" * area
>>> "area" / length

Unknown physical types are labelled as "unknown".

>>> (u.s ** 13).physical_type

Dimensional analysis may be performed for unknown physical types too.

>>> length_to_19th_power = (u.m ** 19).physical_type
>>> length_to_20th_power = (u.m ** 20).physical_type
>>> length_to_20th_power / length_to_19th_power