[Python] Sun and Moon Azimuth from x,y,z - astro Math in Python

Discussão em 'Python' iniciado por Stack, Fevereiro 22, 2025.

  1. Stack

    Stack Membro Participativo

    I use the following code for sun and moon calculations. https://github.com/peterhinch/micro...cfd7d83afd9cf3ffd98fdac/astronomy/sun_moon.py

    This code has the option to calculate the height of the sun/moon above the horizon using the sin_alt function, but I also want to calculate the azimuth.

    def sin_alt(self, hour, sun):
    # Returns the sine of the altitude of the object (moon or sun)
    # at an hour relative to the current date (mjd)
    func = minisun if sun else minimoon
    mjd = (self.mjd - 51544.5) + hour / 24.0
    # mjd = self.mjd + hour / 24.0
    t = mjd / 36525.0
    x, y, z = func(t)
    tl = self.lstt(t, hour) + self.long # Local mean sidereal time adjusted for logitude
    return self.sglat * z + self.cglat * (x * cos(radians(tl)) + y * sin(radians(tl))) # OR math.degrees(math.asin(self.sglat * z + self.cglat * (x * cos(radians(tl)) + y * sin(radians(tl)))))



    This function receives x,y,z coordinates from the minisun or minimoon function and uses them to calculate the height of the sun above the horizon. [If I want to convert this to degrees, then I do alt = math.degrees(math.asin(sin_alt))]

    I would be happy if someone could give me the code necessary to obtain the sun/moon azimuth in degrees from north.

    I use Micropython, so I need a simple use of the math library.

    thanks!

    Continue reading...

Compartilhe esta Página