quantulum3 icon indicating copy to clipboard operation
quantulum3 copied to clipboard

Conversion of units to pint

Open Helveg opened this issue 5 years ago • 7 comments

Is there any integration/conversion possible to pint units and quantities?

Helveg avatar Jul 23 '19 10:07 Helveg

There is no integration/conversion currently, but of course this is possible :)

nielstron avatar Jul 23 '19 11:07 nielstron

Is there already an obvious way to do it? Currently I'm trying to use the unit name to get the corresponding pint unit but they're not a one on one relation...

On Tue, 23 Jul 2019, 13:31 Niels Mündler, [email protected] wrote:

There is no integration/conversion currently, but of course this is possible :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/nielstron/quantulum3/issues/133?email_source=notifications&email_token=AG4VQS5R5CPIRFXVBVVXG5TQA3T2ZA5CNFSM4IGCYBN2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2S2ERQ#issuecomment-514171462, or mute the thread https://github.com/notifications/unsubscribe-auth/AG4VQSYYF4YMGJBYRUQNLBLQA3T2ZANCNFSM4IGCYBNQ .

Helveg avatar Jul 23 '19 11:07 Helveg

I do not know of an obvious way. One could think about including matching pint units in the units.json files.

When trying to work with the current state of the project I can only suggest trying the different possible names and abbreviations of a unit (they are iterable with .unit.name, .unit.surfaces and .unit.symbols, also see the unit class definition) with the parse_expression method of pint. As a security check you can re-parse the stringyfied result and test whether quantulum extracts the same unit again.

nielstron avatar Jul 23 '19 20:07 nielstron

I was wondering about this too.

The manipulation section of the docs mentions several other packages for working with quantities. (I'm not sure if astropy.units builds on one of those, or whether it is yet another representation?)

It's unlikely that each separate package maintainer would want to change their quantity object representations to a common representation, but it would be handy if one of them could act as a bridge to convert to / from the other representations.

Or perhaps it would be better to start a new package whose role was simply to convert object representations between the different packages?

psychemedia avatar Aug 06 '19 11:08 psychemedia

So a ... unit conversion package conversion package ... ;D

On Tue, 6 Aug 2019, 13:58 Tony Hirst, [email protected] wrote:

I was wondering about this too.

The manipulation https://github.com/nielstron/quantulum3#manipulation section of the docs mentions several other packages for working with quantities. (I'm not sure if astropy.units https://docs.astropy.org/en/stable/units/ builds on one of those, or whether it is yet another representation?)

It's unlikely that each separate package maintainer would want to change their quantity object representations to a common representation, but it would be handy if one of them could act as a bridge to convert to / from the other representations.

Or perhaps it would be better to start a new package whose role was simply to convert object representations between the different packages?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/nielstron/quantulum3/issues/133?email_source=notifications&email_token=AG4VQS24HY2STS3DM5G5AQ3QDFROFA5CNFSM4IGCYBN2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3U4YCQ#issuecomment-518638602, or mute the thread https://github.com/notifications/unsubscribe-auth/AG4VQS4W5FU6RM6DIRJ43CDQDFROFANCNFSM4IGCYBNQ .

Helveg avatar Aug 06 '19 12:08 Helveg

I was going to post the appropriate that XKCD cartoon, but thought better of it! ;-)

psychemedia avatar Aug 06 '19 12:08 psychemedia

I did some mapping match between unit name/surfaces/symbols of quantulum units and names of units of quantities library

import quantities as pq
dir(pq)

for e.g. result for 'mass' and 'volume' entities mostly matching each other

mappings = {"short ton": "ton", "kilogram": "kilogram", "gram": "gram", "milligram": "milligram", "atomic mass unit": "dalton", "pound-mass": "pound", "ounce": "ounce", "ton": "ton", "tonne": "tonne", "quintal": "q", "carat": "carat", "bushel": "bushel", "cubic metre": "kiloliter", "cubic centimetre": "millilitre", "litre": "litre", "centilitre": "cl", "decilitre": "dl", "barrel": "barrel", "gallon": "gallon", "quart": "quart", "pint": "pint", "cup": "cup", "fluid ounce": "floz", "tablespoon": "tablespoon", "teaspoon": "teaspoon", "stere": "stere", "peck": "peck"}

hrabkin avatar Jan 15 '24 14:01 hrabkin