Hi Jean, As an astronomer, this message caught my eye, so I thought I’d make a few comments. Before I do, I want to say that (a) I appreciate people working on astronomical code, which can be tricky, and (b) my goal here is to be helpful rather than annoyingly pedantic. If I appear to fail at (b), I hope you’ll take it as a failure to convey the right tone by email rather than anything else. Some of the background below is likely to be things you already know, but I’m trying to be complete.
That said, I’d encourage you *not* to make the selection of this parameter a user choice, simply because it can’t be the case that both values are correct - so you’re putting the user in the position of trying to guess which is the right answer, which isn’t helpful to people who want to use your code. As you note, 15 degrees per hour (where “hour” here is a mean solar hour, i.e. the time we normally use) is the speed that the Earth rotates compared to the average position of the Sun. (The “mean Sun” is a convenient fictitious object that moves at a constant rate throughout the year, whereas the real Sun doesn’t, due to the Earth’s slightly elliptical orbit and tilted axis.) But that rate combines both the Earth’s rotation on its axis and its motion around the Sun - because it moves in its orbit each day, it has to rotate a little more than 360 degrees (relative to some distant reference frame) to get the Sun back to the same position in the sky. So the Earth’s rotation rate compared to a distant reference frame (e.g. the stars) is 15.04107 degrees per hour, so it rotates 360 degrees in 23 hours and 56 minutes (a “sidereal day”), and rotates about 361 degrees in a mean solar day (24 hours). (To easily derive that “magic value”, you can note that the Earth will have completed 365.25 rotations with respect to the Sun in one year, but one extra rotation with respect to the stars; the ratio 366.25/365.25 is the same as the ratio of your two factors.) So if you’re calculating the Sun’s position based on some coordinate system fixed to the (distant) sky rather than the Sun (which I assume must be what you’re doing), you need to use the Earth’s rotation speed compared to that coordinate system, which is the larger value (15.04107). The question still remains of why you’re getting different answers from different other codes you’re comparing to. While it’s possible that some are simply wrong, my best guess would be that some are taking into account refraction by the Earth’s atmosphere and some are not. Because the path of a light ray is bent as it travels through air, it turns out that when you see the bottom limb of the Sun touch the horizon, the whole Sun is already below the horizon! The exact amount of refraction depends on atmospheric pressure and temperature, but on average it’s about 0.6 degrees (which coincidentally is about the angular diameter of the Sun). That slightly more than half a degree translates to about two minutes of time, so if that’s about the difference you’re seeing, that could be the cause. The other reason could be different definitions of sunset, i.e. is it defined by when the top limb of the Sun is at the horizon? Or the center? Or is it some other distance below the horizon? (You list 0.833 degrees below, which is a combination of the average refraction and the Sun’s angular radius, i.e. it’s when the upper limb of the Sun would appear to go below the horizon, given average refraction.) But other other codes might make other assumptions that could lead to differences, i.e. they could be separately accounting for refraction on top of a specified angle of the Sun below the horizon. I suspect that I haven’t told you much (if anything!) that you didn’t know already, but maybe the background is useful for others reading the thread. But the bottom line is that again I encourage you to dig a little deeper to try to find the source of the differences rather than exposing this as a user choice. As for authoritative sources to compare to, as Bill Ricker notes, the USNO is generally my go-to source. Unfortunately, their website has been down for months as they reorganize, and unfortunately looks like it will still be a while. (https://datacenter.iers.org/data/2/message_400.txt - that’s about the IERS but the same is true for the astronomical parts of the USNO website.) So without access to USNO, I’d be inclined to compare to NOAA, who at least are clear on their website that they are including refraction - they say they assume 0.833 degrees of refraction, though as noted above I think of that value as including both 0.6 degrees of refraction *and* the angular radius of the Sun, so maybe there’s still a little ambiguity there. If you want to compare against a different Perl solution, in my own astro-related code I make use of Astro::Coords and Astro::Telescope, which depend on Astro::PAL, a Perl interface to a widely-used positional astronomy library. I’d be curious to hear what you find if you compare your code to those. (Or perhaps I can try to make a comparison later, but I need to go to bed now, and this message is too long already!) Hope some of this is at least a little helpful, and I’m curious to see where you end up - With best wishes, Eric > On Jun 19, 2020, at 12:03 PM, Jean Forget <j2n-for...@orange.fr> wrote: > > Following the creation of RT ticket > https://rt.cpan.org/Public/Bug/Display.html?id=132336 > I have decided to implement the proper precise algorithm in > DateTime::Event::Sunrise (already implemented in Astro::Sunrise) and > to check the values with NOAA's solar calculator and with Stellarium. > > After I have implemented the proper precise algorithm, there are still > differences between the values obtained by Stellarium and the NOAA on > one side and by DT::E::S on the other side. I have found that these > differences are the caused by the "magic" values 15 and 15.04107 used > in the module. > > 15.04107 is the angular speed of Earth's spin, while 15 is the > combination of Earth's spin with the orbital speed of the > Sun-Earth system. According to Paul Schlyter 's description of > the precise algorithm, we should use 15.04107, but I have found > that using 15 instead gives results closer to Stellarium. > > More abstractly, the problem is: when you are an low-level > amateur astronomer, who is an authoritative source for you? > Whom do you trust? Paul Schlyter or the Stellarium team or > the NOAA? > > I have decided to defer this question to the module user. There is a > new parameter, "algo", which lets the user choose between trusting > Paul Schlyter more than Stellarium or trusting Stellarium more > than Paul Schlyter. > > Now you may code either > > my $sunriseset = DateTime::Event::Sunrise->new( > latitude => 42.3358, > longitude => -71.2044, > altitude => '-0.833', > precise => 1, > algo => 'Schlyter'); > > or > > my $sunriseset = DateTime::Event::Sunrise->new( > latitude => 42.3358, > longitude => -71.2044, > altitude => '-0.833', > precise => 1, > algo => 'Stellarium'); > > Can you think of a better name for the new option? The creator of > ticket 132336 suggests > spin => 15.04107, > or > spin => 15, > > The problem is that the "magic" value 15.04107 is not easy to remember, > especially if the module user knows even less astronomy than myself. > While "Schlyter" and "Stellarium" are easier to remember. > > I will release the new version of DT::E::S to CPAN next week. > If you have a better idea for the name of the new parameter, please > tell me before this release. > > In the meantime, the updated code is available on Github. > > Thank you for your advice, > > By the way, this is the second attempt to write this message > to the datetime mailing list. As it happened already, my first > attempt was lost somewhere and did not reach you or the websites > https://www.nntp.perl.org/group/perl.datetime/ > and https://www.mail-archive.com/datetime@perl.org/. > > Jean Forget
smime.p7s
Description: S/MIME cryptographic signature