Repository navigation
Constants - #21
Constants#21
Conversation
|
Hello, I have just a few comments; the full code is at https://github.com/phn/astropy/blob/constants-test/astropy/constants/__init__.py . At some point it will be useful to know the source of constants. For example CODATA or Particle Data Group's compilation or from astronomy references. I thought perhaps we can have a simple number like constants that carry such information with it. I came up with this simple sub-class of namedtuple, that will act like a constant number but with fields carrying meta-data. The number like behavior is obtained by simply adding methods such as The definition of a constant looks like this: The _refs dictionary stores the references. One can do computations, for example, Is this an over-kill? I think that as we add more astronomy constants, the references will become very important. I believe that one of the reasons the IAU has discontinued(?) issuing constants is because there are many reference to choose the values from, and the one to use is not obvious. For example, distance of Sun from the Galactic center. Even conversion methods can be added that can be used, for example, or even, The conversion factors can be stored, at the module level, as nested dictionaries, with physical quantity as the main key. For example, Users can access these conversion factor directly or as methods of constants. Thanks, |
|
The pull request looks good, except for one thing: |
|
Oh, and my preference would be to have all the variables not have underscores, so as not to appear like fnctions (although that's mostly an opinion thing). Also, while technically they should all be capitalized because they're constants, I think here we break that rule, because there are clear conventions for capitalizations that are used when these constants are actually written down, and it would be too confusing to a lot of people to violate those conventions. (To be clear, you've already done that, but I see that Prasanth's version instead uses all caps in some places.) |
|
Prasanth, First of all, your approach here is quite clever... and not necessarily overkill, but perhaps premature. The main reason why I say that is that there is a At the astropy meeting it was a more-or-less unanimous agreement that the interim solution would be to use this approach where the constants are stored in the typical unit systems that are encountered, at least until the units system is worked out. That way, when someone imports units and types On the other hand, I definitely like the way the approach you've described here stores the reference information and extra notes, though - you're definitely right that it would be good to keep that available programmatically. One possible approach might be to use your class as you've defined it to store the information, but remove the units part for now (until the larger unit scheme is worked out) and define the constants in the si.py and cgs.py scheme as Thomas has done. If you want to try this, I recommend creating your own pull request with the understanding that we will merge either this one or that one once we decide which is best. Also, we definitely don't want to include all the parameters for solar system objects in the A few stylistic comment's I'd like to add about your branch though (mostly for your information):
|
|
Hello, Thanks for all the comments. My idea of a The current version was a personal project to collect astronomical quantities, and hence the information on physical properties of planets. The orbits of planets would, of-course, be part of say, the coordinates module. But the orbital period of Jupiter, as specified by the Solar System Dynamics group, can be in As an interim solution the current idea of splitting constants into cgs and si is the way to go. But in the "long term", we may run into problems, where the split may not be obvious: is the magnitude system cgs? Here also, I am assuming that the constants module will have quantities such as say, the magnitude of Vega in the Johnson filter, or the B-V color of Sun, or perhaps even the current estimates of the solar abundances according to paper X. If such quantities are deemed not to be included in constants, then of-course the current split is more appropriate. I will start a branch in my fork, with my version of the For the naming scheme, I am for using underscores, since they make it easier to read the name. Also, is Since we are still in the exploration stage, I will get started with a reasonably consistent naming scheme, and then we can make changes. So I will start with The branch was named "constants-test" specifically because it doesn't follow most of the AstroPy coding conventions! Thanks for pointing out the usage of Thanks, |
|
Ah, now that I see what you had in mind I understand your implementation better. I see your point that it makes sense to have a unified object to store this information (including reference info and the like). So while the class is a good idea, and we should probably encourage its use if we end up adopting this solution, my main point was that many of these quantities themselves should actually be defined in whatever module is most appropriate to them. Things like e.g. magnitude of Vega do not belong in |
|
Oh, and
|
|
Erik, I'm not sure I understand your first comment about the imports in |
|
I do like the idea of keeping some metadata in the constants, and have a few comments about that:
|
|
Sorry, you're absolutely right - I saw what you wrote and somehow mentally assigned Also, a suggestion for the """
The constants module stores physical and astronomical constants.
These constants are currently accessible in two unit systms: cgs or SI.
These are stored as submodules (`~astropy.constants.cgs` and
`~astropy.constants.si`) of the constants module. Thus, the constants should
be accessed as e.g. ``from constants.cgs import c`` or
``from constants.cgs import c``
Notes
--------
Many of these constants make use of the 2010 CODATA recommended values [cod]_ .
References
----------------
.. [cod] http://www.codata.org/
""" |
|
Thanks for the docstring! I'll include that. What should we do for now regarding classes - should we use floats, a 'thin' wrapper around floats like what I showed above, or a more complete class like what Prasanth is suggesting? |
|
Perhaps you can try doing the thin wrapper approach? I think that seems a bit cleaner to me, but it sounds like Prasanth is going to change his approach based on the above comments, and we can just see which seems to work better? |
|
Hello, As both of you say, the simplest thing to do right now is to have two separate modules with SI and CGS values. In fact, we should just stick to a simple list of constants as Tom has done now. I accept that as an interim solution, since we don't have a consistent way of working with units. And additionally many of the "constants" can be defined in separate modules like time, coords, photometry, and then simply have references to them in the In a module it will be easier to see which system is being used by looking at the import line, but this will be hard while working at the terminal. So in my opinion having classes, with built-in conversions, will be more appropriate in the long term than having separate modules. We could store instances of classes, with the appropriate units and values, in the submodules constants.si and constants.cgs, to maintain backward compatibility. Also, we can import the one we want without having to perform an additional conversion step. My point in asking about Within the two module scheme, I am for storing reference values in constants.si and then performing the conversion in constants.cgs. I went with namedtuples because that was the first thing that came to mind: constants => immutable => tuple! For me, most of these are issues that can be settled one way or the other; I can live with either one. But there may be users, even if they are not developers, who may have strong opinions on these. Prasanth |
|
I only just noticed this pull request and the ensuing discussion. I don't have too much more to add at the moment other than a +1 for using a wrapper approach. It doesn't necessarily need to be limited to floats either, though I'm not sure I can think of any examples where a float wouldn't be the most appropriate type anyways. |
|
Before I modify the pull request to include the thin wrapper we are talking about, I just wanted to mention the scipy constants module: http://docs.scipy.org/doc/scipy/reference/constants.html - do we want to repeat constants that are already in scipy? do we want to use a system that is the same as theirs? |
|
I think If we plan to implement the thin wrapper with source information, it makes sense to do it all internally consistently and not use the scipy constants module, given that some of those values don't have source information. Also, given that we are not requiring scipy, it might be useful to include them here on their own. Also, a lot of the constants in the scipy module aren't relevant to astronomy... although it certainly makes sense to have a Oh, but we probably should use t |
|
About distributing constants of some sort throughout |
|
I've implemented the We can still discuss things like capitalization, underscores, etc., but otherwise are you happy with this system? |
|
Also, once we have a proper units module in Astropy, we can add a |
|
Also, here's a dilemma: is 'e' the electron charge, or |
|
Why do we need |
|
@astrofrog - I would say add 'dumb' units now, as long as it won't take too much time - but make sure to put a disclaimer in the docstring that this is for informational purposes and will be changed in the future. @hamogu - That's a good point... I was thinking people might expect pi, in particular, to be in a |
|
Oh, and maybe Also, one extra suggestion: we should set a scheme that automatically adds a last of the constants into the docstring, so we don't have to rely on people updating the docs whenever they add a new constant. (I can do this later if you'd rather not do it now, though.) |
|
@eteq - I guess adding dumb units is fine because if someone does c in cgs times k in SI for example, it will give a float anyway, not a Constant that would need to figure out units. So it's up to the user to figure out the units of the result. I'll get rid of system too, since in some cases it doesn't even apply (e.g. Avogadro's number). Also agree about getting rid of pi! |
|
@hamogu - I agree that might be a good approach, but until the unit scheme is implemented, I don't think we want to guarantee that this will be the case, given that the design might end up putting this information somewhere else. In that case, we certainly don't want two (potentially) different values of That is, you're probably right if its better that they stay there, but I'm just suggesting we warn anyone who's going to use this that it might change when the units are implemented. |
|
@eteq - I don't want all values in this file, I just suggest that they can be referenced via In the same way That said, there is nothing wrong with a disclaimer at this stage. Also there might be good reasons not to have |
|
@hamogu - I agree this is a very reasonable scheme (although with the caveat that it's actually |
|
Alternatively, cgs.au can remain a constant (which it is) and be used by the unit conversion system? Even when the units system is implemented, it will still be true that cgs.au is a constant in cgs units :-) |
|
You could argue that M_sun, M_earth etc. are units too and if you check, that's basically all of the 'astronomical' constants. I'd suggest that we keep these and au, kpc, pc, etc. in this module though, and have the units module use these values if necessary. Anyway, I guess this is something that can be decided later, and I would be for just putting a deprecation warning if things do change (not pre-emptively, in case we don't actually deprecate them in the end). |
|
Last comment - the nice thing about keeping au, kpc, M_sun, etc. in constants is that with this object we can keep track of the origin of the values (because there are many definitions of these values, and origin is really important). |
|
Right, I was just think it might be that the |
There was a problem hiding this comment.
I think this should be 7.1492e7, as your units are in meters ... I'm fairly sure Jupiter is more than 71 km in radius :)
There was a problem hiding this comment.
Thanks for spotting this! Fixed.
There was a problem hiding this comment.
Hello,
Should't we leave the uncertainty to None or Exact in cases where we
don't have a value? This makes it explicit that the reference for the
quantity did not list a value for its uncertainty or it is an exact
quantity.
Prasanth
On Thu, Oct 27, 2011 at 5:48 AM, Thomas Robitaille <
[email protected]>wrote:
+# Solar radius
+R_sun = Constant(6.95508e8, 0.00026e8,
"Solar radius","Allen's Astrophysical Quantities 4th Ed.", 'm')+# OTHER SOLAR SYSTEM QUANTITIES
+
+# Jupiter mass
+M_jup = Constant(1.8987e27, 0.,"Jupiter mass","Allen's Astrophysical Quantities 4th Ed.", 'kg')+# Jupiter equatorial radius
+R_jup = Constant(7.1492e4, 0.,Thanks for spotting this! Fixed.
Reply to this email directly or view it on GitHub:
https://github.com/astropy/astropy/pull/21/files#r193569
|
I just checked over all the Allen's values and saw two (related) typos that I commented on inline. One final thought: For all the values that currently have errors of "0", perhaps the errors should be changed to .5 of the last significant digit? e.g. if the value is "1.8987e27", perhaps the error should be "0.00005e27" ? |
…ficant digit (except for the speed of light).
|
Thanks for the comments - I fixed the units as @hamogu pointed out, I changed the Stefan-Boltzmann constant to |
|
Looks good to me as it stands. @phn - were you planning on implementing something in a branch of your own still, or should we go ahead and merge this? |
|
Hello, @phn - were you planning on implementing something in a branch of your own
Prasanth |
|
@phn - sorry, didn't see your earlier comment until now: I don't think I'm going to merge this to make it easier for some upcoming work, but if you disagree with this approach still, feel free to continue commenting and @astrofrog or I can change it directly in master. |
|
Hello,
|
Fix tests on Numpy 1.4 and Python 3.x
implemed constants module
Fix tests on Numpy 1.4 and Python 3.x
Update doctests
Update from astropy
pytest 3 settings: use system pytest
Add "provisional" status for affiliated package
Note: this module is not ready for merging. I am opening this pull request so that we can review the current code and iterate on it first (with the ultimate goal of merging).
A few notes:
_for subscripts and to use lowercase and uppercase as is usually conventional - but we can also switch to all lowercase if you think that would be best