astro py:docs

- Index
- Modules

### Navigation

- next »
- « previous |
- Astropy v5.2.1 »
- Units and Quantities (`astropy.units`) »
- PhysicalType

# PhysicalType

class astropy.units.physical.PhysicalType(unit, physical_types)

  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.

  Parameters:
    unit `Unit`

      The unit to be represented by the physical type.

    physical_types `str` 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.

  Notes

  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.

  Examples

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

      >>> import astropy.units as u
      >>> u.meter.physical_type
      PhysicalType('length')

  `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")
      PhysicalType('volume')
      >>> u.get_physical_type(1)
      PhysicalType('dimensionless')

  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
      True

  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
      True
      >>> area == "area"
      True

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

      >>> length = u.pc.physical_type
      >>> area = (u.cm ** 2).physical_type
      >>> length * area
      PhysicalType('volume')
      >>> area / length
      PhysicalType('length')
      >>> length ** 3
      PhysicalType('volume')

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

      >>> "length" * area
      PhysicalType('volume')
      >>> "area" / length
      PhysicalType('length')

  Unknown physical types are labelled as `"unknown"`.

      >>> (u.s ** 13).physical_type
      PhysicalType('unknown')

  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
      PhysicalType('length')