-
-
Notifications
You must be signed in to change notification settings - Fork 573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A more appropriate way to define moon_radius constants #7465
Conversation
Can you explain why the class is better? I guess I am left a bit confused as how it improves the code. |
I think it's more maintainable, as it makes it clear that these values are related and belong to a certain context. |
If you want to go this route, it should be a dictionary rather than a class. For example: radius_options = {
'IAU': 0.2725076,
'minimum': 0.272281
}
try:
R_moon = radius_options[moon_radius] * R_earth
except KeyError:
raise ValueError("The supported values for `moon_radius` are: " + ", ".join(radius_options.keys())) |
Albert, are these values not defined in astropy? And if not, should we upstream them there? Or even as sunpy constants? |
Hence the TODO that I wrote: The constants are not defined in astropy nor does it make sense to add them there. It's not clear it makes sense to add them to our constants. It's academic until some other code wants to use these constants. |
If we are going through the effort to tidy up how we present these numbers in the function, I do not see why we should go with the slight extra effort to define them formally as constants. |
It's not code effort, but rather design effort. These are constants that make sense only for solar eclipses, hence way too specialized to put into astropy. Our existing constants are specific to the Sun – we have |
Sounds good to me, let's do it. Could it be sunpy.constants.moon and sunpy.constants.sun? |
I think we should take a step back and ask ourselves if there is anywhere, in our existing codebase, besides this function, where these values would be useful. If the answer is no, I don't see the point in trying to expose them in some more formal way at this point. |
In that case, the dict that Albert posted should be the method we use instead of a class. |
Thanks for the PR @ahmedhosssam |
Hi,
In
sunpy/coordinates/sun.py
ineclipse_amount()
, I think that we could encapsulate the constants in aclass K
and initialize the value of k with K.IAU as a default, and then check if moon_radius is neither IAU nor minimum to throw an error.I think the code is more readable now.
Please let me know if there are any improvements needed.