Page 1 of 1

Detecting daytime and nighttime

Posted: 11 Dec 2018, 16:51
by Forum_2017
Hello, I've been asked the simplest way to detect daytime and nighttime, for automatic research scripts.
Instead of looking at the current time, I think that it's better to check the altitude of the sun: when it's 15 degrees below the horizon then it's surely night.
A possible implementation would be: (remember to change the longitude/latitude of your observatory)

Code: Select all

myLon = 12  ' positive if East
myLat = 44  ' North

al = SunAlt
if al < -15 then
   print al; "= nighttime"
else
   print al; "= daytime"
end if

sub SunAlt
  ra,de = SunRaDec(JD)
  az,al = EquatToAltaz(ra,de,myLon,myLat,JD)
  return al
end sub

Re: Detecting daytime and nighttime

Posted: 11 Dec 2018, 16:51
by Forum_2017
> when it's 15 degrees below the horizon then it's surely night.

Nope!

18 degrees below is the official start of astronomical darkness.

Civil, Nautical and Astronomical twilight are each 6 degrees, hence astronautical night starts at -18 degrees.

Andrew