Repository navigation
Possible implementation of constants as quantities - #529
Conversation
…tDefinition intermediate class to store constants and meta-data.
|
The approach is definitely very promising! Is it necessary that the actual definitions live in I think you can preserve basically all the code with a scheme, but give it a slightly cleaner file/package organization. |
|
@eteq - ah, good point, I hadn't thought of doing it that way, I agree it would be less confusing to have a hidden |
|
@eteq - I've implemented your suggestion. I think it helped clean things up conceptually. I still need to fix things like docstrings, docs, tests, etc. but I'll wait until I know whether people are happy going this way. |
|
This looks like a good approach. One minor suggestion -- it's probably entirely obvious to us, but to avoid confusion for those coming fresh to this it might be helpful to add the following comment to all of the mostly empty modules in |
|
I see a possibility for user confusion here: Maybe we should override the to the bottom of the conversion loop seems to work. Also, it seems there is no automatic way to get |
There was a problem hiding this comment.
Should these things injected into the locals() namespace also be added to __all__? (I'm not certain they should: I just don't want to miss it if so).
There was a problem hiding this comment.
I think not because there's no __all__ in this module. However, @astrofrog, I think you want to move the del nm,val to after this for loop. And probably also change it to del nm, val, c to get rid of the intermediate variable.
|
@mdboom - thanks for reviewing this. I will think about the issue you raised (and will add the notes you suggested). In the mean time, how should we deal with si->cgs conversions for EM constants? (this is more of a question to do with Quantity than Units): should we hard-code the |
|
@mdboom - I'm going to reply to your comment on user confusion on the list, since this is something we were discussing there before, and the choice of having |
|
Maybe it's just me, but I guess I'm not clear on the need for the separate |
|
@iguananaut - first, regarding the |
|
Ah, okay. I didn't realize Constants were used to define some of the Units, but I guess that should have been obvious. Hmm--I feel like there should be a way around that. But this works fine for now so carry on :) Might be worth adding a note about that in the code--I know there was already a comment about circular dependencies, but I didn't get the full cycle of Constants are Quantities which have Units many of which are defined in terms of Constants. |
|
Inception! |
|
Just for info, I will have to wait until the weekend to implement the suggestions from here and the mailing list. But feel free to play around with the functionality in the mean time, to see if you can break it. |
|
Sounds good, @astrofrog, and thanks for working this out! (Also, I agree with @iguananaut that it'd be nice to get the slightly more informative |
|
Sorry, just catching up now... @astrofrog This idea looks good to me and thanks for figuring this out! |
|
Whoops sent that too soon -- I still think we should change all I also don't really like origin, and in my implementation changed it to |
|
@adrn - ok, will fix that. |
…el, but instead store Constant Quantity instances inside `si` and `cgs`. Updated tests.
|
@adrn - I changed @eteq and @iguananaut - I reinstated the @mdboom (and everyone else): I have now moved all constants into @mdboom and @iguananaut - I've added notes about the circular dependencies in all the relevant source files. Just noticed there is no documentation page for constants. I will open a separate issue for that (and assign it to myself) Shall we go ahead and review this for merging, and then if people have improved implementations later they can open a new PR? Has anyone had a chance to play with this? |
|
This seems to address all of my concerns. |
|
Looks good to me as well |
|
I will merge this later today if there are no objections. |
Possible implementation of constants as quantities
Possible implementation of constants as quantities
…ties Possible implementation of constants as quantities
Remove Médéric Boquien as requested
Ensure dropped world coordinates use correct values at slice, resolving inconsistencies when PC matrix couples sliced/kept dims. Regression test added for issue reported in astropy#529.
This is a possible implementation of the Constant class as a Quantity sub-class. This requires storing the constants in an intermediate
ConstantDefinitionclass that lives insideastropy.units. The non-quantity constants are still available. Example:This needs some tidying up, docs, and tests, but I won't do those until we know whether this is the approach we want to follow.