Beispiel #1
0
def test_leap():
    """example from leap-seconds.list"""
    l = leapsec.LeapSeconds()
    jd9 = novas.julian_date(1972, 6, 30, 23 + (3599. / 3600))
    assert l.getLeapSeconds(jd9) == 10
    jd0 = novas.julian_date(1972, 7, 1, 0)
    assert l.getLeapSeconds(jd0) == 11
def main():
    jd_start, jd_end, number = eph_manager.ephem_open()
    output({}, """\
        'Auto-generated accuracy tests vs NOVAS (see build_novas_tests.py).'

        from numpy import abs, array, einsum, max
        from skyfield import (earthlib, framelib, nutationlib, positionlib,
                              precessionlib, starlib, timelib)
        from skyfield.api import Topos, load
        from skyfield.constants import AU_KM, AU_M
        from skyfield.data import hipparcos
        from skyfield.functions import length_of

        OLD_AU_KM = 149597870.691  # TODO: load from de405
        OLD_AU = AU_KM / OLD_AU_KM

        one_second = 1.0 / 24.0 / 60.0 / 60.0
        arcsecond = 1.0 / 60.0 / 60.0
        ra_arcsecond = 24.0 / 360.0 / 60.0 / 60.0
        meter = 1.0 / AU_M

        def ts():
            yield load.timescale()

        def compare(value, expected_value, epsilon):
            if hasattr(value, 'shape') or hasattr(expected_value, 'shape'):
                assert max(abs(value - expected_value)) <= epsilon
            else:
                assert abs(value - expected_value) <= epsilon

        def de405():
            yield load('de405.bsp')

        def earth():
            eph = load('de405.bsp')
            yield eph[399]

        def reduce_precision(t):
            # The NOVAS library uses only 64-bit precision for Julian dates.
            # Some of these tests are so sensitive they can see the difference!
            # So we need to collapse the Julian dates back into single floats.
            delta = t.tdb - t.tt
            t.whole = t.tdb
            t.tt_fraction = delta
            t.tdb_fraction = 0.0

        """)

    moon_landing = novas.julian_date(1969, 7, 20, 20.0 + 18.0 / 60.0)
    first_hubble_image = novas.julian_date(1990, 5, 20)
    voyager_intersellar = novas.julian_date(2012, 8, 25)

    date_vector = [moon_landing, first_hubble_image, T0, voyager_intersellar]
    dates = date_vector + [date_vector]

    output_subroutine_tests(dates)
    output_ephemeris_tests()
    output_geocentric_tests(dates)
    output_topocentric_tests(dates)
    output_catalog_tests(dates)
def main():
    jd_start, jd_end, number = eph_manager.ephem_open()
    output({}, """\
        'Auto-generated accuracy tests vs NOVAS (see build_novas_tests.py).'

        from numpy import abs, array, einsum, max
        from skyfield import (earthlib, framelib, nutationlib, positionlib,
                              precessionlib, starlib, timelib)
        from skyfield.api import Topos, load
        from skyfield.constants import AU_KM, AU_M
        from skyfield.data import hipparcos
        from skyfield.functions import length_of

        OLD_AU_KM = 149597870.691  # TODO: load from de405
        OLD_AU = AU_KM / OLD_AU_KM

        one_second = 1.0 / 24.0 / 60.0 / 60.0
        arcsecond = 1.0 / 60.0 / 60.0
        ra_arcsecond = 24.0 / 360.0 / 60.0 / 60.0
        meter = 1.0 / AU_M

        def ts():
            yield load.timescale()

        def compare(value, expected_value, epsilon):
            if hasattr(value, 'shape') or hasattr(expected_value, 'shape'):
                assert max(abs(value - expected_value)) <= epsilon
            else:
                assert abs(value - expected_value) <= epsilon

        def de405():
            yield load('de405.bsp')

        def earth():
            eph = load('de405.bsp')
            yield eph[399]

        """)

    moon_landing = novas.julian_date(1969, 7, 20, 20.0 + 18.0/60.0)
    first_hubble_image = novas.julian_date(1990, 5, 20)
    voyager_intersellar = novas.julian_date(2012, 8, 25)

    date_vector = [moon_landing, first_hubble_image, T0, voyager_intersellar]
    dates = date_vector + [date_vector]

    output_subroutine_tests(dates)
    output_ephemeris_tests()
    output_geocentric_tests(dates)
    output_topocentric_tests(dates)
    output_catalog_tests(dates)
Beispiel #4
0
def main():
    jd_start, jd_end, number = eph_manager.ephem_open()
    output({}, """\
        'Auto-generated accuracy tests vs NOVAS (see build_novas_tests.py).'

        from numpy import abs, array, einsum, max
        from skyfield import (earthlib, framelib, nutationlib, positionlib,
                              precessionlib, starlib, timelib)
        from skyfield.api import load
        from skyfield.constants import AU_KM, AU_M
        from skyfield.data import hipparcos
        from skyfield.functions import length_of

        OLD_AU_KM = 149597870.691  # TODO: load from de405
        OLD_AU = AU_KM / OLD_AU_KM

        one_second = 1.0 / 24.0 / 60.0 / 60.0
        arcsecond = 1.0 / 60.0 / 60.0
        ra_arcsecond = 24.0 / 360.0 / 60.0 / 60.0
        meter = 1.0 / AU_M

        def ts():
            yield load.timescale()

        def compare(value, expected_value, epsilon):
            if hasattr(value, 'shape') or hasattr(expected_value, 'shape'):
                assert max(abs(value - expected_value)) <= epsilon
            else:
                assert abs(value - expected_value) <= epsilon

        def de405():
            yield load('de405.bsp')

        def earth():
            eph = load('de405.bsp')
            yield eph[399]

        """)

    moon_landing = novas.julian_date(1969, 7, 20, 20.0 + 18.0 / 60.0)
    first_hubble_image = novas.julian_date(1990, 5, 20)
    voyager_intersellar = novas.julian_date(2012, 8, 25)

    date_vector = [moon_landing, first_hubble_image, T0, voyager_intersellar]
    dates = date_vector + [date_vector]

    output_subroutine_tests(dates)
    output_geocentric_tests(dates)
    output_topocentric_tests(dates)
    output_catalog_tests(dates)
Beispiel #5
0
def date2JD(dateObs):
    yr, mn, dy = parseDate(dateObs)
    if ' ' in dy:
        dy = dy.split(' ')[0]
    hr, dy = math.modf(float(dy))
    jd = novas.julian_date(int(yr), int(mn), int(dy), 24. * hr)
    return jd
Beispiel #6
0
def main(args):
    date = args.date.split(' ')
    leap_secs = 37
    epoc_hip = 2448349.0625
    # Date to convert the catalog to
    jd_utc = novas.julian_date(int(date[0]), int(date[1]), int(date[2]),
                               float(date[3]))
    jd_tt = jd_utc + (leap_secs + 32.184) / 86400
    # jd_tt = novas.julian_date(1991, 4, 2, 12.5)
    converted = []

    # Read the original catalog content
    with open(args.input, 'r') as raw:
        content = [[field.strip() for field in line.split()] for line in raw]

    for line in content:
        if not data_complete(line):
            continue
        ra_degrees = float(line[4]) * 180 / math.pi
        ra_hours = deg_to_decimal_time(ra_degrees)
        dec_degrees = float(line[5]) * 180 / math.pi
        parallax = float(line[6]) if float(line[6]) > 0 else 0.0
        vmag = float(line[19])
        star = novas.make_cat_entry(line[0], "HIP", int(line[0]),
                                    ra_hours, dec_degrees, float(line[7]),
                                    float(line[8]), parallax, 0.0)

        star_con = novas.transform_cat(1, epoc_hip, star, jd_tt, "HP2")
        star_entry = CatEntry(star_con.starname, star_con.catalog,
                              star_con.starnumber, star_con.ra, star_con.dec,
                              star_con.promora, star_con.promodec,
                              star_con.parallax, star_con.radialvelocity, vmag)
        converted.append(star_entry)

    # Write new catalog into a file
    with open(args.output, mode='w') as csv_file:
        fieldnames = [
            'HIP_number', 'ra_degrees', 'dec_degrees', 'promora', 'promodec',
            'parallax', 'vmag'
        ]
        writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
        writer.writeheader()
        for star in converted:
            writer.writerow({
                'HIP_number':
                star.starnumber,
                'ra_degrees':
                "{0:.8f}".format(decimal_time_to_degrees(star.ra)),
                'dec_degrees':
                "{0:.8f}".format(star.dec),
                'promora':
                "{0:.8f}".format(star.promora),
                'promodec':
                "{0:.8f}".format(star.promodec),
                'parallax':
                "{0:.8f}".format(star.parallax),
                'vmag':
                "{0:.2f}".format(star.vmag),
            })
Beispiel #7
0
def to_julian_date(year, month, day):
    frac, d = math.modf(day)
    j = novas.julian_date(year, month, int(d), frac * 24)
    if j >= 2299159.5:  # start of Gregorian calendar, October 15, 1582
        return j
    # else compute correction for Julian calendar
    y = year - (14 - month) // 12
    return j + y // 100 - y // 400 - 2
Beispiel #8
0
    def calc_JD_UTC(date_string):

        (year, month, day) = date_string.split('-')
        hour = 0.0

        jd_utc = julian_date(int(year), int(month), int(day), hour)

        return jd_utc
Beispiel #9
0
def getOwlt(utc_time):
	'''Uses novas module to compute One Way Light Time at given UTC time.'''
	jd_start, jd_end, number = eph_manager.ephem_open()
	jd_tt = novas.julian_date(utc_time.tm_year, utc_time.tm_mon, utc_time.tm_mday, utc_time.tm_hour) 
	mars = novas.make_object(0, 4, 'Mars', None)
	ra, dec, dis = novas.astro_planet(jd_tt, mars)
	au_sec = 499.0047838061 # Light-time for one astronomical unit (AU) in seconds, from DE-405
	owlt = dis * au_sec
	return owlt
def main():
    jd_start, jd_end, number = eph_manager.ephem_open()
    output({}, """\
        'Auto-generated accuracy tests vs NOVAS (see build_novas_tests.py).'

        import pytest
        from numpy import abs, array, einsum, max
        from skyfield import (earthlib, framelib, nutationlib, positionlib,
                              precessionlib, starlib, timelib)
        from skyfield.api import JulianDate
        from skyfield.constants import AU_M
        from skyfield.functions import length_of
        from skyfield.jpllib import Ephemeris


        try:
            import de405
            de405 = Ephemeris(de405)
        except ImportError:
            pytestmark = pytest.mark.skipif(True, reason='de405 unavailable')

        one_second = 1.0 / 24.0 / 60.0 / 60.0
        arcsecond = 1.0 / 60.0 / 60.0
        ra_arcsecond = 24.0 / 360.0 / 60.0 / 60.0
        meter = 1.0 / AU_M

        def compare(value, expected_value, epsilon):
            if hasattr(value, 'shape') or hasattr(expected_value, 'shape'):
                assert max(abs(value - expected_value)) <= epsilon
            else:
                assert abs(value - expected_value) <= epsilon

        """)

    moon_landing = novas.julian_date(1969, 7, 20, 20.0 + 18.0/60.0)
    first_hubble_image = novas.julian_date(1990, 5, 20)
    voyager_intersellar = novas.julian_date(2012, 8, 25)

    date_vector = [moon_landing, first_hubble_image, T0, voyager_intersellar]
    dates = date_vector + [date_vector]

    output_subroutine_tests(dates)
    output_geocentric_tests(dates)
    output_topocentric_tests(dates)
def main():
    jd_start, jd_end, number = eph_manager.ephem_open()
    output({}, """\
        'Auto-generated accuracy tests vs NOVAS (see build_novas_tests.py).'

        from numpy import abs, array, einsum, max
        from skyfield import (earthlib, framelib, nutationlib, positionlib,
                              precessionlib, starlib, timelib)
        from skyfield.api import JulianDate
        from skyfield.constants import AU_M
        from skyfield.data import hipparcos
        from skyfield.functions import length_of
        from skyfield.jpllib import Ephemeris
        from skyfield.positionlib import Apparent

        import de405
        de405 = Ephemeris(de405)

        one_second = 1.0 / 24.0 / 60.0 / 60.0
        arcsecond = 1.0 / 60.0 / 60.0
        ra_arcsecond = 24.0 / 360.0 / 60.0 / 60.0
        meter = 1.0 / AU_M

        def compare(value, expected_value, epsilon):
            if hasattr(value, 'shape') or hasattr(expected_value, 'shape'):
                assert max(abs(value - expected_value)) <= epsilon
            else:
                assert abs(value - expected_value) <= epsilon

        """)

    moon_landing = novas.julian_date(1969, 7, 20, 20.0 + 18.0 / 60.0)
    first_hubble_image = novas.julian_date(1990, 5, 20)
    voyager_intersellar = novas.julian_date(2012, 8, 25)

    date_vector = [moon_landing, first_hubble_image, T0, voyager_intersellar]
    dates = date_vector + [date_vector]

    output_subroutine_tests(dates)
    output_geocentric_tests(dates)
    output_topocentric_tests(dates)
    output_catalog_tests(dates)
Beispiel #12
0
def V_LSR(RA, dec, dss, timedate):
    """
  Computes the velocity of the local standard of rest w.r.t. the observer
  
  @param ra : J2000 right ascension as a float or as "12h34m56.78s"
  @type  ra : float or str
  
  @param dec : J2000 declination as a float or as "-12d34m56.78s"
  @type  dec : float or str
  
  @param observer : DSN station
  @type  observer : int
  
  @param timedate : date/time of the observation
  @type  timedate : datetime object
  """
    logger.debug("V_LSR: entered with coord types %s and %s", type(RA),
                 type(dec))
    if type(RA) == str and type(dec) == str:
        skypos = coord.SkyCoord(RA, dec, unit=(u.hourangle, u.deg))
    elif type(RA) == float and type(dec) == float:
        skypos = coord.SkyCoord(RA * u.hour, dec * u.degree)
    else:
        raise RuntimeError(RA, dec, "cannot be parsed")
    logger.debug("V_LSR: sky pos: %s", skypos)
    ra2000, dec2000 = skypos.ra.hour, skypos.dec.deg
    logger.debug("V_LSR: J2000 coordinates are %f, %f", ra2000, dec2000)
    sourcename = "%5.2f%+5.2f" % (ra2000, dec2000)
    cat_entry = novas.make_cat_entry(sourcename, "", 0, ra2000, dec2000, 0, 0,
                                     0, 0)
    source = novas.make_object(2, 0, sourcename, cat_entry)
    station = Astronomy.DSN_coordinates.DSS(dss)
    logger.debug("V_LSR: station lat=%f", station.lat * 180 / math.pi)
    logger.debug("V_LSR: station long=%f", station.lon * 180 / math.pi)
    if station.long > math.pi:
        longitude = station.long - 2 * math.pi
    elif station.long < math.pi:
        longitude = station.long + 2 * math.pi
    else:
        longitude = station.long
    observer = novas.make_observer_on_surface(station.lat * 180 / math.pi,
                                              longitude * 180 / math.pi,
                                              station.elev, 0, 0)
    jd = novas.julian_date(timedate.year, timedate.month, timedate.day,
                           timedate.hour + timedate.minute / 60.)
    mjd = DatesTimes.MJD(timedate.year, timedate.month, timedate.day)
    earth = novas.make_object(0, 3, 'Earth', None)
    urthpos, urthvel = novas.ephemeris((jd, 0), earth, origin=0)
    (obspos, obsvel) = novas.geo_posvel(jd, 0, observer, 0)
    totvel = tuple(numpy.array(urthvel) + numpy.array(obsvel))
    (srcpos, srcvel) = novas.starvectors(cat_entry)
    V = novas.rad_vel(source, srcpos, srcvel, totvel, 0, 0, 0)
    logger.debug("V_LSR: velocity of observer w.r.t. Sun= %.2f", V)
    return V + Astronomy.v_sun(mjd, ra2000 / 15., dec2000)
 def test_julian_date(self):
     self.delta = 0.0
     for args in (
           (-4712, 1, 1, 0.0),
           (-4712, 3, 1, 0.0),
           (-4712, 12, 31, 0.5),
           (-241, 3, 25, 19.0),
           (530, 9, 27, 23.5),
           (1976, 3, 7, 12.5),
           (2000, 1, 1, 0.0),
           ):
         self.eq(c.julian_date(*args), timescales.julian_date(*args))
def test_julian_date():
    epsilon = 0.0
    for args in (
          (-4712, 1, 1, 0.0),
          (-4712, 3, 1, 0.0),
          (-4712, 12, 31, 0.5),
          (-241, 3, 25, 19.0),
          (530, 9, 27, 23.5),
          (1976, 3, 7, 12.5),
          (2000, 1, 1, 0.0),
          ):
        eq(c.julian_date(*args), timescales.julian_date(*args), epsilon)
Beispiel #15
0
def date2JD(dateObs):
    """
    Converts the date string to a JD floating point number, using the NOVAS routine
    The time scale of the returned value will be same as that of the input date.
    
    Parameters
    ----------
    RA      : string
    
    Returns
    -------
    degRA   : float
    
    Examples
    --------
    >>> ...
    
    """
    yr, mn, dy = parseDate(dateObs)
    if ' ' in dy:
        dy = dy.split(' ')[0]
    hr, dy = math.modf(float(dy))
    jd = novas.julian_date(int(yr), int(mn), int(dy), 24. * hr)
    return jd
try:
    import novas
    import novas_de405
except ImportError:
    novas = None
else:
    import novas.compat as c
    import novas.compat.eph_manager

    jd_start, jd_end, number = c.eph_manager.ephem_open()  # needs novas_de405

    c_nutation = c.nutation
    import novas.compat.nutation  # overwrites nutation() function with module!

    TA = c.julian_date(1969, 7, 20, 20. + 18. / 60.)
    TB = c.julian_date(2012, 12, 21)

    D0 = 63.8285
    DA = 39.707
    DB = 66.8779

    P0 = (T0, D0)  # "pair 0"
    PA = (TA, DA)
    PB = (TB, DB)

arcminute = DEG2RAD / 60.0
arcsecond = arcminute / 60.0
meter = 1.0 / AU_KM

planet_codes = {
from novas import compat as novas

print("INFO: Converting Oct 2, 2012 to Julian date...")
jd_tt = novas.julian_date(2012, 10, 2, 12.0)
print("OK: " + str(jd_tt))

Beispiel #18
0
        return True
    else:
        return False


dtheta = 0.0
leap_second = 37  #闰秒
tt_tai = 32.184  #tt和国际原子时tai之差
#EOP参数
ut1_utc = 0.06723
x_pole = -0.002
y_pole = +0.529
#tt-ut1
delta_t = tt_tai + leap_second - ut1_utc
#构造不同的儒略日时间变量
jd_utc = novas.julian_date(year, month, day, hour)  #utc
jd_ut1 = jd_utc + ut1_utc / 86400.0  #ut1
jd_tt = jd_utc + (leap_second + tt_tai) / 86400.0  #tt
jd = (jd_tt, 0.0)
jd0 = (jd_tt - ta / 86400, 0.0)
#打开de历表
jd_s, jd_e, num = eph_manager.ephem_open()
#太阳和地球构造
sun = novas.make_object(0, 10, 'sun', None)
moon = novas.make_object(0, 11, 'moon', None)
earth = novas.make_object(0, 3, 'earth', None)
#位置构造
location1 = novas.make_on_surface(latitude, longitude, height, 25.0, 1013)
location = novas.make_observer_on_surface(latitude, longitude, height, 25.0,
                                          1013)
#矢量和夹角初始化
try:
    import novas
    import novas_de405
except ImportError:
    novas = None
else:
    import novas.compat as c
    import novas.compat.eph_manager

    jd_start, jd_end, number = c.eph_manager.ephem_open()  # needs novas_de405

    c_nutation = c.nutation
    import novas.compat.nutation  # overwrites nutation() function with module!

    TA = c.julian_date(1969, 7, 20, 20. + 18. / 60.)
    TB = c.julian_date(2012, 12, 21)
    TC = c.julian_date(2027, 8, 2, 10. + 7. / 60. + 50. / 3600.)

    D0 = 63.8285
    DA = 39.707
    DB = 66.8779
    DC = 72.  # http://maia.usno.navy.mil/ser7/deltat.preds

    P0 = (T0, D0)  # "pair 0"
    PA = (TA, DA)
    PB = (TB, DB)

arcminute = DEG2RAD / 60.0
arcsecond = arcminute / 60.0
arcsecond_in_hours = 24.0 / 360.0 / 60.0 / 60.0
Beispiel #20
0
from novas import compat as novas
from novas.compat import eph_manager
jd_start, jd_end, number = eph_manager.ephem_open()

jd_tt = novas.julian_date(2013, 12, 27, 6.0)
print jd_tt

def print_planet(planet_name, planet_num):
    # make_object(type, number, name, star)
    # type = 0;major planet, Pluto, Sun, or Moon
    # type = 1; minor planet
    # type = 2; object located outside the soloar system
    # number; Mercury = 1, ..., Pluto = 9, Sun = 10, Moon = 11
    print planet_name
    planet = novas.make_object(0, planet_num, planet_name, None)
    ra, dec, dis = novas.astro_planet(jd_tt, planet)
    print 'R.A. %d:%02f' % (ra, abs(ra) % 1. * 60.)
    print 'dec. %d:%02f' % (dec, abs(dec) % 1. * 60.)
    print 'distance %f AU' % (dis,)

# Where is mars located.
print_planet('Mars', 4)

print_planet('Mercury', 1)
print_planet('Pluto', 9)
print_planet('Sun', 10)
print_planet('Moon', 11)
def output_subroutine_tests(dates):
    date_floats = [d for d in dates if not isinstance(d, list)]
    delta_t_floats = [+39.707, +57.1136, +63.8285, +66.7846]

    def shorter_cal_date(jd):
        y, m, d, h = novas.cal_date(jd)
        return y, m, d + h / 24.0 - 0.5

    for i, jd in enumerate(date_floats):
        cal_date = call(shorter_cal_date, jd)
        output(locals(), """\
            def test_calendar_date_{i}():
                compare(timelib.calendar_date({jd!r}), array({cal_date}), 0.0)
            """)

    for i, jd in enumerate(date_floats):
        angle = novas.era(jd)
        output(locals(), """\
            def test_earth_rotation_angle_date{i}():
                compare(earthlib.earth_rotation_angle({jd!r}), {angle},
                        0.000001 * arcsecond)
            """)

    for i, jd in enumerate(date_floats):
        angles = novas.e_tilt(jd)
        output(locals(), """\
            def test_earth_tilt_date{i}():
                compare(nutationlib.earth_tilt(JulianDate(tdb={jd!r})),
                        array({angles}), 0.00001 * arcsecond)
            """)

    for i, jd in enumerate(date_floats):
        terms = novas.ee_ct(jd, 0.0, 0)
        output(locals(), """\
            def test_equation_of_the_equinoxes_complimentary_terms_date{i}():
                compare(nutationlib.equation_of_the_equinoxes_complimentary_terms({jd!r}),
                        array({terms}), 0.0000000000000001 * arcsecond)
            """)

    vector = (1.1, 1.2, 1.3)
    tie1 = novas.frame_tie(vector, 0)
    tie2 = novas.frame_tie(vector, -1)
    output(locals(), """\
        def test_forward_frame_tie():
            compare(framelib.ICRS_to_J2000.dot({vector}), {tie1}, 1e-15)

        def test_reverse_frame_tie():
            compare(framelib.ICRS_to_J2000.T.dot({vector}), {tie2}, 1e-15)
        """)

    for i, jd in enumerate(date_floats):
        jcentury = (jd - T0) / 36525.0
        arguments = novas.fund_args(jcentury)
        output(locals(), """\
            def test_fundamental_arguments_date{i}():
                compare(nutationlib.fundamental_arguments({jcentury!r}),
                        array({arguments}), 0.000000001 * arcsecond)
            """)

    for i, jd in enumerate(date_floats):
        psi, eps = nutation_module.iau2000a(jd, 0.0)
        psi *= 1e7 / ASEC2RAD
        eps *= 1e7 / ASEC2RAD
        output(locals(), """\
            def test_iau2000a_date{i}():
                compare(nutationlib.iau2000a({jd!r}),
                        array([{psi}, {eps}]), 0.001)
            """)

    for i, args in enumerate([
          (-4712, 1, 1, 0.0),
          (-4712, 3, 1, 0.0),
          (-4712, 12, 31, 0.5),
          (-241, 3, 25, 19.0),
          (530, 9, 27, 23.5),
          (1976, 3, 7, 12.5),
          (2000, 1, 1, 0.0),
          ]):
        jd = novas.julian_date(*args)
        output(locals(), """\
            def test_julian_date_function_date{i}():
                compare(timelib.julian_date{args}, {jd!r}, 0.0)
            """)

    for i, jd in enumerate(date_floats):
        angle = novas.mean_obliq(jd)
        output(locals(), """\
            def test_mean_obliquity_date{i}():
                compare(nutationlib.mean_obliquity({jd!r}),
                        {angle!r}, 0.0)  # arcseconds
            """)

    for i, jd in enumerate(date_floats):
        vector = [1.1, 1.2, 1.3]
        result = nutation_function(jd, vector)
        output(locals(), """\
            def test_nutation_date{i}():
                matrix = nutationlib.compute_nutation(JulianDate(tdb={jd!r}))
                result = einsum('ij...,j...->i...', matrix, [1.1, 1.2, 1.3])
                compare({result},
                        result, 1e-14)
            """)

    for i, jd in enumerate(date_floats):
        vector = [1.1, 1.2, 1.3]
        result = novas.precession(T0, vector, jd)
        output(locals(), """\
            def test_precession_date{i}():
                matrix = precessionlib.compute_precession({jd!r})
                result = einsum('ij...,j...->i...', matrix, [1.1, 1.2, 1.3])
                compare({result},
                        result, 1e-15)
            """)

    for i, jd in enumerate(date_floats):
        result1 = novas.sidereal_time(jd, 0.0, 0.0, False, True)
        result2 = novas.sidereal_time(jd, 0.0, 99.9, False, True)
        output(locals(), """\
            def test_sidereal_time_on_date{i}():
                jd = JulianDate(tt={jd!r})
                compare(earthlib.sidereal_time(jd), {result1!r}, 1e-13)

            def test_sidereal_time_with_nonzero_delta_t_on_date{i}():
                jd = JulianDate(tt={jd!r} + 99.9 * one_second, delta_t=99.9)
                compare(earthlib.sidereal_time(jd), {result2!r}, 1e-13)
            """)

    p, v = novas.starvectors(novas.make_cat_entry(
        'POLARIS', 'HIP', 0, 2.530301028, 89.264109444,
        44.22, -11.75, 7.56, -17.4))
    output(locals(), """\
        def test_star_vector():
            star = starlib.Star(ra_hours=2.530301028, dec_degrees=89.264109444,
                                ra_mas_per_year=44.22, dec_mas_per_year=-11.75,
                                parallax_mas=7.56, radial_km_per_s=-17.4)
            compare(star._position,
                    {p},
                    1e3 * meter)
            compare(star._velocity,
                    {v},
                    1e-6 * meter)
        """)

    for i, (tt, delta_t) in enumerate(zip(date_floats, delta_t_floats)):
        jd_low = xp = yp = 0.0
        vector = [1.1, 1.2, 1.3]
        ut1 = tt - delta_t * one_second
        result = novas.ter2cel(ut1, jd_low, delta_t, xp, yp, vector)
        output(locals(), """\
            def test_ITRF_to_GCRS_conversion_on_date{i}():
                jd = JulianDate(tt={tt!r}, delta_t={delta_t!r})
                position = positionlib.ITRF_to_GCRS(jd, {vector!r})
                compare(position, {result!r}, 1e-13)
            """)

    for i, jd_tdb in enumerate(date_floats):
        result = novas.tdb2tt(jd_tdb)[1]
        output(locals(), """\
            def test_tdb_minus_tt_on_date{i}():
                result = timelib.tdb_minus_tt({jd_tdb!r})
                compare(result, {result!r}, 1e-16)
            """)
def output_subroutine_tests(dates):
    date_floats = [d for d in dates if not isinstance(d, list)]
    delta_t_floats = [+39.707, +57.1136, +63.8285, +66.7846]

    def shorter_cal_date(jd):
        y, m, d, h = novas.cal_date(jd)
        return y, m, d + h / 24.0 - 0.5

    for i, jd in enumerate(date_floats):
        cal_date = call(shorter_cal_date, jd)
        output(locals(), """\
            def test_calendar_date_{i}():
                compare(timelib.calendar_date({jd!r}), array({cal_date}), 0.0)
            """)

    for i, jd in enumerate(date_floats):
        angle = novas.era(jd)
        output(locals(), """\
            def test_earth_rotation_angle_date{i}():
                compare(earthlib.earth_rotation_angle({jd!r}) * 360.0, {angle},
                        0.000001 * arcsecond)
            """)

    for i, jd in enumerate(date_floats):
        angles = novas.e_tilt(jd)
        output(locals(), """\
            def test_earth_tilt_date{i}():
                compare(nutationlib.earth_tilt(JulianDate(tdb={jd!r})),
                        array({angles}), 0.00001 * arcsecond)
            """)

    for i, jd in enumerate(date_floats):
        terms = novas.ee_ct(jd, 0.0, 0)
        output(locals(), """\
            def test_equation_of_the_equinoxes_complimentary_terms_date{i}():
                compare(nutationlib.equation_of_the_equinoxes_complimentary_terms({jd!r}),
                        array({terms}), 0.0000000000000001 * arcsecond)
            """)

    vector = (1.1, 1.2, 1.3)
    tie1 = novas.frame_tie(vector, 0)
    tie2 = novas.frame_tie(vector, -1)
    output(locals(), """\
        def test_forward_frame_tie():
            compare(framelib.ICRS_to_J2000.dot({vector}), {tie1}, 1e-15)

        def test_reverse_frame_tie():
            compare(framelib.ICRS_to_J2000.T.dot({vector}), {tie2}, 1e-15)
        """)

    for i, jd in enumerate(date_floats):
        jcentury = (jd - T0) / 36525.0
        arguments = novas.fund_args(jcentury)
        output(locals(), """\
            def test_fundamental_arguments_date{i}():
                compare(nutationlib.fundamental_arguments({jcentury!r}),
                        array({arguments}), 0.000000002 * arcsecond)
            """)

    for i, jd in enumerate(date_floats):
        psi, eps = nutation_module.iau2000a(jd, 0.0)
        psi *= 1e7 / ASEC2RAD
        eps *= 1e7 / ASEC2RAD
        output(locals(), """\
            def test_iau2000a_date{i}():
                compare(nutationlib.iau2000a({jd!r}),
                        array([{psi}, {eps}]), 0.001)
            """)

    for i, args in enumerate([
          (-4712, 1, 1, 0.0),
          (-4712, 3, 1, 0.0),
          (-4712, 12, 31, 0.5),
          (-241, 3, 25, 19.0),
          (530, 9, 27, 23.5),
          (1976, 3, 7, 12.5),
          (2000, 1, 1, 0.0),
          ]):
        jd = novas.julian_date(*args)
        output(locals(), """\
            def test_julian_date_function_date{i}():
                compare(timelib.julian_date{args}, {jd!r}, 0.0)
            """)

    for i, jd in enumerate(date_floats):
        angle = novas.mean_obliq(jd)
        output(locals(), """\
            def test_mean_obliquity_date{i}():
                compare(nutationlib.mean_obliquity({jd!r}),
                        {angle!r}, 0.0)  # arcseconds
            """)

    for i, jd in enumerate(date_floats):
        vector = [1.1, 1.2, 1.3]
        result = nutation_function(jd, vector)
        output(locals(), """\
            def test_nutation_date{i}():
                matrix = nutationlib.compute_nutation(JulianDate(tdb={jd!r}))
                result = einsum('ij...,j...->i...', matrix, [1.1, 1.2, 1.3])
                compare({result},
                        result, 1e-14)
            """)

    for i, jd in enumerate(date_floats):
        vector = [1.1, 1.2, 1.3]
        result = novas.precession(T0, vector, jd)
        output(locals(), """\
            def test_precession_date{i}():
                matrix = precessionlib.compute_precession({jd!r})
                result = einsum('ij...,j...->i...', matrix, [1.1, 1.2, 1.3])
                compare({result},
                        result, 1e-15)
            """)

    for i, jd in enumerate(date_floats):
        result1 = novas.sidereal_time(jd, 0.0, 0.0, False, True)
        result2 = novas.sidereal_time(jd, 0.0, 99.9, False, True)
        output(locals(), """\
            def test_sidereal_time_on_date{i}():
                jd = JulianDate(tt={jd!r})
                compare(earthlib.sidereal_time(jd), {result1!r}, 1e-13)

            def test_sidereal_time_with_nonzero_delta_t_on_date{i}():
                jd = JulianDate(tt={jd!r} + 99.9 * one_second, delta_t=99.9)
                compare(earthlib.sidereal_time(jd), {result2!r}, 1e-13)
            """)

    p, v = novas.starvectors(novas.make_cat_entry(
        'POLARIS', 'HIP', 0, 2.530301028, 89.264109444,
        44.22, -11.75, 7.56, -17.4))
    output(locals(), """\
        def test_star_vector():
            star = starlib.Star(ra_hours=2.530301028, dec_degrees=89.264109444,
                                ra_mas_per_year=44.22, dec_mas_per_year=-11.75,
                                parallax_mas=7.56, radial_km_per_s=-17.4)
            star.au_km = de405.jplephemeris.AU
            star._compute_vectors()
            compare(star._position_au,
                    {p!r},
                    1e3 * meter)
            compare(star._velocity_au_per_d,
                    {v!r},
                    1e-3 * meter)  # TODO: was 1e-6 before switch to modern au
        """)

    atp = product([-5, -1, 15, 89.95], [10, 25], [1010, 1013.25])

    for i, (angle, temperature, pressure) in enumerate(atp):
        location = novas.make_on_surface(0.0, 0.0, 0, temperature, pressure)
        r = novas.refract(location, 90 - angle, 2)
        output(locals(), """\
            def test_refraction{i}():
                r = earthlib.refraction({angle}, {temperature}, {pressure})
                compare(r, {r}, 0.001 * arcsecond)
            """)

    northpole = novas.make_on_surface(90.0, 0.0, 0.0, 10.0, 1010.0)

    for i, angle in enumerate([-90, -2, -1, 0, 1, 3, 9, 90]):
        alt, az = altaz_maneuver(T0, northpole, 0.0, angle, ref=2)
        output(locals(), """\
            def test_refract{i}():
                alt = earthlib.refract({angle!r}, 10.0, 1010.0)
                compare(alt, {alt!r}, 0.000000001 * arcsecond)
            """)

    usno = novas.make_on_surface(38.9215, -77.0669, 92.0, 10.0, 1010.0)

    ra = 12.34
    for i, (tt, dec) in enumerate(product(date_floats, [56.78, -67.89])):
        alt, az = altaz_maneuver(tt, usno, ra, dec, ref=0)
        output(locals(), """\
            def test_from_altaz_{i}():
                jd = JulianDate(tt={tt!r})
                usno = de405.earth.topos(
                    '38.9215 N', '77.0669 W', elevation_m=92.0)
                a = usno(jd).from_altaz(alt_degrees={alt!r}, az_degrees={az!r})
                ra, dec, distance = a.radec(epoch=jd)
                compare(ra.hours, {ra!r}, 0.000000001 * arcsecond)
                compare(dec.degrees, {dec!r}, 0.000000001 * arcsecond)
            """)

    for i, (tt, delta_t) in enumerate(zip(date_floats, delta_t_floats)):
        jd_low = xp = yp = 0.0
        vector = [1.1, 1.2, 1.3]
        ut1 = tt - delta_t * one_second
        result = novas.ter2cel(ut1, jd_low, delta_t, xp, yp, vector)
        output(locals(), """\
            def test_ITRF_to_GCRS_conversion_on_date{i}():
                jd = JulianDate(tt={tt!r}, delta_t={delta_t!r})
                position = positionlib.ITRF_to_GCRS(jd, {vector!r})
                compare(position, {result!r}, 1e-13)
            """)

    for i, jd_tdb in enumerate(date_floats):
        result = novas.tdb2tt(jd_tdb)[1]
        output(locals(), """\
            def test_tdb_minus_tt_on_date{i}():
                result = timelib.tdb_minus_tt({jd_tdb!r})
                compare(result, {result!r}, 1e-16)
            """)
Beispiel #23
0
def date2JD(dateObs):
    yr = dateObs[0:4]
    mn = dateObs[5:7]
    frac, dy = math.modf(float(dateObs[8:]))
    jd = novas.julian_date(int(yr), int(mn), int(dy), 24. * frac)
    return jd
def output_subroutine_tests(dates):
    date_floats = [d for d in dates if not isinstance(d, list)]
    delta_t_floats = [+39.707, +57.1136, +63.8285, +66.7846]

    def shorter_cal_date(jd):
        y, m, d, h = novas.cal_date(jd)
        return y, m, d + h / 24.0 - 0.5

    for i, jd in enumerate(date_floats):
        cal_date = call(shorter_cal_date, jd)
        output(
            locals(), """\
            def test_calendar_date_{i}():
                compare(timelib.calendar_date({jd!r}), array({cal_date}), 0.0)
            """)

    for i, jd in enumerate(date_floats):
        angle = novas.era(jd)
        output(
            locals(), """\
            def test_earth_rotation_angle_date{i}():
                compare(earthlib.earth_rotation_angle({jd!r}) * 360.0, {angle!r},
                        0.000001 * arcsecond)
            """)

    for i, jd in enumerate(date_floats):
        angles = novas.e_tilt(jd)
        output(
            locals(), """\
            def test_earth_tilt_date{i}(ts):
                compare(nutationlib.earth_tilt(ts.tdb_jd({jd!r})),
                        array({angles}), 0.00001 * arcsecond)
            """)

    for i, jd in enumerate(date_floats):
        terms = novas.ee_ct(jd, 0.0, 0)
        output(
            locals(), """\
            def test_equation_of_the_equinoxes_complimentary_terms_date{i}():
                compare(nutationlib.equation_of_the_equinoxes_complimentary_terms({jd!r}),
                        array({terms!r}), 0.0000000000000001 * arcsecond)
            """)

    vector = (1.1, 1.2, 1.3)
    tie1 = novas.frame_tie(vector, 0)
    tie2 = novas.frame_tie(vector, -1)
    output(
        locals(), """\
        def test_forward_frame_tie():
            compare(framelib.ICRS_to_J2000.dot({vector}), {tie1}, 1e-15)

        def test_reverse_frame_tie():
            compare(framelib.ICRS_to_J2000.T.dot({vector}), {tie2}, 1e-15)
        """)

    for i, jd in enumerate(date_floats):
        jcentury = (jd - T0) / 36525.0
        arguments = novas.fund_args(jcentury)
        output(
            locals(), """\
            def test_fundamental_arguments_date{i}():
                compare(nutationlib.fundamental_arguments({jcentury!r}),
                        array({arguments}), 0.000000002 * arcsecond)
            """)

    for i, jd in enumerate(date_floats):
        psi, eps = nutation_module.iau2000a(jd, 0.0)
        psi *= 1e7 / ASEC2RAD
        eps *= 1e7 / ASEC2RAD
        output(
            locals(), """\
            def test_iau2000a_date{i}():
                compare(nutationlib.iau2000a({jd!r}),
                        array([{psi!r}, {eps!r}]), 0.001)
            """)

    for i, jd in enumerate(date_floats):
        psi, eps = nutation_module.iau2000b(jd, 0.0)
        psi *= 1e7 / ASEC2RAD
        eps *= 1e7 / ASEC2RAD
        output(
            locals(), """\
            def test_iau2000b_date{i}():
                compare(nutationlib.iau2000b({jd!r}),
                        array([{psi!r}, {eps!r}]), 0.001)
            """)

    for i, args in enumerate([
        (-4712, 1, 1, 0.0),
        (-4712, 3, 1, 0.0),
        (-4712, 12, 31, 0.5),
        (-241, 3, 25, 19.0),
        (530, 9, 27, 23.5),
        (1976, 3, 7, 12.5),
        (2000, 1, 1, 0.0),
    ]):
        jd = novas.julian_date(*args)
        output(
            locals(), """\
            def test_julian_date_function_date{i}():
                compare(timelib.julian_date{args}, {jd!r}, 0.0)
            """)

    for i, jd in enumerate(date_floats):
        angle = novas.mean_obliq(jd)
        output(
            locals(), """\
            def test_mean_obliquity_date{i}():
                compare(nutationlib.mean_obliquity({jd!r}),
                        {angle!r}, 0.0)  # arcseconds
            """)

    for i, jd in enumerate(date_floats):
        vector = [1.1, 1.2, 1.3]
        result = nutation_function(jd, vector)
        output(
            locals(), """\
            def test_nutation_date{i}(ts):
                matrix = nutationlib.compute_nutation(ts.tdb_jd({jd!r}))
                result = einsum('ij...,j...->i...', matrix, [1.1, 1.2, 1.3])
                compare({result},
                        result, 1e-14)
            """)

    for i, jd in enumerate(date_floats):
        vector = [1.1, 1.2, 1.3]
        result = novas.precession(T0, vector, jd)
        output(
            locals(), """\
            def test_precession_date{i}():
                matrix = precessionlib.compute_precession({jd!r})
                result = einsum('ij...,j...->i...', matrix, [1.1, 1.2, 1.3])
                compare({result},
                        result, 1e-15)
            """)

    for i, jd in enumerate(date_floats):
        result1 = novas.sidereal_time(jd, 0.0, 0.0, False, True)
        result2 = novas.sidereal_time(jd, 0.0, 99.9, False, True)
        output(
            locals(), """\
            def test_sidereal_time_on_date{i}():
                jd = load.timescale(delta_t=0.0).tt_jd({jd!r})
                compare(earthlib.sidereal_time(jd), {result1!r}, 1e-13)

            def test_sidereal_time_with_nonzero_delta_t_on_date{i}():
                jd = load.timescale(delta_t=99.9).tt_jd({jd!r} + 99.9 * one_second)
                compare(earthlib.sidereal_time(jd), {result2!r}, 1e-13)
            """)

    p, v = novas.starvectors(
        novas.make_cat_entry('POLARIS', 'HIP', 0, 2.530301028, 89.264109444,
                             44.22, -11.75, 7.56, -17.4))
    output(
        locals(), """\
        def test_star_vector():
            star = starlib.Star(ra_hours=2.530301028, dec_degrees=89.264109444,
                                ra_mas_per_year=44.22, dec_mas_per_year=-11.75,
                                parallax_mas=7.56, radial_km_per_s=-17.4)
            star.au_km = OLD_AU_KM
            star._compute_vectors()
            compare(star._position_au,
                    {p!r},
                    1e3 * meter)
            compare(star._velocity_au_per_d,
                    {v!r},
                    1e-3 * meter)  # TODO: was 1e-6 before switch to modern au
        """)

    atp = product([-5, -1, 15, 89.95], [10, 25], [1010, 1013.25])

    for i, (angle, temperature, pressure) in enumerate(atp):
        location = novas.make_on_surface(0.0, 0.0, 0, temperature, pressure)
        r = novas.refract(location, 90 - angle, 2)
        output(
            locals(), """\
            def test_refraction{i}():
                r = earthlib.refraction({angle}, {temperature}, {pressure})
                compare(r, {r!r}, 1e-9 * arcsecond)
            """)

    northpole = novas.make_on_surface(90.0, 0.0, 0.0, 10.0, 1010.0)

    for i, angle in enumerate([-90, -2, -1, 0, 1, 3, 9, 90]):
        alt, az = altaz_maneuver(T0, northpole, 0.0, angle, ref=2)
        output(
            locals(), """\
            def test_refract{i}():
                alt = earthlib.refract({angle!r}, 10.0, 1010.0)
                compare(alt, {alt!r}, 1e-9 * arcsecond)
            """)

    usno = novas.make_on_surface(38.9215, -77.0669, 92.0, 10.0, 1010.0)

    ra = 12.34
    for i, (tt, dec) in enumerate(product(date_floats, [56.78, -67.89])):
        alt, az = altaz_maneuver(tt, usno, ra, dec, ref=0)
        output(
            locals(), """\
            def test_from_altaz_{i}(earth):
                jd = load.timescale(delta_t=0.0).tt_jd({tt!r})
                usno = earth + Topos(
                    '38.9215 N', '77.0669 W', elevation_m=92.0)
                a = usno.at(jd).from_altaz(alt_degrees={alt!r}, az_degrees={az!r})
                ra, dec, distance = a.radec(epoch=jd)
                compare(ra.hours, {ra!r}, 1e-9 * arcsecond)
                compare(dec.degrees, {dec!r}, 1e-9 * arcsecond)
            """)

    for i, (tt, delta_t) in enumerate(zip(date_floats, delta_t_floats)):
        jd_low = xp = yp = 0.0
        vector = [1.1, 1.2, 1.3]
        ut1 = tt - delta_t * one_second
        result = novas.ter2cel(ut1, jd_low, delta_t, xp, yp, vector)
        output(
            locals(), """\
            def test_ITRF_to_GCRS_conversion_on_date{i}():
                jd = load.timescale(delta_t={delta_t!r}).tt_jd({tt!r})
                position = positionlib.ITRF_to_GCRS(jd, {vector!r})
                compare(position, {result!r}, 1e-13)
            """)

    for i, jd_tdb in enumerate(date_floats):
        result = novas.tdb2tt(jd_tdb)[1]
        output(
            locals(), """\
            def test_tdb_minus_tt_on_date{i}():
                result = timelib.tdb_minus_tt({jd_tdb!r})
                compare(result, {result!r}, 1e-16)
            """)
Beispiel #25
0
def yrmndy2JD(yrmndy):
    yr, mn, dy = yrmndy
    hr, dy = math.modf(float(dy))
    jd = novas.julian_date(int(yr), int(mn), int(dy), 24. * hr)
    return jd