Re: About the next version of DateTme::Event::Sunrise

2020-06-20 Thread Troy Davis
Best thread on this list in quite a while, thank you so much, both Jean and 
Eric.

I’m interested to see any info you could provide on the decision-making and 
resulting mplementation!

Thank You,
Troy

> On Jun 20, 2020, at 11:27 PM, Eric Jensen  wrote:
> 
> 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 

Re: About the next version of DateTme::Event::Sunrise

2020-06-20 Thread Eric Jensen
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 

Re: About the next version of DateTme::Event::Sunrise

2020-06-20 Thread Bill Ricker
> PPS - I generally use the U. S. Naval Observatory for the reference value
> for this sort of thing. It's more "official" than Stellarium, but that's
> not the same thing as authoritative. - TW
>

USNO is the official authority for such in the US. Only the Greenwich
Observatory might be considered a higher authority.  Alas their website is
kind of wonky today, which is ironic since it's Solstice.


-- 
Bill Ricker
[email protected]
https://www.linkedin.com/in/n1vux


Re: About the next version of DateTme::Event::Sunrise

2020-06-20 Thread Thomas (HFM) Wyant
PS - Are you testing your sunrise predictions throughout the year?

The actual solar day (the time from noon to noon) changes throughout the year. 
The Mean Solar Day (24 hours) is just the average. The relation between these 
is something called the Equation of Time. If it were me, I would test at the 
solstices (two of the four times every year when the equation of time is zero, 
but also when it changes the most rapidly), and in mid-November and 
mid-February, when it is largest (about 15 minutes).

Disclaimer: this is just a thought thrown up for consideration. It would have 
been more helpful if I had consulted the actual code. This is laziness, but not 
in the Larry Wall sense of the word. Sorry.

Tom Wyant

PPS - I generally use the U. S. Naval Observatory for the reference value for 
this sort of thing. It's more "official" than Stellarium, but that's not the 
same thing as authoritative. - TW


Re: About the next version of DateTme::Event::Sunrise

2020-06-19 Thread Rick Measham
What if you implemented it as 'spin' or 'hour' or 'spin_hour' or 
whatever, as a number and (optionally) exported constants to signify the 
algorithm? That means users could either provide their own number, or 
could use one of the provided.


I don't write much perl any more so forgive me if I get the syntax wrong 
here ...



    use DateTime::Event::Sunrise qw/SIDEREAL SCHLYTER/;

    my $sunriseset = DateTime::Event::Sunrise->new(
 latitude  => 42.3358,
 longitude => -71.2044,
 altitude  => '-0.833',
 precise   => 1,
 hour  => SIDEREAL);


- Rick


On 6/20/2020 2:03 AM, Jean Forget 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/[email protected]/.

Jean Forget

--
Message  protected for iSite by MailGuard: e-mail anti-virus, anti-spam and 
content filtering.http://www.mailguard.com.au


Re: About the next version of DateTme::Event::Sunrise

2020-06-19 Thread Thomas (HFM) Wyant
Just to throw a monkey wrench into the works, they could also be 'sidereal' and 
'solar' (or mean solar), since 15 degrees is the rotation of the earth in one 
mean solar hour, and 15.04... is the rotation of the Earth in one sidereal 
hour. The terminology and length of a sidereal day are from Appendix I of Jean 
Meeus' Astronomical Algorithms, which I recommend, though it's not light 
reading.

Of course, this is Perl, and you could do both. Plus allow explicit 
user-specified values.

I have not looked into the actual algorithm, though I probably should. The 
Astro::Coord::ECI suite (disclaimer: I'm the author) gets almanac data by 
successive approximation.

While I'm disclaiming, I have no formal qualifications at all in computational 
astronomy. I remember vividly that my biggest problems implementing 
Astro::Coord::ECI::TLE (satellite position) were, simply stated, "Where am I?" 
and "What time is it?"

Tom Wyant