예제 #1
0
def test_raw_julian_gregorian_cutover():
    gregory = 2299161
    assert compute_calendar_date(gregory - 2, gregory) == (1582, 10, 3)
    assert compute_calendar_date(gregory - 1, gregory) == (1582, 10, 4)
    assert compute_calendar_date(gregory + 0, gregory) == (1582, 10, 15)
    assert compute_calendar_date(gregory + 1, gregory) == (1582, 10, 16)

    jd = np.arange(gregory - 2, gregory + 2)
    assert [list(a) for a in compute_calendar_date(jd, gregory)] == [
        [1582, 1582, 1582, 1582],
        [10, 10, 10, 10],
        [3, 4, 15, 16],
    ]

    assert julian_day(1582, 10, 3, gregory) == (gregory - 2)
    assert julian_day(1582, 10, 4, gregory) == (gregory - 1)
    assert julian_day(1582, 10, 15, gregory) == (gregory + 0)
    assert julian_day(1582, 10, 16, gregory) == (gregory + 1)

    days = [3, 4, 15, 16]
    assert list(julian_day(1582, 10, np.array(days), gregory)) == [
        2299159,
        2299160,
        2299161,
        2299162,
    ]
예제 #2
0
def days_in_range(data: AstroData,
                  start: Time,
                  end: Time,
                  progress: OPTIONAL_PROGRESS = None) -> List[BabylonianDay]:
    assert start.tt < end.tt
    position = data.timescale.tt_jd(start.tt - 2)
    end = data.timescale.tt_jd(end.tt + 1)
    prev_altitude = float("inf")
    results = []  # type: List[BabylonianDay]

    while position.tt < end.tt:
        # Sunset for this day
        cal_date = compute_calendar_date(int(position.tt), GREGORIAN_START)
        ss = sunset_and_rise_for_date(data, *cal_date)
        alt = altitude_of_moon(data, ss[0])
        # If first visibility
        if prev_altitude < LUNAR_VISIBILITY <= alt.degrees:
            first_visibility = True
        else:
            first_visibility = False
        # Next day
        results.append(BabylonianDay(ss[0], ss[1], first_visibility))
        position = data.timescale.tt_jd(int(position.tt + 1))
        prev_altitude = alt.degrees
        if progress is not None:
            progress((position.tt - start.tt) / (end.tt - start.tt))

    results = list(
        filter(lambda x: x.sunset.tt >= start.tt and x.sunrise.tt <= end.tt,
               results))
    return results