hgrecco / pint

Operate and manipulate physical quantities in Python
http://pint.readthedocs.org/
Other
2.36k stars 466 forks source link

uncertainty propagation looses dimension information #341

Closed morgenst closed 8 years ago

morgenst commented 8 years ago

Hi dev team,

let me first stress that pint is a very awesome tool I enjoy much using. However, I came across an issue when doing quadratic uncertainty propagation. Essentially when I do the following:

`from scipy import sqrt ureg = pint.UnitRegistry()

q1 = ureg.Quantity(10, ureg.Bq) q2 = ureg.Quantity(10000, ureg.mBq) q3 = sqrt(pow(q1,2) + pow(q2, 2))'

the magnitude is calculated correctly, but q3 is dimensionless. Since this is a quite often occuring calculation in physics, I was wondering whether there is a fix for this?

Thanks, Marcus

morgenst commented 8 years ago

Sorry folks, somehow missed issue #276. Anyhow, is there any explanation why it works with sqrt from numpy and not with scipy implementation? Thx

hgrecco commented 8 years ago

Thanks for your comments about Pint! We are glad that you find it useful.

It works for numpy because numpy provides a hook to provide custom implementations for numerical functions. This is not the case for scipy. By the way for your case, you can just do:

>>> (q1 ** 2 + q2 ** 2) ** (1./2)