On Github tbekolay / scipy2013-quantities
Trevor Bekolay University of Waterloo bekolay.org/scipy2013-quantities
Hi, I'm Trevor Bekolay You can follow along with this talk at this URL I want to talk to you about quantities Introduced in python-neo It was good Why aren't they more common?Container
class Quantity(object): def __init__(self, magnitude, unit): ...
Subclass
class Quantity(numpy.ndarray): def __new__(cls, ...): ...To clarify about implementation, this is what I mean If you want pure speed and dimensional analysis check out numericalunits * Or check it out anyway, it's neat
from scipy.optimize import fsolve CA0 = 1 * u.mol / u.L CA = 0.01 * u.mol / u.L k = 1.0 / u.s def func(t): return CA - CA0 * np.exp(-k * t) tguess = 4 * u.s print fsolve(func, tguess)
from scipy.optimize import fsolve as _fsolve def fsolve(func, t0): # units on initial guess, normalized tU = t0 / float(t0) def wrapped_func(t): return float(func(t * tU)) sol, = _fsolve(wrapped_func, t0) return sol * tU
Thanks John! (jkitchin.github.io/blog)
length = 5.0 * q.meterQuantity constructor with unit argument (string or unit)
length = q.Quantity(5.0, units='meter') length = q.Quantity(5.0, units=q.meter)
length = np.ones((3, 3)) * q.meter length = q.Quantity(np.ones((3, 3)), units='meter') length = q.Quantity(np.ones((3, 3)), units=q.units.meter)