Пример #1
0
def equinox_solstice():
    lookup_table = [
        'VE',
        'SS',
        'AE',
        'WS',
    ]
    start = datetime.today().astimezone().replace(month=1,
                                                  day=1,
                                                  hour=0,
                                                  minute=0,
                                                  second=0,
                                                  microsecond=0)
    end = datetime.today().astimezone().replace(month=12,
                                                day=31,
                                                hour=0,
                                                minute=0,
                                                second=0,
                                                microsecond=0)
    today = datetime.today().astimezone()
    t0 = ts.utc(start)
    t1 = ts.utc(end)
    times, events = almanac.find_discrete(t0, t1, almanac.seasons(ephem))

    tz = datetime.now().astimezone().tzinfo

    for yi, ti in zip(events, times):
        ti = ti.astimezone(tz)
        if (today.month, today.day) == (ti.month, ti.day):
            return lookup_table[yi] + ti.strftime('%H%M')
    return ''
Пример #2
0
def test_close_start_and_end():
    ts = api.load.timescale()
    t0 = ts.utc(2018, 9, 23, 1)
    t1 = ts.utc(2018, 9, 23, 2)
    e = api.load('de421.bsp')
    t, y = almanac.find_discrete(t0, t1, almanac.seasons(e))
    strings = t.utc_strftime('%Y-%m-%d %H:%M')
    assert strings == ['2018-09-23 01:54']
Пример #3
0
def test_close_start_and_end():
    ts = api.load.timescale()
    t0 = ts.utc(2018, 9, 23, 1)
    t1 = ts.utc(2018, 9, 23, 2)
    e = api.load('de421.bsp')
    t, y = almanac.find_discrete(t0, t1, almanac.seasons(e))
    t.tt += half_minute
    strings = t.utc_strftime('%Y-%m-%d %H:%M')
    assert strings == ['2018-09-23 01:54']
Пример #4
0
def test_seasons():
    ts = api.load.timescale()
    t0 = ts.utc(2018, 9, 20)
    t1 = ts.utc(2018, 12, 31)
    e = api.load('de421.bsp')
    t, y = almanac.find_discrete(t0, t1, almanac.seasons(e))
    strings = t.utc_strftime('%Y-%m-%d %H:%M')
    print(strings)
    assert strings == ['2018-09-23 01:54', '2018-12-21 22:23']
    assert (y == (2, 3)).all()
Пример #5
0
def march_equinox(year):
    # must be 15 day range minimum, apparently?
    t0 = ts.utc(year, 3, 13)
    t1 = ts.utc(year, 3, 28)
    tstamp, phase = almanac.find_discrete(t0, t1, almanac.seasons(e))
    for phi, ti in zip(phase, tstamp):
        if phi == 0:
            return ti.utc_datetime()
    else:
        raise ExceptionalError("Is this Earth?")
Пример #6
0
def season_event_times(start, end):
    """
    Computes season event times between start and end.
    Returns list of EventTime objects.
    """
    t, y = almanac.find_discrete(start, end, almanac.seasons(ephemeris))
    return [
        EventTime(Event(event, almanac.SEASON_EVENTS[event]), time)
        for time, event in zip(t, y)
    ]
Пример #7
0
def test_seasons():
    ts = api.load.timescale()
    t0 = ts.utc(2018, 9, 20)
    t1 = ts.utc(2018, 12, 31)
    e = api.load('de421.bsp')
    t, y = almanac.find_discrete(t0, t1, almanac.seasons(e))
    t.tt += half_minute
    strings = t.utc_strftime('%Y-%m-%d %H:%M')
    print(strings)
    assert strings == ['2018-09-23 01:54', '2018-12-21 22:23']
    assert (y == (2, 3)).all()
Пример #8
0
def getSeason( n, season ):
    '''Returns the date of the season for year n.'''
    from skyfield import almanac
    loadAstronomyData( )

    if not g.astroDataAvailable:
        raise ValueError( "Astronomy functions are unavailable." )

    t, y = almanac.find_discrete( g.timescale.utc( real_int( n ), 1, 1 ),
                                  g.timescale.utc( n, 12, 31 ), almanac.seasons( g.ephemeris ) )
    result = RPNDateTime.parseDateTime( t[ season ].utc_datetime( ) )
    return result.getLocalTime( )
def get_seasons(timezone_name, year):
    ts = api.load.timescale(builtin=True)
    load = api.Loader('/var/data')
    eph = load('de430t.bsp')
    localtz = timezone(timezone_name)
    t0 = ts.utc(year)  # midnight Jan 1
    t1 = ts.utc(year + 1)  # midnight Jan 1 following year
    t, y = almanac.find_discrete(t0, t1, almanac.seasons(eph))
    season = {}
    for yi, ti in zip(y, t):
        season[almanac.SEASON_EVENTS[yi]] = ti.utc_datetime().astimezone(localtz)
    eph.close()
    return season
Пример #10
0
def calculate_equinoxes(year, timezone='UTC'):
    """ calculate equinox with time zone """
    tz = pytz.timezone(timezone)

    load = Loader(get_skyfield_data_path())
    ts = load.timescale()
    planets = load('de421.bsp')

    t0 = ts.utc(year, 1, 1)
    t1 = ts.utc(year, 12, 31)
    datetimes, _ = almanac.find_discrete(t0, t1, almanac.seasons(planets))
    vernal_equinox = datetimes[0].astimezone(tz).date()
    autumn_equinox = datetimes[2].astimezone(tz).date()
    return vernal_equinox, autumn_equinox
Пример #11
0
def getSeason( n, season ):
    '''Returns the date of the season for year n.'''
    loadAstronomyData( )

    if isinstance( n, RPNDateTime ):
        n = n.year

    if not g.astroDataAvailable:
        raise ValueError( 'Astronomy functions are unavailable.' )

    times, _ = almanac.find_discrete( g.timescale.utc( n, 1, 1 ),
                                      g.timescale.utc( n, 12, 31 ), almanac.seasons( g.ephemeris ) )
    result = RPNDateTime.parseDateTime( times[ season ].utc_datetime( ) )
    return result.getLocalTime( )
Пример #12
0
def vernal_equinox(data: AstroData, year: int) -> Time:
    """
    For a given year find the date of the vernal equinox
    """
    before = data.timescale.julian_calendar_cutoff
    data.timescale.julian_calendar_cutoff = None
    t0 = data.timescale.ut1(year, 3, 16)
    t1 = data.timescale.ut1(year, 3, 26)
    data.timescale.julian_calendar_cutoff = before
    times, types = almanac.find_discrete(t0, t1,
                                         almanac.seasons(data.ephemeris))
    assert len(times) == 1
    assert almanac.SEASON_EVENTS[(types[0])] == 'Vernal Equinox'
    return times[0]
Пример #13
0
    def get_seasons(year: int) -> dict:
        start_time = get_timescale().utc(year, 1, 1)
        end_time = get_timescale().utc(year, 12, 31)
        times, almanac_seasons = find_discrete(
            start_time, end_time, almanac.seasons(get_skf_objects()))

        seasons = {}
        for time, almanac_season in zip(times, almanac_seasons):
            if almanac_season == 0:
                season = 'MARCH'
            elif almanac_season == 1:
                season = 'JUNE'
            elif almanac_season == 2:
                season = 'SEPTEMBER'
            elif almanac_season == 3:
                season = 'DECEMBER'
            else:
                raise AssertionError

            seasons[season] = time.utc_iso()

        return seasons
Пример #14
0
    import matplotlib.pyplot as plt
    fig, ax = plt.subplots()
    ax.plot(t.J, gd - jd, '.') #, label='label', linestyle='--')
    ax.axvline(325, color='blue')
    #ax.plot(325, 0, '.') #, label='label', linestyle='--')
    # ax.set(xlabel='time (s)', ylabel='voltage (mV)', title='Title')
    # ax.set_aspect(aspect=1.0)
    ax.grid()
    # plt.legend()
    ax.set_ylim(-10, 15)
    fig.savefig('tmp.png')
    exit()

eph = api.load('de422.bsp')
t, y = almanac.find_discrete(t0, t1, almanac.seasons(eph))

vernal = (y == 0)
t = t[vernal]
y = y[vernal]

#cal = t.ut1_calendar
cal = lambda: t.utc
gday = cal()[2]
for yi, ti in zip(y, t):
    if 325 < ti.J <= 326:
        print(yi, almanac.SEASON_EVENTS[yi], ti.utc_iso(' '))

ts.julian_calendar_cutoff = api.GREGORIAN_START

del t.utc
Пример #15
0
# Useful constants
SECS_IN_HOUR = 3600
HOURS_IN_DAY = 24
SECS_IN_DAY = SECS_IN_HOUR * HOURS_IN_DAY
UNIX_TS_OFFSET = datetime(1970, 1, 1).toordinal() * SECS_IN_DAY
DAYS_IN_YEAR = 365.2422
MOON_SYNODIC_PERIOD = 29.53

# Load Skyfield data
TIMESCALE = sf_api.load.timescale()
PLANETS = sf_api.load('de421.bsp')
SUN = PLANETS['sun']
MOON = PLANETS['moon']
EARTH = PLANETS['earth']
SEASONS = almanac.seasons(PLANETS)


# Genalized from skyfield/almanac.py
def PlanetObserver(planet, topos):
    topos_at = (EARTH + topos).at

    def _observe_at(t):
        t._nutation_angles = iau2000b(t.tt)
        return topos_at(t).observe(planet).apparent()

    return _observe_at


# For computing sun/moon rise/set time
SUN_TOP_HORIZON = 0.26667