[SciPy-user] module with physical constants
O'Keefe, Michael
Michael_OKeefe at nrel.gov
Wed May 31 11:29:15 EDT 2006
I'm happy to see a move towards a physical constants and units package. Just thought I'd mention that another source that may be worth noting/referencing for ideas is the SIUnits module in the Modelica language:
http://www.dynasim.se/ModelicaStandardLibrary/help/Modelica_SIunits.html#Modelica.SIunits
This is not python (in fact it's the Modelica language) but I think one can get some ideas for a python implementation from here.
-Michael
FYI. For those who want to reference, Modelica is at http://www.modelica.org
-----Original Message-----
From: scipy-user-bounces at scipy.net [mailto:scipy-user-bounces at scipy.net] On Behalf Of Travis N. Vaught
Sent: Wednesday, May 31, 2006 8:58
To: SciPy Users List
Subject: Re: [SciPy-user] module with physical constants
Darren Dale wrote:
> On Tuesday 30 May 2006 11:24 pm, Robert Kern wrote:
>
>> Travis Oliphant wrote:
>>
>>> weg werp wrote:
>>>
>>>> http://physics.nist.gov/cuu/Constants/
>>>>
>>>> combined with some other constans like conversion factors between
>>>> imperial and SI, lightyears, arcminutes etc. If everything is defined
>>>> in SI units, you could do tricks like
>>>>
>>>>
>>> >from constants import *
>>>
>>>> speed = 23454 * parsec / week # in m/s
>>>> print 'your are going',speed/Mach,'times the speed of sound.'
>>>> p = 18 * torr # in Pascal
>>>> print 'the pressure is', p/atm, 'atmosphere or', p/psi, 'pounds per
>>>> square inch'.
>>>>
>>> I like this style for doing unit conversions. I think keeping it
>>> simple as a module of float constants is a great idea.
>>>
>> I would prefer that the underlying database of constants and units is that
>> dictionary full of "ugly" names provided by Chuck so long ago. Among other
>> things, it's programmatically accessible. A more convenient set of variable
>> names can be glommed into a neighboring module that indexes into that
>> dictionary.
>>
>> And yes, I want the full set of CODATA Recommended Values.
>>
>> I do have reservations about such a thing becoming *the* scipy module for
>> doing unit conversions, though.
>>
>
> What if the constants were defined in SI, but let each constant derive from a
> class or classes with methods that take care of conversion to other unit
> systems. I was thinking of using gettable, but not settable, object
> properties like si, cgs, emperial... Maybe the module could even be designed
> such that the desired unit system is set as the default at module load time,
> so the user could do "c=lightspeed" instead of "c=lightspeed.cgs". This would
> still be compatible with further unit conversions, like "lightspeed/week".
>
> I remember trying to do conversion between electromagnetic units and SI, which
> I was never quite able to wrap my head around. It would really be nice to
> have unit conversion built in somehow.
>
> Darren
>
>
It seems like the real thrust of this thread is to have a simple
constants module(s), but the conversation has ballooned a bit into the
(valid) need for a full-blown unit package. This has been don before in
the Unum module mentioned as well as a units package (based on a fork of
Michael Aivazis's units package) included with the Enthought Tool Suite
('ETS' -- which some folks may be surprised they already have installed
if they're using a recent version of the Python Enthought Edition
distro). The ETS units package could still use some work in it's
handling of "unit families" (or 'measure-of') but it does provide all
the functionality you're mentioning (conversion, unit systems). It's
probably easier to show than to explain:
C:\>python
Python 2.3.5 - Enthought Edition 0.9.7 (#62, May 11 2005, 20:02:58) [MSC
v.1200
32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from enthought.units.mass import *
>>> from enthought.units.energy import *
>>> from enthought.units.speed import *
>>> mass = 1*kg
>>> mass
1.0*kg
>>> C = 299792458.0*meters_per_second # no constants included, (still
guessing the right numbers)
>>> C
299792458.0*m*s**-1
>>> E = mass*C**2
>>> E
89875517873681760.0*m**2*kg*s**-2
>>> joule # check to see if this is in Joules
1.0*m**2*kg*s**-2
These are obviously objects, though...
>>> E.__class__
<class 'enthought.units.unit.unit'>
...so you don't get the lightweight notion of simple floats assigned to
symbols in the namespace as Travis O. was saying. Which begs the
question of whether you really want the namespace mangling which comes
from a "from constants import *" If I understand it right, I think I
like Robert's dictionary idea.
Travis
_______________________________________________
SciPy-user mailing list
SciPy-user at scipy.net
http://www.scipy.net/mailman/listinfo/scipy-user
More information about the SciPy-User
mailing list