Sun elevation and moon phase

I need to know what the:

  1. sun elevation (and sunrise)
  2. moon phase
  3. moon elevation

is as a function of date, time, and coordinates.

I tried looking for an existing package in JuliaAstro, and it truly seems like all the pieces are there, but I couldn’t find anything that directly mentions any of this.

Does anyone know of a straight forward way to do this?

Thanks!

Really?

http://juliaastro.github.io/AstroLib.jl/stable/ref/#Moon-and-sun

An example of putting everything together (for the Sun):

4 Likes

We learn something new here every day.

Linking a related scientific article on how to Build Your Own Analemma.

1 Like

First, Merry Christmas. Second, I don’t see documentation for AstroLib.sunpos(). Is there any? Lastly, I’m doing something wrong in trying to get the azimuth and elevation of the sun. All pointers appreciated.
“”"
B5 = Observatory(“Bldg5”, 29.574166, -95.114444, 1, -6)
jd=jdcnv(“2024-01-28T07:15:00”)
ra,dec=sunpos(jd)
az, el = eq2hor(ra, dec)
“”"
The values I get are nowhere near the values other sources have. Even if I use a 6 hour offset for my time vs UTC.

Just a curiosity: what is the day on which the curve intertwines?
What characteristic does it have (same hours of dark and light or something like that)?

You don’t supply details or expected output, but a quick test here (Julia v1.10rc, AstroLib v0.4.2) suggests it works OK.

using AstroLib
lat, lon = (51.477811, -0.001475)
jd = jdcnv("2023-12-25T10:27:00")
ra, dec = sunpos(jd)
alti, azi, ha = eq2hor(ra, dec, jd, lat, lon)

giving altitude and azimuth (12.389058355400406, 157.92698445374288). This is close to NOAA’s calculations:

but I don’t know how accurate AstroLib’s results are expected to be - is 0.071 difference good or bad…

I think the documentation issue for sunpos has already been addressed by a helpful contributor! As it says in the README:

Check TODO.md out to see how you can help. Volunteers are welcome!

But - see here for more recent developments.

Perhaps talk to the Julia/Astronomy folks?

3 Likes

Hi - I am also trying calculate the local sunrise/sunset/moonPhase using the functions in AstroLib.jl. I have the following example code.

I read the article linked in the solution to this question, but I’m not able to take it that final step for times (either a code problem or lack of understanding the process).

using AstroLib
using Dates

dateTime = DateTime("2024-01-13")
lat, lon = (38.88, -77.03)
jd = jdcnv(dateTime)
gmst = ct2lst(lon, -5, dateTime) # local sideral time in hours

## find local coords and hour angle (in degrees)
ra, dec = sunpos(jd)  # get sun ra and dec
alt, az, ha = eq2hor(ra, dec, jd, lat, lon)  # local alt, azi, and hour angle in degrees

## calculate transit
transit =  ra/360 + lon/360 - gmst
if (transit < 0) transit += 24 end
transit_time = DateTime(year(dateTime), month(dateTime), day(dateTime), sixty(transit)[1], sixty(transit)[2])
# transit time is close, according to NOAA web site - 17:17 UTC (12:17 EST (local))

## Calculation of sunrise from transit and hour angle
sunrise = transit - ha/360

## convert to dateTime
sunrise_time = DateTime(year(dateTime), month(dateTime), day(dateTime), sixty(sunrise)[1], sixty(sunrise)[2])
## According to the NOAA calculator, sunrise should be at 12:26 UTC

It seems to have calculated the transit correctly (close to NOAA’s spreadsheet); however, I am not getting the sunrise to be even close (off by several hours). I assume I have botched units or a transform.

Any astronomy people out there familiar with AstroLib and might quickly see what is wrong?

Side question - Is Astrolib.jl considered fast/slow/similar compared to something like SunCalc? I typically need a few hundred days calculated at a time.

Thank you in advance!