architest / pymeeus

Library of astronomical algorithms in Python
GNU Lesser General Public License v3.0
59 stars 29 forks source link

Sun.equation_of_time() returns incorrect values around the Spring equinox #22

Closed janbredenbeek closed 1 year ago

janbredenbeek commented 1 year ago

When the true Sun has just passed the Spring equinox but the 'mean' Sun has not, equation_of_time() returns an incorrect value. E.g. entering 21.0 March 2023 returns e=352 minutes 37.7 seconds where the correct value should be -7 minutes 22.3 seconds.

The fix is to convert all values in the calculation of e to float before assigning it, to avoid e being assigned as an Angle() object (which causes reduction to 0..360 range):

    e = l0() - 0.0057183 - alpha() + deltapsi() * cos(epsilon.rad())
    # FIX: in cases where alpha was just past the spring equinox but l0
    # was still < 360, e was incorrectly calculated.
    # We keep e now as a float and reduce to range -180 .. +180
    e = e - 360.0 * round(e / 360.0)
    e *= 4.0
    # Extract seconds
    s = (abs(e) % 1) * 60.0
    m = int(e)
    return m, s
architest commented 1 year ago

Dear Mr. Bredenbeek (@janbredenbeek),

Thank you very much for your remarks. I'll look into the problems you raised as soon as possible.

Best regards