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
Add a function to calculate the solar eclipse amount for an observer #7142
Conversation
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.dates import DateFormatter
import astropy.units as u
from astropy.coordinates import EarthLocation
from astropy.time import Time
from sunpy.coordinates import sun
obstime = Time('2024-04-08 18:43') + np.arange(-100, 100) * u.min
observer = EarthLocation.from_geodetic(-96.808891*u.deg, 32.779167*u.deg).get_itrs(obstime)
amount = sun.eclipse_amount(observer)
plt.figure()
plt.plot(obstime.datetime64, amount)
plt.gca().xaxis.set_major_formatter(DateFormatter('%H:%M'))
plt.title('From Dallas on 2024 April 8')
plt.ylabel('Eclipse percentage')
plt.xlabel('UTC')
plt.grid()
plt.show() |
Want to make this an example gallery entry? 😁 |
It's already on the to-do list. =). Appropriately spiffed up, of course |
Accuracy looks excellent once I remember to use the JPL ephemeris rather than Astropy's built-in ephemeris |
examples/showcase/eclipse_amount.py
Outdated
# the array of observation times. | ||
|
||
location = EarthLocation.from_geodetic(-96.808891*u.deg, 32.779167*u.deg) | ||
observer = location.get_itrs(obstime) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhat off on a tangent, but can we pass EarthLocation
as an observer? i.e. skip this line. If not why not? 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because EarthLocation
doesn't include obstime
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drives the PR car off down another street
Couldn't we still do the conversion though? Wont most transforms pull the obstime from the frame if it's missing on the observer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're not looking at how the observer
variable is later used. Despite its name, it's not being used as the value for an observer
frame attribute. The function eclipse_amount()
takes a single argument, which is the coordinate of the observer including the obstime
. If the function were to accept EarthLocation
for the observer location, the function would need to additionally require the obstime
to be supplied as a second argument.
sunpy/coordinates/sun.py
Outdated
.. minigallery:: sunpy.coordinates.sun.eclipse_amount | ||
""" | ||
# The radius of the Moon to use | ||
k = 0.272281 if minimum else 0.2725076 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we not put this in constants somewhere rather than in here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And also define it better. It's not a radius but a fraction of Earth's radius.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's of course a dimensionless fraction, but it's also the value of the lunar radius in units of Earth radii.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know where to stick such constants, since we don't really have a home for non-Sun constants. I've tacked on a TODO comment, and someone in the future can figure it out.
I tested this code and it worked great. This is a cool example and this capability could be used for an update to NumFocus. To make it more relevant, how about choosing a point where both 2023 and 2024 eclipses pass and show both the total eclipse and annular eclipse curves on the same plot? |
831543e
to
acdc703
Compare
Okay, I've picked a location on the outskirts of San Antonio that is on both eclipse paths. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I've left a few comments 👍
dac22ab
to
57ce27b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should fix the test...
c4efd83
to
5ac2d71
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of very minor tweaks.
846b886
to
ac9e625
Compare
Go go solar eclipse!
Checking with other resources indicates that we can use our coordinates framework to calculate the start/end of total solar eclipses to within a few seconds.
To do:
get_body_heliographic_stonyhurst()
to silence the info message for the light-travel-time correction?