Пример #1
0
def find_new_moon(d):       # used in doublepage
    # find previous & next new moon
    global PreviousNewMoon
    global NextNewMoon
    PreviousNewMoon  = None
    NextNewMoon      = None
    # note: the python datetimes above are timezone 'aware' (not 'naive')

    # search from 30 days earlier than noon... till noon on this day
    d0 = d - datetime.timedelta(days=30)
    t0 = ts.utc(d0.year, d0.month, d0.day, 12, 0, 0)
    t1 = ts.utc(d.year, d.month, d.day, 12, 0, 0)
    t, y = almanac.find_discrete(t0, t1, almanac.moon_phases(eph))
    for i in range(len(t)):
        if y[i] == 0:       # 0=New Moon, 1=First Quarter, 2=Full Moon, 3=Last Quarter
            PreviousNewMoon = t[i].utc_datetime()

    if PreviousNewMoon != None:
        # synodic month = about 29.53 days
        t2 = ts.utc(PreviousNewMoon + datetime.timedelta(days=28))
        t3 = ts.utc(PreviousNewMoon + datetime.timedelta(days=30))
        t, y = almanac.find_discrete(t2, t3, almanac.moon_phases(eph))
        for i in range(len(t)):
            if y[i] == 0:       # 0 = New Moon
                NextNewMoon = t[i].utc_datetime()
    return
Пример #2
0
def moon_phase_list(t0, t1):
    t, p = almanac.find_discrete(t0, t1, almanac.moon_phases(e))

    l = []
    for i in range(0, len(t)):
        l.append({'t': t[i].utc_datetime(), 'p': p[i]})

    return l
Пример #3
0
def test_moon_phases():
    ts = api.load.timescale()
    t0 = ts.utc(2018, 9, 11)
    t1 = ts.utc(2018, 9, 30)
    e = api.load('de421.bsp')
    t, y = almanac.find_discrete(t0, t1, almanac.moon_phases(e))
    strings = t.utc_strftime('%Y-%m-%d %H:%M')
    assert strings == ['2018-09-16 23:15', '2018-09-25 02:52']
    assert (y == (1, 2)).all()
Пример #4
0
def next_full_moon(given_date):
    start = ts.utc(given_date)
    finish = ts.utc(given_date + timedelta(30))
    times, phases = almanac.find_discrete(start, finish, almanac.moon_phases(e))
    for t, p in zip(times, phases):
        if p == 2:
            return t.utc_datetime()
    else:
        raise ExceptionalError("That's no moon.") #there should always be a full moon over the span of 30 days
def find_phases(endyear, startyear, zone):
    d0 = datetime(startyear, 1, 1)
    d1 = datetime(endyear + 1, 1, 1)
    # localize to eastern timezone
    e0 = zone.localize(d0)
    e1 = zone.localize(d1)
    t, y = almanac.find_discrete(ts.from_datetime(e0), ts.from_datetime(e1),
                                 almanac.moon_phases(eph))
    return t, y
Пример #6
0
def test_moon_phases():
    ts = api.load.timescale()
    t0 = ts.utc(2018, 9, 11)
    t1 = ts.utc(2018, 9, 30)
    e = api.load('de421.bsp')
    t, y = almanac.find_discrete(t0, t1, almanac.moon_phases(e))
    t.tt += half_minute
    strings = t.utc_strftime('%Y-%m-%d %H:%M')
    assert strings == ['2018-09-16 23:15', '2018-09-25 02:52']
    assert (y == (1, 2)).all()
Пример #7
0
    def newMoon(self):
        result = []
        t0 = ts.utc(self.t0)
        t1 = ts.utc(self.t1)
        f = almanac.moon_phases(e)
        t, y = almanac.find_discrete(t0, t1, f)
        for ti, yi in zip(t, y):
            if(yi == 0):
                result.append(ti)
            else:
                pass

        return result
Пример #8
0
def moon_phase():
    lookup_table = [
        "NM",
        "FQ",
        "FM",
        "LQ",
    ]
    end = datetime.today().astimezone().replace(hour=23,
                                                minute=59,
                                                second=0,
                                                microsecond=0)
    t0 = ts.utc(end)

    mp = almanac.moon_phases(ephem)(t0)
    mp = lookup_table[mp]

    mf = almanac.fraction_illuminated(ephem, 'moon', t0)
    mf = math.ceil(mf * 100)

    return f"{mp}{mf:02}"
Пример #9
0
def main(startyear=1582, years=1000, month=10, day=15):
    '''
    Generate tables of number of, next and previous occurances of :
       Full moon falling on Friday the 13th
       Mini moon falling on Friday the 13th
       Super moon falling on Friday the 13th
    Across American timezones and anywhere in the world
    :param startyear: year to start
    :param years: number of years to consider
    :param month: month to start (defaults to first month of Gregorian calendar)
    :param day: day to start (defaults to first day of Gregorian calendar)
    :return: nothing
    '''
    endyear = startyear + years
    picklefile = f"data/fullmoons_{startyear}-{endyear}.p"
    try:
        # try cache first
        (t, y) = pickle.load(open(picklefile, "rb"))
    except:
        # first day =  Friday, 15 October 1582
        t0 = ts.utc(startyear, month,
                    day)  # start with introduction of Gregorian calendar
        t1 = ts.utc(endyear, month, day)
        t, y = almanac.find_discrete(t0, t1, almanac.moon_phases(e))
        pickle.dump((t, y), open(picklefile, "wb"))

    picklefile2 = f"data/coincidences_{startyear}-{endyear}.p"
    try:
        (fri13, fri13apogee, fri13perigee,
         total) = pickle.load(open(picklefile2, "rb"))
    except:
        fri13, fri13apogee, fri13perigee, total = find_coincidences(t, y)
        pickle.dump((fri13, fri13apogee, fri13perigee, total),
                    open(picklefile2, "wb"))

    dump_html(day, fri13, fri13apogee, fri13perigee, month, startyear, total,
              years)
Пример #10
0
from skyfield.api import load, Topos
from skyfield import almanac
from datetime import datetime, timedelta
from pytz import timezone

jkt = timezone('Asia/Jakarta')
ts = load.timescale(builtin=True)
e = load('de421.bsp')

def nearest_second(t):
    return (t + timedelta(seconds=0.5)).replace(microsecond=0)

t0 = ts.utc(2019, 1, 1)
t1 = ts.utc(2020, 1, 1)
f = almanac.moon_phases(e)
t, y = almanac.find_discrete(t0, t1, f)
for ti, yi in zip(t, y):
    if (yi == 3):
        t = ti.astimezone(jkt)
        dt = nearest_second(t)
        print(dt.replace(tzinfo=None))
Пример #11
0
def get_lunar_dates_and_phases(start: datetime, end: datetime):
    times, phases = almanac.find_discrete(ts.from_datetime(start),
                                          ts.from_datetime(end),
                                          almanac.moon_phases(eph))
    return [(time.utc_datetime(), phases[i]) for i, time in enumerate(times)]
Пример #12
0
        return 0


def MoonPhaseCycleObserver():
    def _moon_cycle(t):
        phdeg = MOON_PHDEGOB(t)
        moon_cycle = ndarray((len(t), ), int)
        for ofs in range(len(t)):
            moon_cycle[ofs] = phdeg[ofs] >= 0 and phdeg[ofs] < 180
        return moon_cycle

    _moon_cycle.rough_period = MOON_SYNODIC_PERIOD // 2
    return _moon_cycle


MOON_PHASE_EVENTS = almanac.moon_phases(PLANETS)
MOON_PHASE_CYCLES = MoonPhaseCycleObserver()


# For computing progression of this season
def SeasonProg(time_dt, time_ordinal):
    QUARTER = DAYS_IN_YEAR / 4
    period_start = TIMESCALE.utc(time_dt - timedelta(days=QUARTER + 1))
    period_end = TIMESCALE.utc(time_dt + timedelta(days=QUARTER + 1))
    ST, SI = almanac.find_discrete(period_start, period_end, SEASONS)
    ST_ORD = ST.toordinal().tolist()
    SI_ARR = SI.tolist()
    if len(ST_ORD) == 3:
        if time_ordinal >= ST_ORD[1]:
            SI_ARR.pop(0)
            ST_ORD.pop(0)
Пример #13
0
current_phase = (moon_ecliptic_latitude.degrees -
                 sun_ecliptic_longitude.degrees) % MOON_TOTAL_PHASE_ANGLE

# Phases

phrase_start_date = observation_datetime - timedelta(
    days=APPROXIMATIVE_MOON_REVOLUTION_DAYS)
phrase_end_date = observation_datetime + timedelta(
    days=APPROXIMATIVE_MOON_REVOLUTION_DAYS)
phrase_start_time = timescale.utc(phrase_start_date.year,
                                  phrase_start_date.month,
                                  phrase_start_date.day)
phrase_end_time = timescale.utc(phrase_end_date.year, phrase_end_date.month,
                                phrase_end_date.day)

moon_phases = almanac.moon_phases(eph)

previous_phases_times, previous_phases_indentifiers = almanac.find_discrete(
    phrase_start_time,
    observation_time,
    moon_phases,
)

next_phases_times, next_phases_indentifiers = almanac.find_discrete(
    observation_time,
    phrase_end_time,
    moon_phases,
)

moon_phases = []
Пример #14
0
#https://rhodesmill.org/skyfield/almanac.html#transits

from skyfield.api import load
from skyfield import almanac
# ['New Moon', 'First Quarter', 'Full Moon', 'Last Quarter']
#print('Load bsp file ...')
#eph = load('https://naif.jpl.nasa.gov/pub/naif/JUNO/kernels/spk/de421.bsp')
eph = load('de421.bsp')
ts = load.timescale()
year = 2021
print('\nMoon phases in', year)
t0 = ts.utc(year, 1, 1)
t1 = ts.utc(year, 12, 31)
t, y = almanac.find_discrete(t0, t1, almanac.moon_phases(eph))
#print(t.utc_iso())
#print(y)
#print([almanac.MOON_PHASES[yi] for yi in y])
for ti, yi in zip(t, y):
    #print(ti.utc_iso(), almanac.MOON_PHASES[yi])
    print(ti.utc_strftime('On %Y,%b %d at %H:%M:%S (UTC)'),
          almanac.MOON_PHASES[yi])
    if almanac.MOON_PHASES[yi] == 'Last Quarter':
        print()