Skip to content

Units

svetlanna.units.ureg

Bases: Enum

Unit registry for SI-prefixed length, time, and frequency units.

A simple unit registry supporting SI prefixes (T, G, M, k, m, u, n, p, f, a) for length (m), time (s), and frequency (Hz) units. Supports basic arithmetic operations with scalars.

Warning

Units are multiplicative factors only; they carry no information about the physical quantity. Keep eye on the units you use to ensure consistency across calculations.

Warning

Round-off errors may occur when using very large and very small units due to floating-point precision limits.

Examples:

1
2
3
4
5
6
7
from svetlanna.units import ureg

wavelength = 500 * ureg.nm  # 5e-7
x = torch.linspace(-5 * ureg.mm, 5 * ureg.mm, 10)
y = torch.linspace(-5, 5, 10) * ureg.mm

print(f'λ={wavelength / ureg.um:.3f} μm')  # >>> λ=0.500 μm

Attributes:

  • Gm, Mm, km, m, dm, cm, mm, um, nm, pm (float) –

    Length units (gigameters to picometers).

  • Gs, Ms, ks, s, ds, cs, ms, us, ns, ps, fs, as_ (float) –

    Time units (gigaseconds to attoseconds).

  • THz, GHz, MHz, kHz, Hz, dHz, cHz, mHz, uHz, nHz, pHz (float) –

    Frequency units (terahertz to picohertz).