Open cousteaulecommandant opened 14 years ago
Attachment: trac_9763_add_metrology.patch.gz
Creates the metrology.py file, but doesn't edit the corresponding all.py
The metrology.py file itself, in case it's preferred
Attachment: metrology.py.gz
Example of usage, Pi theorem
Attachment: example_metrology.sage.gz
This needs more work as stated in the ticket description and seen by the fact that not all functions included have doctests.
I don't think it makes sense to have 2 different units modules. I suppose the goal here is to replace the existing one at some point. Is the functionality here a clear extension of the existing one? Is there anything that the current module does that this will not be able to do? (I never used the units module.)
Besides the questions of functionality, here are a few things I noticed when I read the patch:
Units
class should derive from SageObject
.U
to the top level namespace is appropriate. Users which need this functionality so often can define such a shortcut in their initialization file.Reviewer: Burcin Erocal
As burcin said, the idea was to have this as a replacement for the current units module, without removing the old one. (Another idea was to call it units2, but that looked kind of ugly)
Making Units
derive from SageObject
might be a good idea; however I didn't know much about Sage (nor do I now, actually) so I didn't consider this possibility. Maybe a Units ring could be made too.
The U()
function was called this way so one could create units conveniently, like
from metrology import U
length = U("1 m")
However, it's not necessary to have this function on the top level namespace, and Python guidelines usually suggest something like
import metrology
length = metrology.U("1 m")
As for advantages/disadvantages, well, I don't remember them all, but here's a rough list:
0 * 1m = 0 m
, not just 0
. Also, it's possible to convert from 0 degrees Celsius to Fahrenheit, which is impossible with the current units
module.Units
is a class written from scratch, with all operations (__add__()
, __mul__()
...) coded explicitly.units
module has a pretty nice documentation for each unit, not present in this module.(Apparently I forgot the space before each "*", resulting on a bad formatting. Since comments cannot be edited, I'll put the points again here for better readability)
Pros
0 * 1m = 0 m
, not just 0
. Also, it's possible to convert from 0 degrees Celsius to Fahrenheit, which is impossible with the current units
module.Cons
Units
is a class written from scratch, with all operations (__add__()
, __mul__()
...) coded explicitly.units
module has a pretty nice documentation for each unit, not present in this module.
This is a module that implements physical units in a more convenient way than the already existing units module: instead of creating separate variables for each unit, it creates an object containing the value, the dimension (mass, length, time...) as a list, and the units as an expression, plus the conversion factor.
It includes an easy-to-use function to create units from a string, implements
SI
prefixes and has a niceLaTeX
output.TO DO: Add more units (there are currently only 74, plus 13 constants), review the documentation and code in case it doesn't follow the Sage style, modify sage/symbolic/all.py to include this module (adding "import metrology" causes Sage to throw exceptions when starting).
CC: @kini
Component: symbolics
Keywords: units, SI, metrology
Author: Javier Mora
Reviewer: Burcin Erocal
Issue created by migration from https://trac.sagemath.org/ticket/9763