Coverage for /usr/lib/python3/dist-packages/sympy/physics/units/definitions/unit_definitions.py: 100%
211 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
1from sympy.physics.units.definitions.dimension_definitions import current, temperature, amount_of_substance, \
2 luminous_intensity, angle, charge, voltage, impedance, conductance, capacitance, inductance, magnetic_density, \
3 magnetic_flux, information
5from sympy.core.numbers import (Rational, pi)
6from sympy.core.singleton import S as S_singleton
7from sympy.physics.units.prefixes import kilo, mega, milli, micro, deci, centi, nano, pico, kibi, mebi, gibi, tebi, pebi, exbi
8from sympy.physics.units.quantities import PhysicalConstant, Quantity
10One = S_singleton.One
12#### UNITS ####
14# Dimensionless:
15percent = percents = Quantity("percent", latex_repr=r"\%")
16percent.set_global_relative_scale_factor(Rational(1, 100), One)
18permille = Quantity("permille")
19permille.set_global_relative_scale_factor(Rational(1, 1000), One)
22# Angular units (dimensionless)
23rad = radian = radians = Quantity("radian", abbrev="rad")
24radian.set_global_dimension(angle)
25deg = degree = degrees = Quantity("degree", abbrev="deg", latex_repr=r"^\circ")
26degree.set_global_relative_scale_factor(pi/180, radian)
27sr = steradian = steradians = Quantity("steradian", abbrev="sr")
28mil = angular_mil = angular_mils = Quantity("angular_mil", abbrev="mil")
30# Base units:
31m = meter = meters = Quantity("meter", abbrev="m")
33# gram; used to define its prefixed units
34g = gram = grams = Quantity("gram", abbrev="g")
36# NOTE: the `kilogram` has scale factor 1000. In SI, kg is a base unit, but
37# nonetheless we are trying to be compatible with the `kilo` prefix. In a
38# similar manner, people using CGS or gaussian units could argue that the
39# `centimeter` rather than `meter` is the fundamental unit for length, but the
40# scale factor of `centimeter` will be kept as 1/100 to be compatible with the
41# `centi` prefix. The current state of the code assumes SI unit dimensions, in
42# the future this module will be modified in order to be unit system-neutral
43# (that is, support all kinds of unit systems).
44kg = kilogram = kilograms = Quantity("kilogram", abbrev="kg")
45kg.set_global_relative_scale_factor(kilo, gram)
47s = second = seconds = Quantity("second", abbrev="s")
48A = ampere = amperes = Quantity("ampere", abbrev='A')
49ampere.set_global_dimension(current)
50K = kelvin = kelvins = Quantity("kelvin", abbrev='K')
51kelvin.set_global_dimension(temperature)
52mol = mole = moles = Quantity("mole", abbrev="mol")
53mole.set_global_dimension(amount_of_substance)
54cd = candela = candelas = Quantity("candela", abbrev="cd")
55candela.set_global_dimension(luminous_intensity)
57# derived units
58newton = newtons = N = Quantity("newton", abbrev="N")
59joule = joules = J = Quantity("joule", abbrev="J")
60watt = watts = W = Quantity("watt", abbrev="W")
61pascal = pascals = Pa = pa = Quantity("pascal", abbrev="Pa")
62hertz = hz = Hz = Quantity("hertz", abbrev="Hz")
64# CGS derived units:
65dyne = Quantity("dyne")
66dyne.set_global_relative_scale_factor(One/10**5, newton)
67erg = Quantity("erg")
68erg.set_global_relative_scale_factor(One/10**7, joule)
70# MKSA extension to MKS: derived units
71coulomb = coulombs = C = Quantity("coulomb", abbrev='C')
72coulomb.set_global_dimension(charge)
73volt = volts = v = V = Quantity("volt", abbrev='V')
74volt.set_global_dimension(voltage)
75ohm = ohms = Quantity("ohm", abbrev='ohm', latex_repr=r"\Omega")
76ohm.set_global_dimension(impedance)
77siemens = S = mho = mhos = Quantity("siemens", abbrev='S')
78siemens.set_global_dimension(conductance)
79farad = farads = F = Quantity("farad", abbrev='F')
80farad.set_global_dimension(capacitance)
81henry = henrys = H = Quantity("henry", abbrev='H')
82henry.set_global_dimension(inductance)
83tesla = teslas = T = Quantity("tesla", abbrev='T')
84tesla.set_global_dimension(magnetic_density)
85weber = webers = Wb = wb = Quantity("weber", abbrev='Wb')
86weber.set_global_dimension(magnetic_flux)
88# CGS units for electromagnetic quantities:
89statampere = Quantity("statampere")
90statcoulomb = statC = franklin = Quantity("statcoulomb", abbrev="statC")
91statvolt = Quantity("statvolt")
92gauss = Quantity("gauss")
93maxwell = Quantity("maxwell")
94debye = Quantity("debye")
95oersted = Quantity("oersted")
97# Other derived units:
98optical_power = dioptre = diopter = D = Quantity("dioptre")
99lux = lx = Quantity("lux", abbrev="lx")
101# katal is the SI unit of catalytic activity
102katal = kat = Quantity("katal", abbrev="kat")
104# gray is the SI unit of absorbed dose
105gray = Gy = Quantity("gray")
107# becquerel is the SI unit of radioactivity
108becquerel = Bq = Quantity("becquerel", abbrev="Bq")
111# Common mass units
113mg = milligram = milligrams = Quantity("milligram", abbrev="mg")
114mg.set_global_relative_scale_factor(milli, gram)
116ug = microgram = micrograms = Quantity("microgram", abbrev="ug", latex_repr=r"\mu\text{g}")
117ug.set_global_relative_scale_factor(micro, gram)
119# Atomic mass constant
120Da = dalton = amu = amus = atomic_mass_unit = atomic_mass_constant = PhysicalConstant("atomic_mass_constant")
122t = metric_ton = tonne = Quantity("tonne", abbrev="t")
123tonne.set_global_relative_scale_factor(mega, gram)
125# Electron rest mass
126me = electron_rest_mass = Quantity("electron_rest_mass", abbrev="me")
129# Common length units
131km = kilometer = kilometers = Quantity("kilometer", abbrev="km")
132km.set_global_relative_scale_factor(kilo, meter)
134dm = decimeter = decimeters = Quantity("decimeter", abbrev="dm")
135dm.set_global_relative_scale_factor(deci, meter)
137cm = centimeter = centimeters = Quantity("centimeter", abbrev="cm")
138cm.set_global_relative_scale_factor(centi, meter)
140mm = millimeter = millimeters = Quantity("millimeter", abbrev="mm")
141mm.set_global_relative_scale_factor(milli, meter)
143um = micrometer = micrometers = micron = microns = \
144 Quantity("micrometer", abbrev="um", latex_repr=r'\mu\text{m}')
145um.set_global_relative_scale_factor(micro, meter)
147nm = nanometer = nanometers = Quantity("nanometer", abbrev="nm")
148nm.set_global_relative_scale_factor(nano, meter)
150pm = picometer = picometers = Quantity("picometer", abbrev="pm")
151pm.set_global_relative_scale_factor(pico, meter)
153ft = foot = feet = Quantity("foot", abbrev="ft")
154ft.set_global_relative_scale_factor(Rational(3048, 10000), meter)
156inch = inches = Quantity("inch")
157inch.set_global_relative_scale_factor(Rational(1, 12), foot)
159yd = yard = yards = Quantity("yard", abbrev="yd")
160yd.set_global_relative_scale_factor(3, feet)
162mi = mile = miles = Quantity("mile")
163mi.set_global_relative_scale_factor(5280, feet)
165nmi = nautical_mile = nautical_miles = Quantity("nautical_mile")
166nmi.set_global_relative_scale_factor(6076, feet)
168angstrom = angstroms = Quantity("angstrom", latex_repr=r'\r{A}')
169angstrom.set_global_relative_scale_factor(Rational(1, 10**10), meter)
172# Common volume and area units
174ha = hectare = Quantity("hectare", abbrev="ha")
176l = L = liter = liters = Quantity("liter")
178dl = dL = deciliter = deciliters = Quantity("deciliter")
179dl.set_global_relative_scale_factor(Rational(1, 10), liter)
181cl = cL = centiliter = centiliters = Quantity("centiliter")
182cl.set_global_relative_scale_factor(Rational(1, 100), liter)
184ml = mL = milliliter = milliliters = Quantity("milliliter")
185ml.set_global_relative_scale_factor(Rational(1, 1000), liter)
188# Common time units
190ms = millisecond = milliseconds = Quantity("millisecond", abbrev="ms")
191millisecond.set_global_relative_scale_factor(milli, second)
193us = microsecond = microseconds = Quantity("microsecond", abbrev="us", latex_repr=r'\mu\text{s}')
194microsecond.set_global_relative_scale_factor(micro, second)
196ns = nanosecond = nanoseconds = Quantity("nanosecond", abbrev="ns")
197nanosecond.set_global_relative_scale_factor(nano, second)
199ps = picosecond = picoseconds = Quantity("picosecond", abbrev="ps")
200picosecond.set_global_relative_scale_factor(pico, second)
202minute = minutes = Quantity("minute")
203minute.set_global_relative_scale_factor(60, second)
205h = hour = hours = Quantity("hour")
206hour.set_global_relative_scale_factor(60, minute)
208day = days = Quantity("day")
209day.set_global_relative_scale_factor(24, hour)
211anomalistic_year = anomalistic_years = Quantity("anomalistic_year")
212anomalistic_year.set_global_relative_scale_factor(365.259636, day)
214sidereal_year = sidereal_years = Quantity("sidereal_year")
215sidereal_year.set_global_relative_scale_factor(31558149.540, seconds)
217tropical_year = tropical_years = Quantity("tropical_year")
218tropical_year.set_global_relative_scale_factor(365.24219, day)
220common_year = common_years = Quantity("common_year")
221common_year.set_global_relative_scale_factor(365, day)
223julian_year = julian_years = Quantity("julian_year")
224julian_year.set_global_relative_scale_factor((365 + One/4), day)
226draconic_year = draconic_years = Quantity("draconic_year")
227draconic_year.set_global_relative_scale_factor(346.62, day)
229gaussian_year = gaussian_years = Quantity("gaussian_year")
230gaussian_year.set_global_relative_scale_factor(365.2568983, day)
232full_moon_cycle = full_moon_cycles = Quantity("full_moon_cycle")
233full_moon_cycle.set_global_relative_scale_factor(411.78443029, day)
235year = years = tropical_year
238#### CONSTANTS ####
240# Newton constant
241G = gravitational_constant = PhysicalConstant("gravitational_constant", abbrev="G")
243# speed of light
244c = speed_of_light = PhysicalConstant("speed_of_light", abbrev="c")
246# elementary charge
247elementary_charge = PhysicalConstant("elementary_charge", abbrev="e")
249# Planck constant
250planck = PhysicalConstant("planck", abbrev="h")
252# Reduced Planck constant
253hbar = PhysicalConstant("hbar", abbrev="hbar")
255# Electronvolt
256eV = electronvolt = electronvolts = PhysicalConstant("electronvolt", abbrev="eV")
258# Avogadro number
259avogadro_number = PhysicalConstant("avogadro_number")
261# Avogadro constant
262avogadro = avogadro_constant = PhysicalConstant("avogadro_constant")
264# Boltzmann constant
265boltzmann = boltzmann_constant = PhysicalConstant("boltzmann_constant")
267# Stefan-Boltzmann constant
268stefan = stefan_boltzmann_constant = PhysicalConstant("stefan_boltzmann_constant")
270# Molar gas constant
271R = molar_gas_constant = PhysicalConstant("molar_gas_constant", abbrev="R")
273# Faraday constant
274faraday_constant = PhysicalConstant("faraday_constant")
276# Josephson constant
277josephson_constant = PhysicalConstant("josephson_constant", abbrev="K_j")
279# Von Klitzing constant
280von_klitzing_constant = PhysicalConstant("von_klitzing_constant", abbrev="R_k")
282# Acceleration due to gravity (on the Earth surface)
283gee = gees = acceleration_due_to_gravity = PhysicalConstant("acceleration_due_to_gravity", abbrev="g")
285# magnetic constant:
286u0 = magnetic_constant = vacuum_permeability = PhysicalConstant("magnetic_constant")
288# electric constat:
289e0 = electric_constant = vacuum_permittivity = PhysicalConstant("vacuum_permittivity")
291# vacuum impedance:
292Z0 = vacuum_impedance = PhysicalConstant("vacuum_impedance", abbrev='Z_0', latex_repr=r'Z_{0}')
294# Coulomb's constant:
295coulomb_constant = coulombs_constant = electric_force_constant = \
296 PhysicalConstant("coulomb_constant", abbrev="k_e")
299atmosphere = atmospheres = atm = Quantity("atmosphere", abbrev="atm")
301kPa = kilopascal = Quantity("kilopascal", abbrev="kPa")
302kilopascal.set_global_relative_scale_factor(kilo, Pa)
304bar = bars = Quantity("bar", abbrev="bar")
306pound = pounds = Quantity("pound") # exact
308psi = Quantity("psi")
310dHg0 = 13.5951 # approx value at 0 C
311mmHg = torr = Quantity("mmHg")
313atmosphere.set_global_relative_scale_factor(101325, pascal)
314bar.set_global_relative_scale_factor(100, kPa)
315pound.set_global_relative_scale_factor(Rational(45359237, 100000000), kg)
317mmu = mmus = milli_mass_unit = Quantity("milli_mass_unit")
319quart = quarts = Quantity("quart")
322# Other convenient units and magnitudes
324ly = lightyear = lightyears = Quantity("lightyear", abbrev="ly")
326au = astronomical_unit = astronomical_units = Quantity("astronomical_unit", abbrev="AU")
329# Fundamental Planck units:
330planck_mass = Quantity("planck_mass", abbrev="m_P", latex_repr=r'm_\text{P}')
332planck_time = Quantity("planck_time", abbrev="t_P", latex_repr=r't_\text{P}')
334planck_temperature = Quantity("planck_temperature", abbrev="T_P",
335 latex_repr=r'T_\text{P}')
337planck_length = Quantity("planck_length", abbrev="l_P", latex_repr=r'l_\text{P}')
339planck_charge = Quantity("planck_charge", abbrev="q_P", latex_repr=r'q_\text{P}')
342# Derived Planck units:
343planck_area = Quantity("planck_area")
345planck_volume = Quantity("planck_volume")
347planck_momentum = Quantity("planck_momentum")
349planck_energy = Quantity("planck_energy", abbrev="E_P", latex_repr=r'E_\text{P}')
351planck_force = Quantity("planck_force", abbrev="F_P", latex_repr=r'F_\text{P}')
353planck_power = Quantity("planck_power", abbrev="P_P", latex_repr=r'P_\text{P}')
355planck_density = Quantity("planck_density", abbrev="rho_P", latex_repr=r'\rho_\text{P}')
357planck_energy_density = Quantity("planck_energy_density", abbrev="rho^E_P")
359planck_intensity = Quantity("planck_intensity", abbrev="I_P", latex_repr=r'I_\text{P}')
361planck_angular_frequency = Quantity("planck_angular_frequency", abbrev="omega_P",
362 latex_repr=r'\omega_\text{P}')
364planck_pressure = Quantity("planck_pressure", abbrev="p_P", latex_repr=r'p_\text{P}')
366planck_current = Quantity("planck_current", abbrev="I_P", latex_repr=r'I_\text{P}')
368planck_voltage = Quantity("planck_voltage", abbrev="V_P", latex_repr=r'V_\text{P}')
370planck_impedance = Quantity("planck_impedance", abbrev="Z_P", latex_repr=r'Z_\text{P}')
372planck_acceleration = Quantity("planck_acceleration", abbrev="a_P",
373 latex_repr=r'a_\text{P}')
376# Information theory units:
377bit = bits = Quantity("bit")
378bit.set_global_dimension(information)
380byte = bytes = Quantity("byte")
382kibibyte = kibibytes = Quantity("kibibyte")
383mebibyte = mebibytes = Quantity("mebibyte")
384gibibyte = gibibytes = Quantity("gibibyte")
385tebibyte = tebibytes = Quantity("tebibyte")
386pebibyte = pebibytes = Quantity("pebibyte")
387exbibyte = exbibytes = Quantity("exbibyte")
389byte.set_global_relative_scale_factor(8, bit)
390kibibyte.set_global_relative_scale_factor(kibi, byte)
391mebibyte.set_global_relative_scale_factor(mebi, byte)
392gibibyte.set_global_relative_scale_factor(gibi, byte)
393tebibyte.set_global_relative_scale_factor(tebi, byte)
394pebibyte.set_global_relative_scale_factor(pebi, byte)
395exbibyte.set_global_relative_scale_factor(exbi, byte)
397# Older units for radioactivity
398curie = Ci = Quantity("curie", abbrev="Ci")
400rutherford = Rd = Quantity("rutherford", abbrev="Rd")