Skip to content
Snippets Groups Projects
moon_phase.py 993 B
Newer Older
tomrink's avatar
tomrink committed
from skyfield import api
from skyfield import almanac
from util.util import get_time_tuple_utc
tomrink's avatar
tomrink committed
from util.setup import ancillary_path
tomrink's avatar
tomrink committed

tomrink's avatar
tomrink committed
time_scale = api.load.timescale()
tomrink's avatar
tomrink committed
load = api.Loader(ancillary_path)
eph = load('de421.bsp')
tomrink's avatar
tomrink committed


def convert_time(epoch_time):
    dt_obj, dt_tup = get_time_tuple_utc(epoch_time)
tomrink's avatar
tomrink committed
    t = time_scale.from_datetime(dt_obj)
    t = time_scale.utc(dt_tup[0], dt_tup[1], dt_tup[2], dt_tup[3])
tomrink's avatar
tomrink committed
    return t


tomrink's avatar
tomrink committed
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)


tomrink's avatar
tomrink committed
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])
tomrink's avatar
tomrink committed
    t = time_scale.from_datetimes(dt_obj_s)
tomrink's avatar
tomrink committed
    return t


tomrink's avatar
tomrink committed
def moon_phases(dt_obj_s, phs_deg=70):
    t = time_scale.from_datetimes(dt_obj_s)
tomrink's avatar
tomrink committed
    phase = almanac.moon_phase(eph, t)
    return (phase.degrees > phs_deg) & (phase.degrees < 360-phs_deg)