コード例 #1
0
ファイル: test_jdcal.py プロジェクト: Jon1ke/script
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)
コード例 #2
0
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
コード例 #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)
コード例 #4
0
ファイル: test_jdcal.py プロジェクト: Jon1ke/script
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)
コード例 #5
0
ファイル: test_jdcal.py プロジェクト: phn/jdcal
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)
コード例 #6
0
ファイル: test_jdcal.py プロジェクト: phn/jdcal
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)