<html><head><meta name="qrichtext" content="1" /></head><body style="font-size:10pt;font-family:DejaVu Sans">
<p>I worked through a bunch of issues today on the quantities package. One can now create a quantity by doing:</p>
<p></p>
<p><span style="color:#006000">>>> import quantities, numpy</span></p>
<p></p>
<p></p>
<p><span style="color:#006000">>>> q=quantities.Quantity([1,2,3.0], 'J')</span></p>
<p></p>
<p>or</p>
<p></p>
<p><span style="color:#006000">>>> q=quantities.Quantity([1,2,3.0], quantities.J)</span></p>
<p></p>
<p>or</p>
<p></p>
<p><span style="color:#006000">>>> q = numpy.array([1,2,3.0]) * quantities.J</span></p>
<p><span style="color:#006000">>>> q</span></p>
<p>Quantity([ 1.,  2.,  3.]), kg * m^2 / s^2</p>
<p></p>
<p>I took the previous commenters' advice and made the following an error:</p>
<p></p>
<p><span style="color:#006000">>>> q.units = 'ft'</span></p>
<p>IncompatibleUnits: Cannot convert between quanitites with units of 'kg m^2 s^-2' and 'ft'</p>
<p></p>
<p>Instead one can do:</p>
<p></p>
<p><span style="color:#006000">>>> q.modify_units('ft')</span></p>
<p></p>
<p>or</p>
<p></p>
<p><span style="color:#006000">>>> q.modify_units(quantities.ft)</span></p>
<p></p>
<p>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:</p>
<p></p>
<p><span style="color:#006000">>>> quantities.Quantity(19,'compound("parsec/cm^3")*compound("J")')</span></p>
<p><span style="color:#006000">Quantity(19), (parsec/cm**3) * (J)</span></p>
<p></p>
<p>or:</p>
<p></p>
<p><span style="color:#006000">>>> q=quantities.Quantity(19,'compound("parsec/cm^3")*compound("m^3/m^2")')</span></p>
<p></p>
<p>or:</p>
<p></p>
<p><span style="color:#006000">>>> q=19*quantities.compound("parsec/cm^3")*quantities.compound("m^3/m^2")</span></p>
<p><span style="color:#006000">>>> q</span></p>
<p>Quantity(19.0), (m^3/m^2) * (parsec/cm^3)</p>
<p></p>
<p>and there is a mechanism to force compound units to be decomposed:</p>
<p></p>
<p><span style="color:#006000">>>> q.reduce_units()</span></p>
<p><span style="color:#006000">>>> q</span></p>
<p>Quantity(5.8627881999999992e+23), 1 / m</p>
<p></p>
<p>or they can be recomposed:</p>
<p></p>
<p><span style="color:#006000">>>> q.units=quantities.compound("parsec/cm^3")*quantities.compound("m^3/m^2")</span></p>
<p><span style="color:#006000">>>> q</span></p>
<p>Quantity(19.000000000000004), (m^3/m^2) * (parsec/cm^3)</p>
<p></p>
<p>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.</p>
<p></p>
<p>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.</p>
<p></p>
<p>Darren</p>
<p></p>
</body></html>