Physical Units

scanning-squid knows about physical units thanks to pint, a package designed to operate on and manipulate physical quantities.

pint is based around the UnitRegistry, an object that knows a set of physical units and the relationships between them.

[1]:
from pint import UnitRegistry
ureg = UnitRegistry()

We can use the our instance of UnitRegistry (here called ureg) to convert a dimensionless number like 2 into a dimensionful quantity like 2 \(\mu\)V, or parse a string like '2 uV' into a Quantity with a magnitude of 2 and unit of microvolt.

[2]:
print(2 * ureg('uV'))
2 microvolt
[3]:
v = ureg.Quantity('2 uV')
print(v)
2 microvolt

ureg knows how units are related to one another:

[4]:
print(v.to('mV'))
0.002 millivolt
[5]:
fJ = ureg.Quantity('483.6 MHz / uV') # a.c. Josephson effect
print(fJ)
print(fJ * v)
print((fJ * v).to('GHz'))
print(fJ * ureg.Quantity('1 nA') * ureg.Quantity('1 ohm'))
print((fJ * ureg.Quantity('1 uA') * ureg.Quantity('1 ohm')).to('MHz'))
483.6 megahertz / microvolt
967.2 megahertz
0.9672000000000001 gigahertz
483.6 megahertz * nanoampere * ohm / microvolt
483.6 megahertz

ureg doesn’t by default know what a \(\Phi_0\) is, but we can teach it:

[6]:
with open('squid_units.txt', 'w') as f:
    f.write('Phi0 = 2.067833831e-15 * Wb\n')
ureg.load_definitions('./squid_units.txt')
[7]:
phi0 = ureg('Phi0')
[8]:
print(phi0)
print(phi0.to('gauss * um**2'))
print(phi0.to('aT * acre'))
1 Phi0
20.67833831 gauss * micrometer ** 2
0.5109708237305385 acre * attotesla
[ ]: