Skip to content
Snippets Groups Projects
Select Git revision
  • 2091d94cd473cc8741eae2dfd2ace6d57cb34431
  • master default protected
  • use_flight_altitude
  • distribute
4 results

moon_phase.py

Blame
  • user avatar
    tomrink authored
    00b58f89
    History
    moon_phase.py 993 B
    from skyfield import api
    from skyfield import almanac
    from util.util import get_time_tuple_utc
    from util.setup import ancillary_path
    
    time_scale = api.load.timescale()
    load = api.Loader(ancillary_path)
    eph = load('de421.bsp')
    
    
    def convert_time(epoch_time):
        dt_obj, dt_tup = get_time_tuple_utc(epoch_time)
        t = time_scale.from_datetime(dt_obj)
        t = time_scale.utc(dt_tup[0], dt_tup[1], dt_tup[2], dt_tup[3])
        return t
    
    
    def moon_phase(epoch_time, phs_deg=70):
        phase = almanac.moon_phase(eph, convert_time(epoch_time))
        return (phase.degrees > phs_deg) & (phase.degrees < 360 - phs_deg)
    
    
    def convert_times(epoch_time_s):
        dt_obj_s = []
        for et in epoch_time_s:
            dt_obj_s.append(get_time_tuple_utc(et)[0])
        t = time_scale.from_datetimes(dt_obj_s)
        return t
    
    
    def moon_phases(dt_obj_s, phs_deg=70):
        t = time_scale.from_datetimes(dt_obj_s)
        phase = almanac.moon_phase(eph, t)
        return (phase.degrees > phs_deg) & (phase.degrees < 360-phs_deg)