Units and unit systems¶
Unit system for physical quantities; include definition of constants.
-
class
sympy.physics.unitsystems.units.
Unit
[source]¶ Class for the units.
A unit is defined by two things:
- a dimension;
- a factor.
The factor represents the position of the unit with respect to the canonical unit of this dimension. For example if we choose the gram to be the canonical dimension for the mass, then by definition its factor is 1; on the other hand the factor defined here for kilogram is 1000, even when it is a base unit. The explanation is that here we do not have defined any system that we could use as a reference: here the canonical unit is the only scale, and thus the only available origin.
Additionnaly one can add a prefix and an abbreviation. The only utility of the former is to provide a shorthand for some units, but it is never used among computations; it appears only when defining and printing units. The same remark applies to the abbreviation.
All operations (pow, mul, etc.) are defined as the corresponding ones acting on the factor (a number) and the dimension.
-
abbrev
¶ Symbol representing the unit name.
Prepend the abbreviation with the prefix symbol if it is defines.
-
abbrev_dim
¶ Abbreviation which use only intrinsinc properties of the unit.
-
as_quantity
¶ Convert the unit to a quantity.
The quantity unit is given by the unit of factor 1 and with identical dimension.
>>> from sympy.physics.unitsystems.dimensions import Dimension >>> from sympy.physics.unitsystems.units import Unit >>> length = Dimension(length=1) >>> u = Unit(length, factor=10) >>> q = u.as_quantity >>> q.factor 10 >>> q.unit == Unit(length) True
-
factor
¶ Overall magnitude of the unit.
-
class
sympy.physics.unitsystems.units.
Constant
[source]¶ Physical constant.
In our framework a constant is considered as a unit, to which humans givesa special sense, because we believe that they give us a special information on nature; but it is just a demonstration of our ignorance.
-
class
sympy.physics.unitsystems.units.
UnitSystem
(base, units=(), name='', descr='')[source]¶ UnitSystem represents a coherent set of units.
A unit system is basically a dimension system with notions of scales. Many of the methods are defined in the same way.
It is much better if all base units have a symbol.
-
dim
¶ Give the dimension of the system.
That is return the number of units forming the basis.
-
extend
(base, units=(), name='', description='')[source]¶ Extend the current system into a new one.
Take the base and normal units of the current system to merge them to the base and normal units given in argument. If not provided, name and description are overriden by empty strings.
-
get_unit
(unit)[source]¶ Find a specific unit which is part of the system.
unit can be a string or a dimension object. If no unit is found, then return None.
-
is_consistent
¶ Check if the underlying dimension system is consistent.
-