![](https://secure.gravatar.com/avatar/9c9772ac67c2ef57a0e03cf8fcd55bc9.jpg?s=120&d=mm&r=g)
Hi all, We have been using the units package written by Michael Aivaziz which is available here: http://www.cacr.caltech.edu/projects/pyre/ http://www.cacr.caltech.edu/projects/pyre/epydoc/public/pyre.units-module.ht... One potential issue is that a units package has to guess whether the user wants to convert a temperature gradient or a temperature: 1Celsius = 1Kelvin (gradient) 1Celsius = 274.15Kelvin (absolute) For a proprietary project Enthought reworked Michael's package to assume temperatures are absolute. This is maybe less surprising to a regular user but was tantamount to forking Michael's project. It also leaves the inherent ambiguity unresolved. If we put Mike's work into scipy we would probably want to use it unchanged. So my questions are: 1) any interest out there in us putting a units package into scipy? 2) any preference for a particular implementation? Unum, etc. 3) does anyone have input or suggestions regarding the temperature issue? Thanks, Duncan
![](https://secure.gravatar.com/avatar/3a6c2451f75d3309b1252476a8f6a4a6.jpg?s=120&d=mm&r=g)
Duncan Child wrote:
One potential issue is that a units package has to guess whether the user wants to convert a temperature gradient or a temperature: ---snip--- 3) does anyone have input or suggestions regarding the temperature issue?
One thing I'd like to point out is that this is not specific to temperature. Whenever two unit systems have different origins, the unit framework will have to distinguish between differences and positions. (Alternatively, the framework can handle all positional measurements as (X - X_0), and use one general-case transformation.) In general, operators are not unit preserving; it's just that we intuitively expect addition/subtraction to be better behaved than multiplication. Off the top of my head, time measurement also suffers this problem. I'm sure there are others (although they're probably obscure). -Peter
![](https://secure.gravatar.com/avatar/5a7d8a4d756bb1f1b2ea729a7e5dcbce.jpg?s=120&d=mm&r=g)
Duncan Child wrote:
Hi all,
We have been using the units package written by Michael Aivaziz which is available here:
http://www.cacr.caltech.edu/projects/pyre/ http://www.cacr.caltech.edu/projects/pyre/epydoc/public/pyre.units-module.ht...
One potential issue is that a units package has to guess whether the user wants to convert a temperature gradient or a temperature:
1Celsius = 1Kelvin (gradient) 1Celsius = 274.15Kelvin (absolute)
For a proprietary project Enthought reworked Michael's package to assume temperatures are absolute. This is maybe less surprising to a regular user but was tantamount to forking Michael's project. It also leaves the inherent ambiguity unresolved. If we put Mike's work into scipy we would probably want to use it unchanged.
So my questions are:
1) any interest out there in us putting a units package into scipy?
Yes. Note that Scientific (Konrad's) also has units support. I just mention it for reference, I can't say anything in terms of comparisons.
3) does anyone have input or suggestions regarding the temperature issue?
Putting my physicist hat on, I'd strongly argue for simply saying that temperatures are temperatures, period. If you need to convert temperature _differences_ (gradients), you should explicitly say so. It's OK for a package to provide utility functions to do this conveniently, if it's a frequent need. But the concept of temperature should be unchanged: T_celsius = T_kelvin - 274.15 This formula implicitly encapsulates the fact that delta_t_celsius == delta_t_kelvin, but it's the only formula with basic physical meaning. The relative size of the unit steps is a simple consequence of this formula. And I think that good scientific libraries should encode, when possible, the more basic concepts, while providing whichever higher-level utility functions are deemed necessary. Just my $.02 Best, f
![](https://secure.gravatar.com/avatar/5c85708f2eed0869671a7d303ca55b85.jpg?s=120&d=mm&r=g)
Fernando Perez <Fernando.Perez@colorado.edu> writes:
Putting my physicist hat on, I'd strongly argue for simply saying that temperatures are temperatures, period. If you need to convert temperature _differences_ (gradients), you should explicitly say so. It's OK for a package to provide utility functions to do this conveniently, if it's a frequent need. But the concept of temperature should be unchanged:
T_celsius = T_kelvin - 274.15
Maybe you'd better check the fit of that physicist's hat ;-) -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke http://arbutus.physics.mcmaster.ca/dmc/ |cookedm@physics.mcmaster.ca
![](https://secure.gravatar.com/avatar/5a7d8a4d756bb1f1b2ea729a7e5dcbce.jpg?s=120&d=mm&r=g)
David M. Cooke wrote:
Fernando Perez <Fernando.Perez@colorado.edu> writes:
Putting my physicist hat on, I'd strongly argue for simply saying that temperatures are temperatures, period. If you need to convert temperature _differences_ (gradients), you should explicitly say so. It's OK for a package to provide utility functions to do this conveniently, if it's a frequent need. But the concept of temperature should be unchanged:
T_celsius = T_kelvin - 274.15
Maybe you'd better check the fit of that physicist's hat ;-)
Sorry, it's 273.15, I didn't actually look it up, I just used the value given by the OP. Best, f
![](https://secure.gravatar.com/avatar/ec366db3649cf13f4061b519193849d6.jpg?s=120&d=mm&r=g)
Duncan Child wrote:
1) any interest out there in us putting a units package into scipy?
Sure, but not any of the current ones.
2) any preference for a particular implementation? Unum, etc.
Unum is GPL. I don't think any of the current offerings (Unum, ScientificPython's PhysicalQuantities, and pyre.units) do particularly well with this issue, although, as I note below, PhysicalQuantities gets closest.
3) does anyone have input or suggestions regarding the temperature issue?
Personally: computing absolute "degrees Fahrenheit" from absolute "degrees Celsius" is not a unit conversion; it is a calculation built on top of unit conversions. Converting "feet" from "meters" is a unit conversion. Computing "feet from my house" from "meters from the North Pole" is a calculation. I think that it is unwise to expect a unit conversion system to handle such a computation the same way it handles everything else. That said, ScientificPython hacks around this creditably: "K" and "degR" are both the absolute (referenced to absolute zero) and the differential units. "degC" and "degF" are the absolute units referenced to their respective zeros. It's limited, though. You can't add a "degR" differential temperature to a "degC" absolute temperature, but you can add a "K" differential temperature. You can add "degC" to a "degC", but that's inconsistent. Frink[1], which I hold as the gold standard for computer unit conversions (and whose "Sample Calculations"[2] ought to be repeated for any proposed unit package), sorta gets this right. Celsius[x] and Fahrenheit[x] are functions that go back and forth between systems. Give them an unadorned number, they'll interpret as, e.g. "10 degrees Celsius", and convert to absolute Kelvin. Give it an absolute temperature (in Kelvin or Rankine), and it will spit out the numerical value of the temperature in its own scale (although unadorned by any unit). "degC" and "degF" are the differential units. It would be useful to have a system that would handle the general case of referenced measurements like the Celsius and Fahrenheit scales and "meters from my house". The appropriate distinctions should be made when operations mix referenced measurements and "differential" quantities. Oh, and any system should yoink the contents of Frink's database. [1] http://futureboy.homeip.net/frinkdocs/ [2] http://futureboy.homeip.net/frinkdocs/#SampleCalculations -- Robert Kern rkern@ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter
![](https://secure.gravatar.com/avatar/ec366db3649cf13f4061b519193849d6.jpg?s=120&d=mm&r=g)
Duncan Child wrote:
3) does anyone have input or suggestions regarding the temperature issue?
I've thought about this a little more, and I would like to describe here an outline of the system that I would like to see with examples drawn from my current research. One of the many things that Konrad got right was the name: the system is dealing with physical quantities. The most general form would consist of "numerical quantities tagged by their measurement system." A large subset can be described as "numerical quantities with units." What we need is a system that can perform operations and conversions between measurement systems, some of which will be user-defined and arbitrarily complicated. The methods for dealing with the unit-subset are sufficiently covered by the currently available software. With the exception of certain, very standard conversions like temperature scales, most of the non-unit-subset must be user-defined. Allow me to describe some of the many measurement systems in my current project in more detail than you probably care; feel free to skip ahead. I am a geophysicist. I am modelling the distribution of slip over a fault surface during and after an earthquake. I am using measurements from a local GPS network and Interferometric Synthetic Aperture Radar (InSAR: I get images of the very small displacements from each pixel between two flyovers of a sattelite; it's kind of like having a very dense GPS network that doesn't get sampled very often). My measurement systems include: Location: * Latitude and longitude of various entities: GPS stations, corners of fault patches, the corners of my InSAR images * Local northings, eastings, up (essentially the meters north, east, and up from a given local reference point) * X, Y, Z referenced to the fault geometry * Pixels in the InSAR images * Distance along-slip and along-dip on the fault (a location on the plane of the fault place itself) Displacements: * Differential ground displacements of the GPS given a reference station * Differential ground displacements from the InSAR images given a reference pixel projected onto the line of sight of the satellite * Absolute ground displacements given a slip model Time: * GPS time: seconds from an arbitrary start point, no leap seconds * Satellite time: seconds from Jan 1 00:00 of the launch year of the satellite, no leap seconds * Calendrical time: leap seconds! Miscellaneous: * Slip, rake: magnitude and direction of the slip for each fault patch * Dip-slip, strike-slip: orthogonal slip components for each fault patch * Green functions: observable displacements (GPS and InSAR) as a function of slip across each fault patch * Smoothing kernel: for regularizing my inverse problem ... and probably some more. Now, I don't claim that even given my dream physical quantities system that I would commit all of these entities to it. Some, like time, are more suited to the strategy of converting everything as soon as it enters the picture. Others don't need conversions between different measurement systems. Skip to here if you are bored by geophysics. I have found that I have been duplicating snippets of code, throwing around little one-to-one conversion functions, or worst, just not bothering with some task because it's too annoying to switch between these systems. Here is my sketch of a physical quantities system: Each quantity has a value, which can be anything reasonably number-like, and measurement system, which probably should be a full-fledged object, but perhaps could also be a string for standard shortcuts. In[1]: x = quantity(10.5, apples) In[2]: y = quantity(12, oranges) There will exist a function for converting quantities from one system to another. In[3]: z = convert(x, oranges) In the case of real, honest-to-goodness units like "m" and "degC" (the differential kind, not absolute systems, not even Kelvin or Rankine), converting falls down to the well-known algorithms. Failing that, convert() will look for an appropriate conversion path from all of the measurement system objects registered with it. This lookup algorithm can be stolen from PyProtocols[1]. Operations that can be performed on quantities of a given measurement system will be defined by the measurement system object. For example, quantities in the (lat, lon) system can be converted to (northings, eastings). To a (lat, lon) quantity, I can add or subtract a unitted quantity of dimensions (length, length). I cannot add another (lat, lon) quantity, but I can subtract it yielding a (length, length), which, given a suitable context, can be converted to (range, azimuth). Multiplication does not make sense, nor does division, but trigonometric functions might depending on your use cases. Of course, temperature scales fit neatly into this system. Since the "shift-scale-shift" type of conversion happens reasonably often, a bit of general-purpose scaffolding can be constructed for it and which the temperature scales can use. [1] http://peak.telecommunity.com/PyProtocols.html -- Robert Kern rkern@ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter
![](https://secure.gravatar.com/avatar/59788df19fe06d80fe6122d964a90d46.jpg?s=120&d=mm&r=g)
Duncan Child wrote:
Hi all,
We have been using the units package written by Michael Aivaziz which is available here:
[...]
1) any interest out there in us putting a units package into scipy?
I've tried units packages in other systems. (notably Mathcad) After 30 minutes I abandon them. Much typing, little payback.
2) any preference for a particular implementation? Unum, etc. 3) does anyone have input or suggestions regarding the temperature issue?
This may be the same as the Scientific Python solution (which I don't quite understand): two units, degC and Cdeg. 100 degC = 373 K. 100 Cdeg = 100 Kdeg. The standard physics text Halliday, Resnick and Walker (and its offspring Cummings, et al) do it that way. -gary
Thanks,
Duncan
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.net http://www.scipy.net/mailman/listinfo/scipy-user
![](https://secure.gravatar.com/avatar/9c9772ac67c2ef57a0e03cf8fcd55bc9.jpg?s=120&d=mm&r=g)
Hi all, After reading all the emails I think the problem splits down like this: 1) Algebra of Units It feels like you should be able to divide a distance by a time and get a velocity. If you then try and add a velocity to a temperature you should get an error. This may be what Gary had in mind when he said "I've tried units packages in other systems. (notably Mathcad) After 30 minutes I abandon them. Much typing, little payback." 2) Quantities (Robert's "numerical quantities tagged with their unit system") This is what I need to provide to scientists who are developing libraries of geophysical algorithms. They know what units they expect eg their algoritm needs a velocity in m/s. As long as I can tag the data that flows through the system with a description of what it's units are then I can add a 'shim' that will do the necessary unit conversions. The problem is that some of the units packages are targetted towards 'units algebra' and then punt on issues like temperature gradients which makes it hard for me to tag all the quantities. In fact, I would almost be better off passing around a string because that would at least allow me to hack around the special cases in my 'shim' code. 3) Map Projections Describing lat lon data is harder because if you don't also specify the datum (effectively where you are assuming the center of the Earth is) your position can be miscontrued by 100s of meters. To convert from lat lon to xy you have to specify a bunch of parameters so this is trickier than converting something like meters to km. So I am not sure where this type of data fits in relation to the more usual conversions. Summary: 1) no one has suggested a better approach than than the one we are already using for Quantities 2) Enthought has not overlooked a clearly superior implementation of a units package that we could include in SciPy 3) Frink is indeed very cool. 4) POSC has a fairly complete database of units http://www.posc.org/UConvert Regards, Duncan
![](https://secure.gravatar.com/avatar/ec366db3649cf13f4061b519193849d6.jpg?s=120&d=mm&r=g)
Duncan Child wrote:
3) Map Projections
Describing lat lon data is harder because if you don't also specify the datum (effectively where you are assuming the center of the Earth is) your position can be miscontrued by 100s of meters. To convert from lat lon to xy you have to specify a bunch of parameters so this is trickier than converting something like meters to km. So I am not sure where this type of data fits in relation to the more usual conversions.
It's just an example of the most general kind of conversions: ones that you have to code yourself. You would have two measurement systems reified as smart objects, not just dumb tags. You can parameterize all you like. class LatLon(MeasurementSystem): ... latlon = LatLon() class MapProjection(MeasurementSystem): ... class DatumShifted(MapProjection): def __init__(self, datum): ... nad83 = DatumShifted('NAD83') nad27 = DatumShifted('NAD27') x1 = quantity([35.94, -120.43], latlon) x2 = quantity([35.31, -120.66], latlon) y1 = convert(x2, nad83) y2 = convert(x2, nad83) In short, it's the same code you'd have to write anyways (and, in fact, I've already written), but it fits into a framework that reduces the amount of *interfaces* I have to write and think about and litter around my code. And with DatumShifted suitably implemented, you could do y2 - y1 and get quantity([-69880.73534289,-20899.29905468], meters) -- Robert Kern rkern@ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter
participants (6)
-
cookedm@physics.mcmaster.ca
-
Duncan Child
-
Fernando Perez
-
Gary
-
Peter Wang
-
Robert Kern