Esempio n. 1
0
def test_gcal2jd_with_astropy_erfa_cal2jd():
    """Compare gcal2jd with astropy._erfa.cal2jd."""
    import random
    import numpy as np
    from astropy import _erfa

    n = 1000
    mday = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

    # sla_cldj needs year > -4699 i.e., 4700 BC.
    year = [random.randint(-4699, 2200) for i in range(n)]
    month = [random.randint(1, 12) for i in range(n)]
    day = [random.randint(1, 31) for i in range(n)]
    for i in range(n):
        x = 0
        if is_leap(year[i]) and month[i] == 2:
            x = 1
        if day[i] > mday[month[i]] + x:
            day[i] = mday[month[i]]

    jd_jdcal = np.array(
        [gcal2jd(y, m, d) for y, m, d in zip(year, month, day)])
    jd_erfa = np.array(_erfa.cal2jd(year, month, day)).T

    assert np.allclose(jd_jdcal, jd_erfa)
def test_gcal2jd_with_sla_cldj():
    """Compare gcal2jd with slalib.sla_cldj."""
    import random
    try:
        from pyslalib import slalib
    except ImportError:
        print("SLALIB (PySLALIB not available).")
        return 1
    n = 1000
    mday = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

    # sla_cldj needs year > -4699 i.e., 4700 BC.
    year = [random.randint(-4699, 2200) for i in range(n)]
    month = [random.randint(1, 12) for i in range(n)]
    day = [random.randint(1, 31) for i in range(n)]
    for i in range(n):
        x = 0
        if is_leap(year[i]) and month[i] == 2:
            x = 1
        if day[i] > mday[month[i]] + x:
            day[i] = mday[month[i]]

    jd_jdc = [gcal2jd(y, m, d)[1]
              for y, m, d in zip(year, month, day)]
    jd_sla = [slalib.sla_cldj(y, m, d)[0]
              for y, m, d in zip(year, month, day)]
    diff = [abs(i - j) for i, j in zip(jd_sla, jd_jdc)]
    assert max(diff) <= 1e-8
    assert min(diff) <= 1e-8
Esempio n. 3
0
def days_in_year(year, c="g"):
    """Number of days in a calendar year (Gregorian/Julian)."""
    if c.lower() == "g":
        return 366 if is_leap(year) else 365
    elif c.lower() == "j":
        return 365
    else:
        raise ValueError("Unknow calendar type %s ." % c)
Esempio n. 4
0
def test_is_leap():
    assert is_leap(2000)
    assert not is_leap(2001)
    assert is_leap(2004)
    assert not is_leap(1000)
    assert not is_leap(1998)
    assert is_leap(1992)
Esempio n. 5
0
def test_is_leap():
    assert is_leap(2000)
    assert not is_leap(2001)
    assert is_leap(2004)
    assert not is_leap(1000)
    assert not is_leap(1998)
    assert is_leap(1992)
Esempio n. 6
0
def test_gcal2jd_with_astropy_erfa_cal2jd():
    """Compare gcal2jd with astropy._erfa.cal2jd."""
    import random
    import numpy as np
    from astropy import _erfa

    n = 1000
    mday = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

    # sla_cldj needs year > -4699 i.e., 4700 BC.
    year = [random.randint(-4699, 2200) for i in range(n)]
    month = [random.randint(1, 12) for i in range(n)]
    day = [random.randint(1, 31) for i in range(n)]
    for i in range(n):
        x = 0
        if is_leap(year[i]) and month[i] == 2:
            x = 1
        if day[i] > mday[month[i]] + x:
            day[i] = mday[month[i]]

    jd_jdcal = np.array([gcal2jd(y, m, d) for y, m, d in zip(year, month, day)])
    jd_erfa = np.array(_erfa.cal2jd(year, month, day)).T

    assert np.allclose(jd_jdcal, jd_erfa)