[SciPy-dev] design of a physical quantities package: seeking comments

Darren Dale dsdale24 at gmail.com
Sun Aug 3 12:54:12 EDT 2008


On Sunday 03 August 2008 11:35:47 am Jonathan Guyer wrote:
> On Aug 3, 2008, at 9:22 AM, Darren Dale wrote:
> >> More, what happens when you have a quantity in Newton-metres (say)
> >> and
> >> you ask it to convert to feet? Do you get Newton-feet, or do all the
> >> occurrences of "feet" in the Newtons get converted?
> >
> > They all get converted.
>
> I'm with Anne. I'm having a really hard time seeing when I would want
> this as a default behavior, whereas I frequently want to be able
> automatically convert BTUs to Joules and atmospheres to Pascals, but I
> want an exception if somebody tries to give me a pressure when I ask
> for an energy. Having it possible to do what you suggest seems like it
> might be useful sometimes, but I don't think it should be the default
> behavior.

[...]

> Using this scheme:
>  >>> from fipy import PhysicalField
>  >>> PhysicalField("12 lyr/cm**3")
>
> PhysicalField(12.0,'lyr/cm**3')
>
>  >>> PhysicalField("1 lyr") / "7.3 cm**2"
>
> PhysicalField(0.13698630136986301,'lyr/cm**2')
>
>  >>> PhysicalField("12 lyr/cm**3").inUnitsOf("m**-2")
>
> PhysicalField(1.1352876567096959e+23,'1/m**2')
>
> so the compound unit that Anne wants is supported and conversion to
> canonical units happens only when requested.

But in the meantime, you aggregate units like 
"dynes kg ft m^3 s / lbs Km ps^4 watts ohms". Quick, what units should I ask 
for that won't yield an error? It seems like it is more helpful to reduce as 
you go, and later when you want your value expressed with a compound unit, 
you ask for it. Let me try it my way and see what you think, and if people 
are not sold, it should be simple to reimplement so all units are aggregated, 
and reduced only on request.

Darren



More information about the SciPy-Dev mailing list