← Back to team overview

python-quantities-developers team mailing list archive

some ideas on compound units and canceling

 

I have been thinking a bit about how we should handle units that the user
wants to be compound (like m**2/m**3, which currently reduces to 1/m) and
units of the same "type" (like J and BTU). I think ideally, the quantity
10.0 * J/BTU (it currently stays as J/BTU) should come out as dimensionless
under most circumstances, but there should be some way to force it to stay
as a compound unit.

Here is one way we could deal with this:

Units which have exactly the same base type (like J and BTU) should cancel
normally, but any quantity/dimension can be told to be "static" which makes
it not cancel unless forced to do so. The .static property would be used
when creating a compound unit. I envision something like this:

kPa * L / J     ->     kPa * L / J

but

J/BTU     ->      (dimensionless)

but

J.static/BTU.static     ->      J/BTU

but

(J.static/BTU.static).simplified     ->      (dimensionless)

Creating compound units would be done like: compoundUnit = CompoundUnit (
(km**2).static/(m**3).static)

We might also think about automatically simplifying any unit group that
comes out dimensionless (kPa * m**3/J      ->      (dimensionless) but
kPa * m**3/ ( J/m)      ->      kPa * m**3/ ( J/m) ) . However, I suspect
this might be too confusing.

Some other ideas:
1) Instead of using the .static property, we could have extra units like
BTU_ and J_ etc. that would behave statically (not reduce unless forced) and
use most of the above
2) Instead of the above, we could parse a string so that creating a would
work like this: compoundUnit = CompoundUnit ("km**2/m**3")
3) Or we could simply use the existing framework; have the user name a unit
and give it a reference quantity: compoundUnit = UnitQuantity ("km**2/m**3",
km**2/m**3).  We could add an argument that tells the quantity it is a
compound unit so that uses parentheses when it writes it out. I suspect this
may end up being the simplest solution.
4) We could also change around quantities so that units are not reduced at
all except when they are printed out (so m/m gets stored as m/m but is
reduced when printed out). This would allow us to simply print out compound
units as they are actually stored. However, I suspect this would be very
awkward.

Tell me what ideas you think are good or bad.

Follow ups