Example #1
0
    def _xyzOpt(self, obs):
        """ calculates the heliocentric position of the observatory at UTC JD
        in equatorial cartesian coordinates.

        Note that for now it ignores polar motion, differences between TT and
        TDB, and differences between UTC and UT1.  The last is probably the
        biggest source of error.
        """
        key = (obs.cod, obs.jdutc)
        try:
            return self.cache[key]
        except KeyError:
            pass
        obsVec = self.siteXYZ[obs.cod]
        leaps = self.leapsec.getLeapSeconds(obs.jdutc)
        jd_tt = obs.jdutc + (32.184 + leaps) / (24.0 * 60 * 60)
        DUT1 = 0.0  # for now
        delta_t = 32.184 + leaps - DUT1
        jd_ut1 = obs.jdutc + DUT1
        xp, yp = 0.0, 0.0  # for now
        geocentric_vec = novas.ter2cel(jd_ut1, 0.0, delta_t, xp, yp, obsVec)
        geocentric_vec = Rearth_AU * numpy.array(geocentric_vec)
        pos = getEarthPosition(jd_tt)  # Might need to switch to tdb
        hc = (pos[0] + geocentric_vec[0],
            pos[1] + geocentric_vec[1], pos[2] + geocentric_vec[2])
        self.cache[key] = hc
        return hc
Example #2
0
    def getObservatoryPosition(self, obsCode, jd_utc):

        # If obsCode==None, set the observatory to be the geocenter
        if not obsCode:
            obsCode = '500'

        if (obsCode, jd_utc) in self.observatoryPositionCache:
            return self.observatoryPositionCache[(obsCode, jd_utc)]
    
        obsVec = self.ObservatoryXYZ[obsCode]

        if obsVec[0]==None:
            print "problem with obscode: ", obsCode
            return None, None, None
        else:

            jd_tdb  = EOP.jdTDB(jd_utc)
            pos = getEarthPosition(jd_tdb)

            if obsCode=='500':
                geocentric_vec = np.zeros(3)
            else:
                delta_t = EOP.delta_t(jd_utc)
                jd_ut1  = EOP.jdUT1(jd_utc)
                xp, yp  = EOP.pmx(jd_utc), EOP.pmy(jd_utc)

                geocentric_vec = Constants.Rearth_AU*np.array(novas.ter2cel(jd_ut1, 0.0, delta_t, xp, yp, obsVec))

            heliocentric_vec = pos+geocentric_vec
            self.observatoryPositionCache[(obsCode, jd_utc)] = heliocentric_vec
            return heliocentric_vec
    def getObservatoryPosition(self, obsCode, jd_utc, xyz=None):
        """
            
        The routine below calculates the HELIOCENTRIC position of the observatory
        in equatorial cartesian coordinates.
        
        Gets the HELIOCENTRIC position of the geocenter
        
        Offsets the input geocentric x,y,z to get the heliocentric x,y,z
        
        Parameters
        ----------
        
        Returns
        -------
        
        Examples
        --------
        >>> ...
        
        """

        # If obsCode==None, set the observatory to be the geocenter
        if not obsCode:
            obsCode = '500'

        if (obsCode, jd_utc) in self.observatoryPositionCache:
            return self.observatoryPositionCache[(obsCode, jd_utc)]

        obsVec = self.ObservatoryXYZ[obsCode]

        if obsVec[0] == None and xyz == None:
            #print("problem with obscode: ", obsCode)
            return None, None, None
        else:
            # Transform time
            jd_tdb = EOP.jdTDB(jd_utc)
            # HELIOCENTRIC posn of the Geocenter
            pos = getEarthPosition(jd_tdb)

            if obsCode == '500':
                geocentric_vec = np.zeros(3)
            elif xyz != None:
                geocentric_vec = xyz
            else:
                delta_t = EOP.delta_t(jd_utc)
                jd_ut1 = EOP.jdUT1(jd_utc)
                xp, yp = EOP.pmx(jd_utc), EOP.pmy(jd_utc)
                geocentric_vec = Constants.PHYS.Rearth_AU * np.array(
                    novas.ter2cel(jd_ut1, 0.0, delta_t, xp, yp, obsVec))

            # Offset pos (of observatory) from Geo- to Helio-centric
            heliocentric_vec = pos + geocentric_vec
            # There's no need to do this, just use ... # from functools import lru_cache
            self.observatoryPositionCache[(obsCode, jd_utc)] = heliocentric_vec
            return heliocentric_vec
def geo2itrs(longitude, latitude):
    E_T = [
        re * math.cos(latitude * constants.DEG2RAD) *
        math.cos(longitude * constants.DEG2RAD),
        re * math.cos(latitude * constants.DEG2RAD) *
        math.sin(longitude * constants.DEG2RAD),
        re * math.sin(latitude * constants.DEG2RAD)
    ]
    E_TT = novas.ter2cel(jd_ut1, 0.0, delta_t, x_pole, y_pole, E_T, 1, 0, 0)
    return E_TT
Example #5
0
def test_ter2cel(jd):
    jd_low = 0.0
    xp = yp = 0.0

    position = array([1.1, 1.2, 1.3])

    theirs = c.ter2cel(jd.ut1, jd_low, jd.delta_t, xp, yp, position)
    ours = positionlib.ITRF_to_GCRS(jd, position)

    epsilon = 1e-13  # 13 digits of agreement
    eq(theirs, ours, epsilon)
Example #6
0
    def getObservatoryPosition(self, obsCode, jd_utc, xyz=None):

        # If obsCode==None, set the observatory to be the geocenter
        if not obsCode:
            obsCode = '500'

        if (obsCode, jd_utc) in self.observatoryPositionCache:
            return self.observatoryPositionCache[(obsCode, jd_utc)]

        obsVec = self.ObservatoryXYZ[obsCode]

        if obsVec[0] == None and xyz == None:
            #print("problem with obscode: ", obsCode)
            return None, None, None
        else:

            jd_tdb = EOP.jdTDB(jd_utc)
            pos = getEarthBaryPosition(jd_tdb)  # Careful here with this change

            if obsCode == '500':
                geocentric_vec = np.zeros(3)
            elif xyz != None:
                geocentric_vec = xyz
            else:
                delta_t = EOP.delta_t(jd_utc)
                jd_ut1 = EOP.jdUT1(jd_utc)
                xp, yp = EOP.pmx(jd_utc), EOP.pmy(jd_utc)
                geocentric_vec = Constants.Rearth_AU * np.array(
                    novas.ter2cel(jd_ut1, 0.0, delta_t, xp, yp, obsVec))

            heliocentric_vec = pos + geocentric_vec
            self.observatoryPositionCache[(obsCode, jd_utc)] = heliocentric_vec
            return heliocentric_vec

        def getSatellitePosition(xyz, jd_utc):
            x, y, z = parseXYZ(xyz)
            x /= au_km
            y /= au_km
            z /= au_km
            jd_tdb = EOP.jdTDB(jd_utc)
            pos = getEarthPosition(jd_tdb)
            heliocentric_vec = pos[0] + x, pos[1] + y, pos[2] + z
            return heliocentric_vec
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)
            """)
Example #8
0
O1_S1 = [0.0, 0.0, 0.0]  #月球半影锥点到太阳质心矢量坐标
O2_S1 = [0.0, 0.0, 0.0]  #月球全影锥点到太阳质心矢量坐标
O1_E = [0.0, 0.0, 0.0]  #月球半影锥点到地心距离矢量坐标
O1_T = [0.0, 0.0, 0.0]  #月球半影锥点到地球某一点距离矢量坐标
O2_E = [0.0, 0.0, 0.0]  #月球全影锥点到地心距离矢量坐标
O2_T = [0.0, 0.0, 0.0]  #月球全影锥点到地球某一点距离矢量坐标
O1_M = [0.0, 0.0, 0.0]  #月球半影锥点到月心距离矢量坐标
O2_M = [0.0, 0.0, 0.0]  #月球全影锥点到月心距离矢量坐标
E_O4 = [0.0, 0.0, 0.0]
#经纬度转为ITRS下坐标
E_T=[re*math.cos(latitude*constants.DEG2RAD)*math.cos(longitude*constants.DEG2RAD),\
  re*math.cos(latitude*constants.DEG2RAD)*math.sin(longitude*constants.DEG2RAD),\
  re*math.sin(latitude*constants.DEG2RAD)\
     ]
#ITRS->GCRS
E_TT = novas.ter2cel(jd_ut1, 0.0, delta_t, x_pole, y_pole, E_T, 1, 0, 0)  #
thetaE_O1 = 0.0  #地球半径在半影锥点O1角距
thetaM_O1 = 0.0  #月球半径在半影锥点O1角距
thetaE_O2 = 0.0  #地球半径在全影锥点O2角距
thetaM_O2 = 0.0  #月球半径在全影锥点O2角距
thetaEM_O1 = 10.0  #地心和月心在月球半影锥点为原点的夹角
thetaTM_O1 = 10.0  #地球某一点和月心在月球半影锥点为原点的夹角
thetaEM_O2 = 1.0  #地心和月球在月心全影锥点为原点的夹角
thetaTM_O2 = 1.0  #地球某一点和月球在月心全影锥点为原点的夹角
O2_Elength = 1  #月球全影锥点可能在地球内部,需要判断,先赋初值足够大
O2E_re = 1  #月球全影锥点到地心距离和地球半径之差
#theta=constants.TWOPI
flag1 = 0  #日偏食开始结束标志,用来结束循环
flag2 = 0  #日全食发生标记
flag3 = 0  #日环食标记
flag4 = 0  #食甚标记
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)
            """)
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)
            """)