[SciPy-dev] design of a physical quantities package: seeking comments
Tue Aug 5 18:20:19 CDT 2008
I worked through a bunch of issues today on the quantities package. One can now create a quantity by doing:
>>> import quantities, numpy
>>> q=quantities.Quantity([1,2,3.0], 'J')
>>> q=quantities.Quantity([1,2,3.0], quantities.J)
>>> q = numpy.array([1,2,3.0]) * quantities.J
Quantity([ 1., 2., 3.]), kg * m^2 / s^2
I took the previous commenters' advice and made the following an error:
>>> q.units = 'ft'
IncompatibleUnits: Cannot convert between quanitites with units of 'kg m^2 s^-2' and 'ft'
Instead one can do:
The standard units will be decomposed to the fundamental dimensions, but there is a mechanism in place to preserve a compound unit, a function called compound, which can be used directly or referenced in a units string:
Quantity(19), (parsec/cm**3) * (J)
Quantity(19.0), (m^3/m^2) * (parsec/cm^3)
and there is a mechanism to force compound units to be decomposed:
Quantity(5.8627881999999992e+23), 1 / m
or they can be recomposed:
Quantity(19.000000000000004), (m^3/m^2) * (parsec/cm^3)
I also started a unittest suite. A short description and directions to get the package are at http://dale.chess.cornell.edu/chess-wiki/Quantities.
I'm pretty pleased with how everything is coming together. In fact, its more capable than I had originally envisioned. I intend to continue writing unittests, working out bugs, writing some documentation, and cleaning up the code but I'll refrain from future posts unless interest picks up.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Scipy-dev