skyfielders / python-skyfield

Elegant astronomy for Python
MIT License
1.38k stars 208 forks source link

Moon phase-finding function #854

Closed tostt closed 12 months ago

tostt commented 1 year ago

I noticed there is no next_new_moon() function. I'm not sure if it's intentional. So I wrote a more general phase-finding function that you may be interested in. Just in case it is useful to anyone.

def next_named_moon_phase(named_phase_index, t0, eph):
    t1 = t0 + timedelta(days=30)
    t, y = almanac.find_discrete(t0, t1, almanac.moon_phases(eph))
    return t[np.where(y == named_phase_index)[0]][0]

print('new moon: ', next_named_moon_phase(0, ts.utc(2023, 1, 1), eph).utc_iso())
brandon-rhodes commented 12 months ago

Thanks for sharing! Hopefully if anyone else is in the same circumstance, a quick search will lead them to your suggestion here in this issue. I'll go ahead and close since it looks like your code is working fine!