hgrecco / pint

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

Pint + uncertainties #710

Open SengerM opened 5 years ago

SengerM commented 5 years ago

This is not exactly an issue of pint but maybe you can help me. I am using both pint and uncertainties to avoid tedious calculations. When operations consist only in +,-,* and / everything works perfectly. The problem arises when I try to use other functions of the uncertainties package such as cosine(), sqrt(), etc. A MWE of what I am trying to do is as follows

import uncertainties as un
from uncertainties.umath import *
import pint
ureg = pint.UnitRegistry()
a = un.ufloat(10,1)*ureg.meter
b = un.ufloat(2,0.1)*ureg.meter
print(a/b) # This works nice
print(sqrt(un.ufloat(3,1))) # This works nice
print(sqrt(a/b)) # This fails

As far as I know the problem is that sqrt() is waiting for a ufloat object. Is there any way to implement this?

hgrecco commented 5 years ago

Pint has this in a class called Measurement (actually using uncertainties under the hood). See the docs

I would like to make a separate package integrating these two modules in a better way.