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

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 

4 

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 

9 

10One = S_singleton.One 

11 

12#### UNITS #### 

13 

14# Dimensionless: 

15percent = percents = Quantity("percent", latex_repr=r"\%") 

16percent.set_global_relative_scale_factor(Rational(1, 100), One) 

17 

18permille = Quantity("permille") 

19permille.set_global_relative_scale_factor(Rational(1, 1000), One) 

20 

21 

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") 

29 

30# Base units: 

31m = meter = meters = Quantity("meter", abbrev="m") 

32 

33# gram; used to define its prefixed units 

34g = gram = grams = Quantity("gram", abbrev="g") 

35 

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) 

46 

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) 

56 

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") 

63 

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) 

69 

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) 

87 

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") 

96 

97# Other derived units: 

98optical_power = dioptre = diopter = D = Quantity("dioptre") 

99lux = lx = Quantity("lux", abbrev="lx") 

100 

101# katal is the SI unit of catalytic activity 

102katal = kat = Quantity("katal", abbrev="kat") 

103 

104# gray is the SI unit of absorbed dose 

105gray = Gy = Quantity("gray") 

106 

107# becquerel is the SI unit of radioactivity 

108becquerel = Bq = Quantity("becquerel", abbrev="Bq") 

109 

110 

111# Common mass units 

112 

113mg = milligram = milligrams = Quantity("milligram", abbrev="mg") 

114mg.set_global_relative_scale_factor(milli, gram) 

115 

116ug = microgram = micrograms = Quantity("microgram", abbrev="ug", latex_repr=r"\mu\text{g}") 

117ug.set_global_relative_scale_factor(micro, gram) 

118 

119# Atomic mass constant 

120Da = dalton = amu = amus = atomic_mass_unit = atomic_mass_constant = PhysicalConstant("atomic_mass_constant") 

121 

122t = metric_ton = tonne = Quantity("tonne", abbrev="t") 

123tonne.set_global_relative_scale_factor(mega, gram) 

124 

125# Electron rest mass 

126me = electron_rest_mass = Quantity("electron_rest_mass", abbrev="me") 

127 

128 

129# Common length units 

130 

131km = kilometer = kilometers = Quantity("kilometer", abbrev="km") 

132km.set_global_relative_scale_factor(kilo, meter) 

133 

134dm = decimeter = decimeters = Quantity("decimeter", abbrev="dm") 

135dm.set_global_relative_scale_factor(deci, meter) 

136 

137cm = centimeter = centimeters = Quantity("centimeter", abbrev="cm") 

138cm.set_global_relative_scale_factor(centi, meter) 

139 

140mm = millimeter = millimeters = Quantity("millimeter", abbrev="mm") 

141mm.set_global_relative_scale_factor(milli, meter) 

142 

143um = micrometer = micrometers = micron = microns = \ 

144 Quantity("micrometer", abbrev="um", latex_repr=r'\mu\text{m}') 

145um.set_global_relative_scale_factor(micro, meter) 

146 

147nm = nanometer = nanometers = Quantity("nanometer", abbrev="nm") 

148nm.set_global_relative_scale_factor(nano, meter) 

149 

150pm = picometer = picometers = Quantity("picometer", abbrev="pm") 

151pm.set_global_relative_scale_factor(pico, meter) 

152 

153ft = foot = feet = Quantity("foot", abbrev="ft") 

154ft.set_global_relative_scale_factor(Rational(3048, 10000), meter) 

155 

156inch = inches = Quantity("inch") 

157inch.set_global_relative_scale_factor(Rational(1, 12), foot) 

158 

159yd = yard = yards = Quantity("yard", abbrev="yd") 

160yd.set_global_relative_scale_factor(3, feet) 

161 

162mi = mile = miles = Quantity("mile") 

163mi.set_global_relative_scale_factor(5280, feet) 

164 

165nmi = nautical_mile = nautical_miles = Quantity("nautical_mile") 

166nmi.set_global_relative_scale_factor(6076, feet) 

167 

168angstrom = angstroms = Quantity("angstrom", latex_repr=r'\r{A}') 

169angstrom.set_global_relative_scale_factor(Rational(1, 10**10), meter) 

170 

171 

172# Common volume and area units 

173 

174ha = hectare = Quantity("hectare", abbrev="ha") 

175 

176l = L = liter = liters = Quantity("liter") 

177 

178dl = dL = deciliter = deciliters = Quantity("deciliter") 

179dl.set_global_relative_scale_factor(Rational(1, 10), liter) 

180 

181cl = cL = centiliter = centiliters = Quantity("centiliter") 

182cl.set_global_relative_scale_factor(Rational(1, 100), liter) 

183 

184ml = mL = milliliter = milliliters = Quantity("milliliter") 

185ml.set_global_relative_scale_factor(Rational(1, 1000), liter) 

186 

187 

188# Common time units 

189 

190ms = millisecond = milliseconds = Quantity("millisecond", abbrev="ms") 

191millisecond.set_global_relative_scale_factor(milli, second) 

192 

193us = microsecond = microseconds = Quantity("microsecond", abbrev="us", latex_repr=r'\mu\text{s}') 

194microsecond.set_global_relative_scale_factor(micro, second) 

195 

196ns = nanosecond = nanoseconds = Quantity("nanosecond", abbrev="ns") 

197nanosecond.set_global_relative_scale_factor(nano, second) 

198 

199ps = picosecond = picoseconds = Quantity("picosecond", abbrev="ps") 

200picosecond.set_global_relative_scale_factor(pico, second) 

201 

202minute = minutes = Quantity("minute") 

203minute.set_global_relative_scale_factor(60, second) 

204 

205h = hour = hours = Quantity("hour") 

206hour.set_global_relative_scale_factor(60, minute) 

207 

208day = days = Quantity("day") 

209day.set_global_relative_scale_factor(24, hour) 

210 

211anomalistic_year = anomalistic_years = Quantity("anomalistic_year") 

212anomalistic_year.set_global_relative_scale_factor(365.259636, day) 

213 

214sidereal_year = sidereal_years = Quantity("sidereal_year") 

215sidereal_year.set_global_relative_scale_factor(31558149.540, seconds) 

216 

217tropical_year = tropical_years = Quantity("tropical_year") 

218tropical_year.set_global_relative_scale_factor(365.24219, day) 

219 

220common_year = common_years = Quantity("common_year") 

221common_year.set_global_relative_scale_factor(365, day) 

222 

223julian_year = julian_years = Quantity("julian_year") 

224julian_year.set_global_relative_scale_factor((365 + One/4), day) 

225 

226draconic_year = draconic_years = Quantity("draconic_year") 

227draconic_year.set_global_relative_scale_factor(346.62, day) 

228 

229gaussian_year = gaussian_years = Quantity("gaussian_year") 

230gaussian_year.set_global_relative_scale_factor(365.2568983, day) 

231 

232full_moon_cycle = full_moon_cycles = Quantity("full_moon_cycle") 

233full_moon_cycle.set_global_relative_scale_factor(411.78443029, day) 

234 

235year = years = tropical_year 

236 

237 

238#### CONSTANTS #### 

239 

240# Newton constant 

241G = gravitational_constant = PhysicalConstant("gravitational_constant", abbrev="G") 

242 

243# speed of light 

244c = speed_of_light = PhysicalConstant("speed_of_light", abbrev="c") 

245 

246# elementary charge 

247elementary_charge = PhysicalConstant("elementary_charge", abbrev="e") 

248 

249# Planck constant 

250planck = PhysicalConstant("planck", abbrev="h") 

251 

252# Reduced Planck constant 

253hbar = PhysicalConstant("hbar", abbrev="hbar") 

254 

255# Electronvolt 

256eV = electronvolt = electronvolts = PhysicalConstant("electronvolt", abbrev="eV") 

257 

258# Avogadro number 

259avogadro_number = PhysicalConstant("avogadro_number") 

260 

261# Avogadro constant 

262avogadro = avogadro_constant = PhysicalConstant("avogadro_constant") 

263 

264# Boltzmann constant 

265boltzmann = boltzmann_constant = PhysicalConstant("boltzmann_constant") 

266 

267# Stefan-Boltzmann constant 

268stefan = stefan_boltzmann_constant = PhysicalConstant("stefan_boltzmann_constant") 

269 

270# Molar gas constant 

271R = molar_gas_constant = PhysicalConstant("molar_gas_constant", abbrev="R") 

272 

273# Faraday constant 

274faraday_constant = PhysicalConstant("faraday_constant") 

275 

276# Josephson constant 

277josephson_constant = PhysicalConstant("josephson_constant", abbrev="K_j") 

278 

279# Von Klitzing constant 

280von_klitzing_constant = PhysicalConstant("von_klitzing_constant", abbrev="R_k") 

281 

282# Acceleration due to gravity (on the Earth surface) 

283gee = gees = acceleration_due_to_gravity = PhysicalConstant("acceleration_due_to_gravity", abbrev="g") 

284 

285# magnetic constant: 

286u0 = magnetic_constant = vacuum_permeability = PhysicalConstant("magnetic_constant") 

287 

288# electric constat: 

289e0 = electric_constant = vacuum_permittivity = PhysicalConstant("vacuum_permittivity") 

290 

291# vacuum impedance: 

292Z0 = vacuum_impedance = PhysicalConstant("vacuum_impedance", abbrev='Z_0', latex_repr=r'Z_{0}') 

293 

294# Coulomb's constant: 

295coulomb_constant = coulombs_constant = electric_force_constant = \ 

296 PhysicalConstant("coulomb_constant", abbrev="k_e") 

297 

298 

299atmosphere = atmospheres = atm = Quantity("atmosphere", abbrev="atm") 

300 

301kPa = kilopascal = Quantity("kilopascal", abbrev="kPa") 

302kilopascal.set_global_relative_scale_factor(kilo, Pa) 

303 

304bar = bars = Quantity("bar", abbrev="bar") 

305 

306pound = pounds = Quantity("pound") # exact 

307 

308psi = Quantity("psi") 

309 

310dHg0 = 13.5951 # approx value at 0 C 

311mmHg = torr = Quantity("mmHg") 

312 

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) 

316 

317mmu = mmus = milli_mass_unit = Quantity("milli_mass_unit") 

318 

319quart = quarts = Quantity("quart") 

320 

321 

322# Other convenient units and magnitudes 

323 

324ly = lightyear = lightyears = Quantity("lightyear", abbrev="ly") 

325 

326au = astronomical_unit = astronomical_units = Quantity("astronomical_unit", abbrev="AU") 

327 

328 

329# Fundamental Planck units: 

330planck_mass = Quantity("planck_mass", abbrev="m_P", latex_repr=r'm_\text{P}') 

331 

332planck_time = Quantity("planck_time", abbrev="t_P", latex_repr=r't_\text{P}') 

333 

334planck_temperature = Quantity("planck_temperature", abbrev="T_P", 

335 latex_repr=r'T_\text{P}') 

336 

337planck_length = Quantity("planck_length", abbrev="l_P", latex_repr=r'l_\text{P}') 

338 

339planck_charge = Quantity("planck_charge", abbrev="q_P", latex_repr=r'q_\text{P}') 

340 

341 

342# Derived Planck units: 

343planck_area = Quantity("planck_area") 

344 

345planck_volume = Quantity("planck_volume") 

346 

347planck_momentum = Quantity("planck_momentum") 

348 

349planck_energy = Quantity("planck_energy", abbrev="E_P", latex_repr=r'E_\text{P}') 

350 

351planck_force = Quantity("planck_force", abbrev="F_P", latex_repr=r'F_\text{P}') 

352 

353planck_power = Quantity("planck_power", abbrev="P_P", latex_repr=r'P_\text{P}') 

354 

355planck_density = Quantity("planck_density", abbrev="rho_P", latex_repr=r'\rho_\text{P}') 

356 

357planck_energy_density = Quantity("planck_energy_density", abbrev="rho^E_P") 

358 

359planck_intensity = Quantity("planck_intensity", abbrev="I_P", latex_repr=r'I_\text{P}') 

360 

361planck_angular_frequency = Quantity("planck_angular_frequency", abbrev="omega_P", 

362 latex_repr=r'\omega_\text{P}') 

363 

364planck_pressure = Quantity("planck_pressure", abbrev="p_P", latex_repr=r'p_\text{P}') 

365 

366planck_current = Quantity("planck_current", abbrev="I_P", latex_repr=r'I_\text{P}') 

367 

368planck_voltage = Quantity("planck_voltage", abbrev="V_P", latex_repr=r'V_\text{P}') 

369 

370planck_impedance = Quantity("planck_impedance", abbrev="Z_P", latex_repr=r'Z_\text{P}') 

371 

372planck_acceleration = Quantity("planck_acceleration", abbrev="a_P", 

373 latex_repr=r'a_\text{P}') 

374 

375 

376# Information theory units: 

377bit = bits = Quantity("bit") 

378bit.set_global_dimension(information) 

379 

380byte = bytes = Quantity("byte") 

381 

382kibibyte = kibibytes = Quantity("kibibyte") 

383mebibyte = mebibytes = Quantity("mebibyte") 

384gibibyte = gibibytes = Quantity("gibibyte") 

385tebibyte = tebibytes = Quantity("tebibyte") 

386pebibyte = pebibytes = Quantity("pebibyte") 

387exbibyte = exbibytes = Quantity("exbibyte") 

388 

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) 

396 

397# Older units for radioactivity 

398curie = Ci = Quantity("curie", abbrev="Ci") 

399 

400rutherford = Rd = Quantity("rutherford", abbrev="Rd")