-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
Document how to find earliest and latest sunrise and sunset #980
Comments
Happily, you don't need any special routines to find the answer in Python to a question like "what's the biggest number in this list?" or "what's the smallest number?" You can just ask NumPy where the biggest or smallest element is, and it will tell you. You can ignore things like It's important not to compare dates, because of course the "least" date in the list of sunrises will be the one on January 1, and the "maximum" will be the sunrise on December 31. Instead, you want to compare times. Happily, the Python datetime object has a You could almost do something like this:
Simple enough, right? Generate the list of sunrises as shown in the Skyfield docs, then ask which one is latest — that is, ask which sunrise has the maximum time-of-day compared to the others. The problem is, it gives the wrong answer.
It says the maximum-timed = latest-timed sunrise is on November 2, which is nonsense. What's going wrong? As always, a graph should make things clear.
Which generates: It very nearly looks like a graph of sunrise times: around 8 AM in the middle of winter at the beginning of the graph, then almost at 6 AM by the middle of summer in the middle, then later again through the autumn and into winter. (Remember that this graph goes from January to December, because its 365-day x-axis is simply the days of the year.) The problem, obviously, is Daylight Savings Time. Twice a year, it messes up the graph with a sharp spike, once when clocks "spring forward", and once when they "fall back". And just before they "fall back" in November, the DST scheme allows a sunrise that's so late in the day — at 8:08 AM, as we saw in the printout above — that it beats all of the mid-winter sunsets by being later in the day than any of them. So, I guess this answer is accurate if you really mean to ask, "which sunrise occurs when my clock says the latest time?" But usually when people ask about the "latest sunrise", they mean relative to Standard Time, not DST. Happily,
The output indeed names a plausible date for latest-sunrise:
So, to summarize: finding the biggest or smallest item in a list is easy in Python, either by writing a little loop yourself that remembers the smallest or biggest item so far, or by calling a pre-written loop of the same sort like Try this out yourself, and see if it works! |
Thanks for your response. Your example code is about the same as what I did. I asked about find_maxima and find_minima mainly because of bad performance of my code.
Remains the observation that I still don't know how to use find_minima and find_maxima. But I've to find a use case for that first. |
I am glad you figured out how to speed up your code, and that you understand now why those two routines won't help you find an earliest or latest sunrise or sunset. I think I should add this example to the Skyfield "examples" docs, since getting a good answer turned out to be a bit more subtle than I expected. I've tagged this issue a "documentation request", and I'll close it once I get my discussion above pasted over into the docs somewhere. |
I'm glad to know that this question serves a certain purpose and that it does not end up as a waste of time. In the meantime I continued programming and I found out that a lot of things can be calculated using plain Python or the find_discrete routine. |
Oh, yes, good idea — those routines would be perfect for finding the moments when the planet turns around at each end of its retrograde loop. I would have thought that there would be a great technical term for those moments, but looking at Guy Ottewell's Astronomical Calendar, which always gives the dates of those events, I see that they are simply described using words — "stationary in longitude" and "stationary in right ascension": (This is from the 2001 edition.) Maybe I should someday think of adding routines for this to Skyfield's |
I don't know if this is the right place to ask this question, however I'm not aware of a better place. If this is not supposed to be here I apologize in advance.
I'm currently trying to integrate the marvels of the universe into my home automation system. Mostly because it is fun and I want to improve my coding skills.
I managed to integrate the more common events like risings and settings of objects and the things described in the more well documented features of Skyfield.
Now I'm trying to calculate less common things and I'm stuck.
For example: I want to figure out the most early and most late occurring times (and dates) of sunrise and sunset in the course of a year. I can do the calculation using the almanac.find_risings and almanac.find_settings routines and iterating over it using regular Python. But I want to know if it is faster to use find_minima and find_maxima.
Somehow I simply don't understand how to do it. The documentation about these functions is not very helpful, because it is mostly about finding elongations. As a matter of fact I haven't been able to find an example on the Internet that is not related to finding elongations.
I even tried a session with an AI-digital assistant which produced multiple versions of a script and each of them failing because of problems, mostly related to errors in the time(s) provided to the script.
Interestingly, I do know how to perform calculations using find_discrete, but apparently using find_minima and find_maxima is more complicated.
So, yes, I have to admit I can't figure this out on my own and a bit of help is very welcome.
The text was updated successfully, but these errors were encountered: