Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions astropy/units/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Licensed under a 3-clause BSD style license - see LICENSE.rst

"""
Expand Down Expand Up @@ -1337,14 +1336,37 @@ def cgs(self):
@property
def physical_type(self):
"""
Return the physical type on the unit.
Physical type(s) dimensionally compatible with the unit.

Returns
-------
`~astropy.units.physical.PhysicalType`
A representation of the physical type(s) of a unit.

Examples
--------
>>> from astropy import units as u
>>> print(u.m.physical_type)
length

>>> u.m.physical_type
PhysicalType('length')
>>> (u.m ** 2 / u.s).physical_type
PhysicalType({'diffusivity', 'kinematic viscosity'})

Physical types can be compared to other physical types
(recommended in packages) or to strings.

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

`~astropy.units.physical.PhysicalType` objects can be used for
dimensional analysis.

>>> number_density = u.m.physical_type ** -3
>>> velocity = (u.m / u.s).physical_type
>>> number_density * velocity
PhysicalType('particle flux')
"""
from . import physical
return physical.get_physical_type(self)
Expand Down
Loading