hgrecco / pint

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

Unit ignored after number after per #430

Closed DancingQuanta closed 8 years ago

DancingQuanta commented 8 years ago

I have been trying to convert between different concentrations of particles detected by various sensors to a standard concentration for analysis. For example, a sensor (called Grimm) measures the number of particles per 100 millilitres and other sensor (called Dylos) measures the number of particles per 0.01 cubic foot.

I tried

In [1]: from pint import UnitRegistry

In [2]: ureg = UnitRegistry()

In [3]: ureg("counts per 0.01 cubic foot")
Out[3]: <Quantity(100.0, 'count * foot ** 3')>

In [4]: ureg("counts per 100 millilitre")
Out[4]: <Quantity(0.01, 'count * milliliter')>

It appears that Pint did not produce expected results where I expect 100 count / foot \ 3 and 0.01 count / millilitre. Replacing per with / produces same results.

My application require I enter the concentration like this as I store the concentration units in a YAML file.

hgrecco commented 8 years ago

You are missing the parenthesis:

>>> ureg("counts / ( 0.01 cubic foot)")
<Quantity(100.0, 'count / foot ** 3')>
>>> ureg("counts per ( 0.01 cubic foot)")
<Quantity(100.0, 'count / foot ** 3')>
DancingQuanta commented 8 years ago

Silly me should have thought of that !

On 13 Sep 2016 15:20, "Hernan Grecco" notifications@github.com wrote:

You are missing the parenthesis:

ureg("counts / ( 0.01 cubic foot)")<Quantity(100.0, 'count / foot 3')>>>> ureg("counts per ( 0.01 cubic foot)")<Quantity(100.0, 'count / foot 3')>

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hgrecco/pint/issues/430#issuecomment-246696783, or mute the thread https://github.com/notifications/unsubscribe-auth/AIB3VQIczP5LY7XiSYvl9BL_ru9WUPVJks5qprEcgaJpZM4J6Vxw .