Sunday 10 November 2019

astronomy - How to determine day/night based on latitude, longitude and a date/time?


Is there a simple method of determining, given a UTC date/time, whether it is day or night at a given lat/long coordinate?


I am currently using a formula based on a Sunrise/Sunset Algorithm from the US Naval Observatory, but unfortunately I am having trouble applying to arrive at a simple night/day indicator.



Should I build upon this formula or is there some more efficient way of doing this that I am missing?


Disclaimer: I am a programmer, not an astronomer, so I find the formulas for astronomical calculations a bit confusing.


Extra stuff: Ideally I would like to artificially shorten the period of "night" by two hours, for the purposes of eliminating some false positives from sensor data that occurs during twilight/dawn. In other words, if sunset occurs at 7 pm at a given location, I would like the option of padding the value by 60 minutes such that the output remains "day" until 8 pm for that location. (And apply the same padding prior to sunrise.)


Update:


I wound up calculating the sun's altitude for the location using a UTC timestamp and the location's lat/long coordinates. Using figures for various twilight amounts (6, 12, 18 or degrees below horizon) I am able to automatically select the portion of "night" that is sufficiently dark. (e.g. 6 degrees below horizon is not as dark as 12 degrees.) This approach was much easier than attempting to determine sunrise and sunset times for the locale's time zone (and all of the associated time zone headaches).



Answer



Formulas on that page are about as simple as you'll find and should meet your needs. If you're confused by something specific, just ask!


For shortening the period of night, you should go by the distance (in degrees, say) the Sun is below the horizion, rather than any fixed time. That is the setting of the "zenith" variable. You might like http://en.wikipedia.org/wiki/Twilight for background, then the values "official", "civil", "nautical", and "astronomical" on the page you referenced should make sense. Without even knowing the use for your sensor, I would suggest starting with the nautical twilight value, that is set the variable zenith to 102. (Nautical twilight is pretty dark!)


UPD: The math on the page looks good. I tried coding it and it gave the right answer (for my location today anyway) to within about a minute.


No comments:

Post a Comment

Understanding Stagnation point in pitot fluid

What is stagnation point in fluid mechanics. At the open end of the pitot tube the velocity of the fluid becomes zero.But that should result...