Time/Date APIs - Astronomical Twilight

This idea scratches my math itch. Good luck! :+1:

@eradicator09! Yes, and interesting subject. I have been running a personally weather Site for +20 years now, and in this is also included, what you try to get, as a possibility on a watch function.
I do still not have the necessary knowledge of the possibilities in Facers tags possibilities, to could make a function to do it.
But I can give you an example of, how it’s done on my Weather Site, out from some calculations, based on latitude, and times, and combined with some math!
The following, is a script (Java) which calculate the Sun’s actual heigt above the Horizon, and when you know this, you can also find the Exact Twilight for Astronomical, Nautical and Civil, for the position you are!

latitude = 54.5 (you’r position)
dateStr = “^vst142^” (is this who picks up the exact Date)
month = parseFloat(dateStr.substring(3,5))
day = parseFloat(dateStr.substring(0,2))
timeStr = “^vst143^” (is this who picks up the exact Time) (it’s a Tag for the program, just as in Facer)
hour = parseFloat(timeStr.substring(0,2))
minute = parseFloat(timeStr.substring(3,5))
riseStr = “^vst144^” (is the strings who pick up the Sunrise, by you’r position) (it’s a Tag for the program, just as in Facer)

risehour = parseFloat(riseStr.substring(0,2))
riseminute = parseFloat(riseStr.substring(3,5))
risetime = (risehour * 60) + riseminute
setStr = “^vst145^” (is the string who picks up the Sunset, by you’r position) (it’s a Tag for the program, just as in Facer)

sethour = parseFloat(setStr.substring(0,2))
sethour = sethour +1 (the Plus, is for getting Summer Time)
setminute = parseFloat(setStr.substring(3,5))
settime = (sethour * 60) + setminute
time = hour * 60 + minute
julian_day = calcJday(month, day)
suntime = sunTime(risetime, settime, time)
sun_elevation = solarAltitude(julian_day, suntime, latitude)
sun_azimuth = solarAzimuth(julian_day, suntime, latitude)

If you (or Mellin) can use it, I don’t know. But it’s a start to ideas :wink:

1 Like

I thought I figured out the Julian Day:

Julian Day - (round(367*#Dyyyy#-(7*(#Dyyyy#+((#DM#+9)/12)))/4+(275*#DM#)/9+#Dd#-730530))

but it seems like I’m slightly off. I’ll need to review the formula.

I think I fixed it, now reads 2458000.5 for today:

Julian Day - ((367*#Dyyyy#)-floor(7*(#Dyyyy#+floor((#DM#+9)/12))/4)+floor(275*#DM#/9)+#Dd#+1721013.5)

seems like I may be 1 day off.

@eradicator09 - If I calculate backwards, your calculated Day, it seems to be the 21. of August, this year. So not one, but many day’s beside.
I put in a link here: What's the Current Day Number?
Which hold more ways to calculate Julian Day.
OR, I can send you all these calculations I use on my Weather Site, for calculation of the Sun’s position, and Sunset and Sunrise. (It’s in java).

@eradicator09 - I just made a new calculation (the other I made, was wrong), with these tags used in your formula. And the JD is correct in you Formula, and not 1 day beside, as you write.
Even if you use the long Formula version, it gives correct number:
((367*#Dyyyy#)-floor(7*(#Dyyyy#+floor((#DM#+9)/12))/4)-floor(3*(floor((#Dyyyy#+(#DM#-9)/7)/100)+1)/4)+floor(275*#DM#/9)+#Dd#+1721028.5)

yep, looks right when comparing to this calculator:
http://aa.usno.navy.mil/data/docs/JulianDate.php

I wonder did I just miss a short section in the formula?

Do these require the lat/lon to calculate?

Only the Latitude!
But in fact, you actually only need the actual day (called JD) of the actual year, to use in end calculation for the Sun’s position, and thereby, the Twilight! And not the fully JD.

No! as I recalculate, by using you’r (short) version of the formula, it is still correct.

1 Like

Well at least that’s something. I wonder if there is a way to solve for latitude by knowing the Sunset and Sunrise times, and date (declination).

That’s where I see the problem, with your “project”. And it was to put in the Latitude (or Longitude), into a watch calculation, as I can’t see anywhere, where it should be possible.
If there was a tag, who could give the GPS info, it could in a way be possible, to use it in that way.
I can’t see a way, to recalculate to find position, by knowing Sunrise, Sunset times.

Figured out Declination:

((round(23.45sin(((360/365)(284+#DD#))*pi/180)*100))/100

Displays as 6.18 for today which appears correct.

Here is my working demo of some of the calculations:

What is you’r actual latitude (Livingplace)?

30.4583° N, 91.1403° W

for Baton Rouge, LA USA

I can’t get it to be fully correct (or fit with your’s time). I get 6.44!!
To could get the exact Twilight, it has to be correct on the exact minute. I will try to look more close on all these tags in facer, to learn more about what’s possible. I’m just started, using the system.

Ohhhhh very nice! Would have been perfect for the eclipse on August 21st!

Hi @eradicator09, did you manage to get a working expression for astronomical twighlight?

Unfortunately no. There is not enough data available to create an accurate calculation. One of the main items missing is location information (GPS coordinates). This along with a few other items needed made it impossible. Generally speaking though, you could get an estimate based Sunset and Sunrise. Since Astronomical twilight is when the sun is 18 degrees below the horizon, you could guesstimate that it takes approximately 1.2 hours after sunset.

Again that is very rough calculation since Longitude is needed to get the declination. I gave on it and instead have made requests for additional API data from the OpenWeather app. There are some additional functions that they provide that would cover astronomical terms. Still waiting on that one.

If you really want to get sciency, then here is the spot for figuring out the calculations:
http://www.stargazing.net/kepler/sunrise.html

3 Likes