jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def test_orbitfit():
    from galpy.orbit import Orbit

    lp = potential.LogarithmicHaloPotential(normalize=1.0, q=0.9)
    o = Orbit([0.8, 0.3, 1.3, 0.4, 0.2, 2.0])
    ts = numpy.linspace(0.0, 1.0, 1001)
    o.integrate(ts, lp)
    # Create orbit points from this integrated orbit, each 100th point
    vxvv = o.getOrbit()[::100, :]
    # now fit
    of = Orbit.from_fit(o.vxvv[0], vxvv, pot=lp, tintJ=1.5)
    assert numpy.all(
        comp_orbfit(of, vxvv, numpy.linspace(0.0, 2.0, 1001), lp) < 10.0**-7.0
    ), "Orbit fit in configuration space does not work"
    return None
//  [python]
def test_setup_progIsTrack():
    # Test that setting up with progIsTrack=True gives a track that is very close to the given progenitor, such that it works as it should
    # Imports
    from galpy.actionAngle import actionAngleIsochroneApprox
    from galpy.df import streamdf
    from galpy.orbit import Orbit
    from galpy.potential import LogarithmicHaloPotential
    from galpy.util import conversion  # for unit conversions

    lp = LogarithmicHaloPotential(normalize=1.0, q=0.9)
    aAI = actionAngleIsochroneApprox(pot=lp, b=0.8)
    obs = Orbit(
        [1.56148083, 0.35081535, -1.15481504, 0.88719443, -0.47713334, 0.12019596],
        ro=8.0,
        vo=220.0,
    )
    sigv = 0.365  # km/s
    sdfp = streamdf(
        sigv / 220.0,
        progenitor=obs,
        pot=lp,
        aA=aAI,
        leading=True,
        nTrackChunks=11,
        tdisrupt=4.5 / conversion.time_in_Gyr(220.0, 8.0),
        progIsTrack=True,
    )
    assert n.all(
        n.fabs(obs.vxvv[0] - sdfp._ObsTrack[0, :]) < 10.0**-3.0
    ), "streamdf setup with progIsTrack does not return a track that is close to the given orbit at the start"
    # Integrate the orbit a little bit and test at a further point
    obs.integrate(n.linspace(0.0, 2.0, 10001), lp)
    indx = n.argmin(n.fabs(sdfp._interpolatedObsTrack[:, 0] - 1.75))
    oindx = n.argmin(n.fabs(obs.orbit[0, :, 0] - 1.75))
    assert n.all(
        n.fabs(sdfp._interpolatedObsTrack[indx, :5] - obs.orbit[0, oindx, :5])
        < 10.0**-2.0
    ), "streamdf setup with progIsTrack does not return a track that is close to the given orbit somewhat further from the start"
    return None
//  [python]
def test_setup_progIsTrack():
    # Test that setting up with progIsTrack=True gives a track that is very close to the given progenitor, such that it works as it should
    # Imports
    from galpy.actionAngle import actionAngleIsochroneApprox
    from galpy.df import streamdf
    from galpy.orbit import Orbit
    from galpy.potential import LogarithmicHaloPotential
    from galpy.util import conversion  # for unit conversions

    lp = LogarithmicHaloPotential(normalize=1.0, q=0.9)
    aAI = actionAngleIsochroneApprox(pot=lp, b=0.8)
    obs = Orbit(
        [1.56148083, 0.35081535, -1.15481504, 0.88719443, -0.47713334, 0.12019596],
        ro=8.0,
        vo=220.0,
    )
    sigv = 0.365  # km/s
    sdfp = streamdf(
        sigv / 220.0,
        progenitor=obs,
        pot=lp,
        aA=aAI,
        leading=True,
        nTrackChunks=11,
        tdisrupt=4.5 / conversion.time_in_Gyr(220.0, 8.0),
        progIsTrack=True,
    )
    assert numpy.all(
        numpy.fabs(obs.vxvv[0] - sdfp._ObsTrack[0, :]) < 10.0**-3.0
    ), "streamdf setup with progIsTrack does not return a track that is close to the given orbit at the start"
    # Integrate the orbit a little bit and test at a further point
    obs.integrate(numpy.linspace(0.0, 2.0, 10001), lp)
    indx = numpy.argmin(numpy.fabs(sdfp._interpolatedObsTrack[:, 0] - 1.75))
    oindx = numpy.argmin(numpy.fabs(obs.orbit[0, :, 0] - 1.75))
    assert numpy.all(
        numpy.fabs(sdfp._interpolatedObsTrack[indx, :5] - obs.orbit[0, oindx, :5])
        < 10.0**-2.0
    ), "streamdf setup with progIsTrack does not return a track that is close to the given orbit somewhat further from the start"
    return None
//  [python]
def test_getOrbit():
    from galpy.orbit import Orbit
    from galpy.potential import LogarithmicHaloPotential
    import numpy as n

    lp = LogarithmicHaloPotential(normalize=1.0, q=0.9)
    o = Orbit([1.0, 0.1, 1.2, 0.3, 0.2, 2.0])
    times = n.linspace(0.0, 7.0, 251)
    o.integrate(times, lp)
    Rs = o.R(times)
    vRs = o.vR(times)
    vTs = o.vT(times)
    zs = o.z(times)
    vzs = o.vz(times)
    phis = o.phi(times)
    orbarray = o.getOrbit()
    assert (
        n.all(n.fabs(Rs - orbarray[:, 0])) < 10.0**-16.0
    ), "getOrbit does not work as expected for R"
    assert (
        n.all(n.fabs(vRs - orbarray[:, 1])) < 10.0**-16.0
    ), "getOrbit does not work as expected for vR"
    assert (
        n.all(n.fabs(vTs - orbarray[:, 2])) < 10.0**-16.0
    ), "getOrbit does not work as expected for vT"
    assert (
        n.all(n.fabs(zs - orbarray[:, 3])) < 10.0**-16.0
    ), "getOrbit does not work as expected for z"
    assert (
        n.all(n.fabs(vzs - orbarray[:, 4])) < 10.0**-16.0
    ), "getOrbit does not work as expected for vz"
    assert (
        n.all(n.fabs(phis - orbarray[:, 5])) < 10.0**-16.0
    ), "getOrbit does not work as expected for phi"
    return None
//  [python]
def test_getOrbit():
    from galpy.orbit import Orbit
    from galpy.potential import LogarithmicHaloPotential

    lp = LogarithmicHaloPotential(normalize=1.0, q=0.9)
    o = Orbit([1.0, 0.1, 1.2, 0.3, 0.2, 2.0])
    times = numpy.linspace(0.0, 7.0, 251)
    o.integrate(times, lp)
    Rs = o.R(times)
    vRs = o.vR(times)
    vTs = o.vT(times)
    zs = o.z(times)
    vzs = o.vz(times)
    phis = o.phi(times)
    orbarray = o.getOrbit()
    assert (
        numpy.all(numpy.fabs(Rs - orbarray[:, 0])) < 10.0**-16.0
    ), "getOrbit does not work as expected for R"
    assert (
        numpy.all(numpy.fabs(vRs - orbarray[:, 1])) < 10.0**-16.0
    ), "getOrbit does not work as expected for vR"
    assert (
        numpy.all(numpy.fabs(vTs - orbarray[:, 2])) < 10.0**-16.0
    ), "getOrbit does not work as expected for vT"
    assert (
        numpy.all(numpy.fabs(zs - orbarray[:, 3])) < 10.0**-16.0
    ), "getOrbit does not work as expected for z"
    assert (
        numpy.all(numpy.fabs(vzs - orbarray[:, 4])) < 10.0**-16.0
    ), "getOrbit does not work as expected for vz"
    assert (
        numpy.all(numpy.fabs(phis - orbarray[:, 5])) < 10.0**-16.0
    ), "getOrbit does not work as expected for phi"
    return None
//  [python]
def test_orbitfit_potinput():
    from galpy.orbit import Orbit

    lp = potential.LogarithmicHaloPotential(normalize=1.0, q=0.9)
    o = Orbit([0.8, 0.3, 1.3, 0.4, 0.2, 2.0])
    ts = numpy.linspace(0.0, 1.0, 1001)
    o.integrate(ts, lp)
    # Create orbit points from this integrated orbit, each 100th point
    vxvv = o.getOrbit()[::100, :]
    # now fit, using another orbit instance, without potential, should error
    of = o()
    try:
        Orbit.from_fit(o.vxvv[0], vxvv, pot=None, tintJ=1.5)
    except AttributeError:
        pass
    else:
        raise AssertionError("Orbit fit w/o potential does not raise AttributeError")
    # Now give a potential to of
    of = Orbit.from_fit(o.vxvv[0], vxvv, pot=lp, tintJ=1.5)
    assert n.all(
        comp_orbfit(of, vxvv, numpy.linspace(0.0, 2.0, 1001), lp) < 10.0**-7.0
    ), "Orbit fit in configuration space does not work"
    return None
//  [python]
def test_orbitfit_potinput():
    from galpy.orbit import Orbit

    lp = potential.LogarithmicHaloPotential(normalize=1.0, q=0.9)
    o = Orbit([0.8, 0.3, 1.3, 0.4, 0.2, 2.0])
    ts = numpy.linspace(0.0, 1.0, 1001)
    o.integrate(ts, lp)
    # Create orbit points from this integrated orbit, each 100th point
    vxvv = o.getOrbit()[::100, :]
    # now fit, using another orbit instance, without potential, should error
    of = o()
    try:
        Orbit.from_fit(o.vxvv[0], vxvv, pot=None, tintJ=1.5)
    except AttributeError:
        pass
    else:
        raise AssertionError("Orbit fit w/o potential does not raise AttributeError")
    # Now give a potential to of
    of = Orbit.from_fit(o.vxvv[0], vxvv, pot=lp, tintJ=1.5)
    assert numpy.all(
        comp_orbfit(of, vxvv, numpy.linspace(0.0, 2.0, 1001), lp) < 10.0**-7.0
    ), "Orbit fit in configuration space does not work"
    return None
//  [python]
def test_time():
    # Setup orbit
    o = setup_orbit_energy(potential.MWPotential, axi=False)
    # Prior to integration, should return zero
    assert (
        numpy.fabs(o.time() - 0.0) < 10.0**-10.0
    ), "Orbit.time before integration does not return zero"
    # Then integrate
    times = numpy.linspace(0.0, 10.0, 1001)
    o.integrate(times, potential.MWPotential)
    assert n.all(
        (o.time() - times) < 10.0**-8.0
    ), "Orbit.time after integration does not return the integration times"
    return None
//  [python]
def test_time():
    # Setup orbit
    o = setup_orbit_energy(potential.MWPotential, axi=False)
    # Prior to integration, should return zero
    assert (
        numpy.fabs(o.time() - 0.0) < 10.0**-10.0
    ), "Orbit.time before integration does not return zero"
    # Then integrate
    times = numpy.linspace(0.0, 10.0, 1001)
    o.integrate(times, potential.MWPotential)
    assert numpy.all(
        (o.time() - times) < 10.0**-8.0
    ), "Orbit.time after integration does not return the integration times"
    return None
//  [python]
def test_orbitfit_lb():
    from galpy.orbit import Orbit

    lp = potential.LogarithmicHaloPotential(normalize=1.0, q=0.9)
    o = Orbit([0.8, 0.3, 1.3, 0.4, 0.2, 2.0])
    ts = numpy.linspace(0.0, 1.0, 1001)
    o.integrate(ts, lp)
    # Create orbit points from this integrated orbit, each 100th point
    vxvv = []
    for ii in range(10):
        vxvv.append(
            [
                o.ll(ii / 10.0),
                o.bb(ii / 10.0),
                o.dist(ii / 10.0),
                o.pmll(ii / 10.0),
                o.pmbb(ii / 10.0),
                o.vlos(ii / 10.0),
            ]
        )
    vxvv = numpy.array(vxvv)
    # now fit
    of = Orbit.from_fit(
        [o.ll(), o.bb(), o.dist(), o.pmll(), o.pmbb(), o.vlos()],
        vxvv,
        pot=lp,
        tintJ=1.5,
        lb=True,
        vxvv_err=0.01 * numpy.ones_like(vxvv),
    )
    compf = comp_orbfit(of, vxvv, numpy.linspace(0.0, 2.0, 1001), lp, lb=True)
    assert n.all(compf < 10.0**-4.0), "Orbit fit in lb space does not work"
    return None
//  [python]
def test_orbitfit_lb():
    from galpy.orbit import Orbit

    lp = potential.LogarithmicHaloPotential(normalize=1.0, q=0.9)
    o = Orbit([0.8, 0.3, 1.3, 0.4, 0.2, 2.0])
    ts = numpy.linspace(0.0, 1.0, 1001)
    o.integrate(ts, lp)
    # Create orbit points from this integrated orbit, each 100th point
    vxvv = []
    for ii in range(10):
        vxvv.append(
            [
                o.ll(ii / 10.0),
                o.bb(ii / 10.0),
                o.dist(ii / 10.0),
                o.pmll(ii / 10.0),
                o.pmbb(ii / 10.0),
                o.vlos(ii / 10.0),
            ]
        )
    vxvv = numpy.array(vxvv)
    # now fit
    of = Orbit.from_fit(
        [o.ll(), o.bb(), o.dist(), o.pmll(), o.pmbb(), o.vlos()],
        vxvv,
        pot=lp,
        tintJ=1.5,
        lb=True,
        vxvv_err=0.01 * numpy.ones_like(vxvv),
    )
    compf = comp_orbfit(of, vxvv, numpy.linspace(0.0, 2.0, 1001), lp, lb=True)
    assert numpy.all(compf < 10.0**-4.0), "Orbit fit in lb space does not work"
    return None
//  [python]
def test_orbitfit_radec():
    from galpy.orbit import Orbit

    lp = potential.LogarithmicHaloPotential(normalize=1.0, q=0.9)
    ro, vo = 9.0, 230.0
    o = Orbit([0.8, 0.3, 1.3, 0.4, 0.2, 2.0], ro=ro, vo=vo)
    ts = numpy.linspace(0.0, 1.0, 1001)
    o.integrate(ts, lp)
    # Create orbit points from this integrated orbit, each 100th point
    vxvv = []
    for ii in range(10):
        vxvv.append(
            [
                o.ra(ii / 10.0),
                o.dec(ii / 10.0),
                o.dist(ii / 10.0),
                o.pmra(ii / 10.0),
                o.pmdec(ii / 10.0),
                o.vlos(ii / 10.0),
            ]
        )
    vxvv = numpy.array(vxvv)
    # now fit
    of = Orbit.from_fit(
        [o.ra(), o.dec(), o.dist(), o.pmra(), o.pmdec(), o.vlos()],
        vxvv,
        pot=lp,
        tintJ=1.5,
        radec=True,
        ro=ro,
        vo=vo,
    )
    compf = comp_orbfit(
        of, vxvv, numpy.linspace(0.0, 2.0, 1001), lp, lb=False, radec=True, ro=ro, vo=vo
    )
    assert n.all(compf < 10.0**-4.0), "Orbit fit in radec space does not work"
    return None
//  [python]
def test_orbitfit_radec():
    from galpy.orbit import Orbit

    lp = potential.LogarithmicHaloPotential(normalize=1.0, q=0.9)
    ro, vo = 9.0, 230.0
    o = Orbit([0.8, 0.3, 1.3, 0.4, 0.2, 2.0], ro=ro, vo=vo)
    ts = numpy.linspace(0.0, 1.0, 1001)
    o.integrate(ts, lp)
    # Create orbit points from this integrated orbit, each 100th point
    vxvv = []
    for ii in range(10):
        vxvv.append(
            [
                o.ra(ii / 10.0),
                o.dec(ii / 10.0),
                o.dist(ii / 10.0),
                o.pmra(ii / 10.0),
                o.pmdec(ii / 10.0),
                o.vlos(ii / 10.0),
            ]
        )
    vxvv = numpy.array(vxvv)
    # now fit
    of = Orbit.from_fit(
        [o.ra(), o.dec(), o.dist(), o.pmra(), o.pmdec(), o.vlos()],
        vxvv,
        pot=lp,
        tintJ=1.5,
        radec=True,
        ro=ro,
        vo=vo,
    )
    compf = comp_orbfit(
        of, vxvv, numpy.linspace(0.0, 2.0, 1001), lp, lb=False, radec=True, ro=ro, vo=vo
    )
    assert numpy.all(compf < 10.0**-4.0), "Orbit fit in radec space does not work"
    return None
//  [python]
def test_callArgs(bovy14_setup):
    # Load the streamdf object
    sdf_bovy14 = bovy14_setup
    # Tests of _parse_call_args
    from galpy.orbit import Orbit

    # Just checking that different types of inputs give the same result
    trackp = 191
    RvR = sdf_bovy14._interpolatedObsTrack[trackp, :].flatten()
    OA = sdf_bovy14._interpolatedObsTrackAA[trackp, :].flatten()
    # RvR vs. array of OA
    s = numpy.ones(2)
    assert n.all(
        n.fabs(
            sdf_bovy14(RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5])
            - sdf_bovy14(
                OA[0] * s,
                OA[1] * s,
                OA[2] * s,
                OA[3] * s,
                OA[4] * s,
                OA[5] * s,
                aAInput=True,
            )
        )
        < 10.0**-8.0
    ), "__call__ w/ R,vR,... and equivalent O,theta,... does not give the same result"
    # RvR vs. OA
    assert (
        n.fabs(
            sdf_bovy14(RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5])
            - sdf_bovy14(OA[0], OA[1], OA[2], OA[3], OA[4], OA[5], aAInput=True)
        )
        < 10.0**-8.0
    ), "__call__ w/ R,vR,... and equivalent O,theta,... does not give the same result"
    # RvR vs. orbit
    assert (
        n.fabs(
            sdf_bovy14(RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5])
            - sdf_bovy14(Orbit([RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5]]))
        )
        < 10.0**-8.0
    ), "__call__ w/ R,vR,... and equivalent orbit does not give the same result"
    # RvR vs. list of orbit
    assert (
        n.fabs(
            sdf_bovy14(RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5])
            - sdf_bovy14([Orbit([RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5]])])
        )
        < 10.0**-8.0
    ), "__call__ w/ R,vR,... and equivalent list of orbit does not give the same result"
    # RvR w/ and w/o log
    assert (
        n.fabs(
            sdf_bovy14(RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5])
            - n.log(
                sdf_bovy14(RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5], log=False)
            )
        )
        < 10.0**-8.0
    ), "__call__ w/ R,vR,... log and not log does not give the same result"
    # RvR w/ explicit interp
    assert (
        n.fabs(
            sdf_bovy14(RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5])
            - sdf_bovy14(RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5], interp=True)
        )
        < 10.0**-8.0
    ), "__call__ w/ R,vR,... w/ explicit interp does not give the same result as w/o"
    # RvR w/o phi should raise error
    try:
        sdf_bovy14(RvR[0], RvR[1], RvR[2], RvR[3], RvR[4])
    except OSError:
        pass
    else:
        raise AssertionError("__call__ w/o phi does not raise IOError")
    return None
//  [python]
def test_callArgs(bovy14_setup):
    # Load the streamdf object
    sdf_bovy14 = bovy14_setup
    # Tests of _parse_call_args
    from galpy.orbit import Orbit

    # Just checking that different types of inputs give the same result
    trackp = 191
    RvR = sdf_bovy14._interpolatedObsTrack[trackp, :].flatten()
    OA = sdf_bovy14._interpolatedObsTrackAA[trackp, :].flatten()
    # RvR vs. array of OA
    s = numpy.ones(2)
    assert numpy.all(
        numpy.fabs(
            sdf_bovy14(RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5])
            - sdf_bovy14(
                OA[0] * s,
                OA[1] * s,
                OA[2] * s,
                OA[3] * s,
                OA[4] * s,
                OA[5] * s,
                aAInput=True,
            )
        )
        < 10.0**-8.0
    ), "__call__ w/ R,vR,... and equivalent O,theta,... does not give the same result"
    # RvR vs. OA
    assert (
        numpy.fabs(
            sdf_bovy14(RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5])
            - sdf_bovy14(OA[0], OA[1], OA[2], OA[3], OA[4], OA[5], aAInput=True)
        )
        < 10.0**-8.0
    ), "__call__ w/ R,vR,... and equivalent O,theta,... does not give the same result"
    # RvR vs. orbit
    assert (
        numpy.fabs(
            sdf_bovy14(RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5])
            - sdf_bovy14(Orbit([RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5]]))
        )
        < 10.0**-8.0
    ), "__call__ w/ R,vR,... and equivalent orbit does not give the same result"
    # RvR vs. list of orbit
    assert (
        numpy.fabs(
            sdf_bovy14(RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5])
            - sdf_bovy14([Orbit([RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5]])])
        )
        < 10.0**-8.0
    ), "__call__ w/ R,vR,... and equivalent list of orbit does not give the same result"
    # RvR w/ and w/o log
    assert (
        numpy.fabs(
            sdf_bovy14(RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5])
            - numpy.log(
                sdf_bovy14(RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5], log=False)
            )
        )
        < 10.0**-8.0
    ), "__call__ w/ R,vR,... log and not log does not give the same result"
    # RvR w/ explicit interp
    assert (
        numpy.fabs(
            sdf_bovy14(RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5])
            - sdf_bovy14(RvR[0], RvR[1], RvR[2], RvR[3], RvR[4], RvR[5], interp=True)
        )
        < 10.0**-8.0
    ), "__call__ w/ R,vR,... w/ explicit interp does not give the same result as w/o"
    # RvR w/o phi should raise error
    try:
        sdf_bovy14(RvR[0], RvR[1], RvR[2], RvR[3], RvR[4])
    except OSError:
        pass
    else:
        raise AssertionError("__call__ w/o phi does not raise IOError")
    return None
//  [python]
def test_backinterpolation_issue204():
    # Setup orbit and its flipped version
    o = setup_orbit_energy(potential.MWPotential, axi=False)
    of = o.flip()
    # Times to integrate backward and forward of flipped (should agree)
    ntimes = numpy.linspace(0.0, -10.0, 1001)
    ptimes = -ntimes
    # Integrate the orbits
    o.integrate(ntimes, potential.MWPotential)
    of.integrate(ptimes, potential.MWPotential)
    # Test that interpolation works and gives the same result
    nitimes = numpy.linspace(0.0, -10.0, 2501)
    pitimes = -nitimes
    assert n.all(
        (o.R(nitimes) - of.R(pitimes)) < 10.0**-8.0
    ), "Forward and backward integration with interpolation do not agree"
    assert n.all(
        (o.z(nitimes) - of.z(pitimes)) < 10.0**-8.0
    ), "Forward and backward integration with interpolation do not agree"
    # Velocities should be flipped
    assert n.all(
        (o.vR(nitimes) + of.vR(pitimes)) < 10.0**-8.0
    ), "Forward and backward integration with interpolation do not agree"
    assert n.all(
        (o.vT(nitimes) + of.vT(pitimes)) < 10.0**-8.0
    ), "Forward and backward integration with interpolation do not agree"
    assert n.all(
        (o.vT(nitimes) + of.vT(pitimes)) < 10.0**-8.0
    ), "Forward and backward integration with interpolation do not agree"
    return None
//  [python]
def test_backinterpolation_issue204():
    # Setup orbit and its flipped version
    o = setup_orbit_energy(potential.MWPotential, axi=False)
    of = o.flip()
    # Times to integrate backward and forward of flipped (should agree)
    ntimes = numpy.linspace(0.0, -10.0, 1001)
    ptimes = -ntimes
    # Integrate the orbits
    o.integrate(ntimes, potential.MWPotential)
    of.integrate(ptimes, potential.MWPotential)
    # Test that interpolation works and gives the same result
    nitimes = numpy.linspace(0.0, -10.0, 2501)
    pitimes = -nitimes
    assert numpy.all(
        (o.R(nitimes) - of.R(pitimes)) < 10.0**-8.0
    ), "Forward and backward integration with interpolation do not agree"
    assert numpy.all(
        (o.z(nitimes) - of.z(pitimes)) < 10.0**-8.0
    ), "Forward and backward integration with interpolation do not agree"
    # Velocities should be flipped
    assert numpy.all(
        (o.vR(nitimes) + of.vR(pitimes)) < 10.0**-8.0
    ), "Forward and backward integration with interpolation do not agree"
    assert numpy.all(
        (o.vT(nitimes) + of.vT(pitimes)) < 10.0**-8.0
    ), "Forward and backward integration with interpolation do not agree"
    assert numpy.all(
        (o.vT(nitimes) + of.vT(pitimes)) < 10.0**-8.0
    ), "Forward and backward integration with interpolation do not agree"
    return None
//  [python]
def test_orbinterp_reset_integrate():
    from galpy.orbit import Orbit
    from galpy.potential import MWPotential, MWPotential2014

    o = Orbit([1.0, 0.1, 1.1, 0.1, -0.03, numpy.pi])
    op = o()
    ts = numpy.linspace(0.0, 100.0, 10001)
    o.integrate(ts, MWPotential)
    o.R(numpy.linspace(0.0, o.t[-1], 1001))
    o.integrate(ts, MWPotential2014)
    op.integrate(ts, MWPotential2014)
    # If things are reset correctly, o and op should now agree on everything
    assert n.all(
        n.fabs(o.R(ts) - op.R(ts)) < 10.0**-10.0
    ), "Orbit R not reset correctly"
    assert n.all(
        n.fabs(o.vR(ts) - op.vR(ts)) < 10.0**-10.0
    ), "Orbit vR not reset correctly"
    assert n.all(
        n.fabs(o.vT(ts) - op.vT(ts)) < 10.0**-10.0
    ), "Orbit vT not reset correctly"
    assert n.all(
        n.fabs(o.z(ts) - op.z(ts)) < 10.0**-10.0
    ), "Orbit z not reset correctly"
    assert n.all(
        n.fabs(o.vz(ts) - op.vz(ts)) < 10.0**-10.0
    ), "Orbit vz not reset correctly"
    assert n.all(
        n.fabs(o.phi(ts) - op.phi(ts)) < 10.0**-10.0
    ), "Orbit phi not reset correctly"
    assert (
        n.fabs(o.rperi() - op.rperi()) < 10.0**-10.0
    ), "Orbit rperi not reset correctly"
    assert n.fabs(o.rap() - op.rap()) < 10.0**-10.0, "Orbit rap not reset correctly"
    assert n.fabs(o.e() - op.e()) < 10.0**-10.0, "Orbit e not reset correctly"
    return None
//  [python]
def test_orbinterp_reset_integrate():
    from galpy.orbit import Orbit
    from galpy.potential import MWPotential, MWPotential2014

    o = Orbit([1.0, 0.1, 1.1, 0.1, -0.03, numpy.pi])
    op = o()
    ts = numpy.linspace(0.0, 100.0, 10001)
    o.integrate(ts, MWPotential)
    o.R(numpy.linspace(0.0, o.t[-1], 1001))
    o.integrate(ts, MWPotential2014)
    op.integrate(ts, MWPotential2014)
    # If things are reset correctly, o and op should now agree on everything
    assert numpy.all(
        numpy.fabs(o.R(ts) - op.R(ts)) < 10.0**-10.0
    ), "Orbit R not reset correctly"
    assert numpy.all(
        numpy.fabs(o.vR(ts) - op.vR(ts)) < 10.0**-10.0
    ), "Orbit vR not reset correctly"
    assert numpy.all(
        numpy.fabs(o.vT(ts) - op.vT(ts)) < 10.0**-10.0
    ), "Orbit vT not reset correctly"
    assert numpy.all(
        numpy.fabs(o.z(ts) - op.z(ts)) < 10.0**-10.0
    ), "Orbit z not reset correctly"
    assert numpy.all(
        numpy.fabs(o.vz(ts) - op.vz(ts)) < 10.0**-10.0
    ), "Orbit vz not reset correctly"
    assert numpy.all(
        numpy.fabs(o.phi(ts) - op.phi(ts)) < 10.0**-10.0
    ), "Orbit phi not reset correctly"
    assert (
        numpy.fabs(o.rperi() - op.rperi()) < 10.0**-10.0
    ), "Orbit rperi not reset correctly"
    assert numpy.fabs(o.rap() - op.rap()) < 10.0**-10.0, "Orbit rap not reset correctly"
    assert numpy.fabs(o.e() - op.e()) < 10.0**-10.0, "Orbit e not reset correctly"
    return None
//  [python]
def test_SkyCoord():
    from astropy import units

    from galpy.orbit import Orbit

    # In ra, dec
    o = Orbit([120.0, 60.0, 2.0, 0.5, 0.4, 30.0], radec=True)
    assert (
        numpy.fabs(o.SkyCoord().ra.degree - o.ra()) < 10.0**-13.0
    ), "Orbit SkyCoord ra and direct ra do not agree"
    assert (
        numpy.fabs(o.SkyCoord().dec.degree - o.dec()) < 10.0**-13.0
    ), "Orbit SkyCoord dec and direct dec do not agree"
    assert (
        numpy.fabs(o.SkyCoord().distance.kpc - o.dist()) < 10.0**-13.0
    ), "Orbit SkyCoord distance and direct distance do not agree"
    # For a list
    o = Orbit([120.0, 60.0, 2.0, 0.5, 0.4, 30.0], radec=True)
    times = numpy.linspace(0.0, 2.0, 51)
    from galpy.potential import MWPotential

    o.integrate(times, MWPotential)
    ras = numpy.array([s.ra.degree for s in o.SkyCoord(times)])
    decs = numpy.array([s.dec.degree for s in o.SkyCoord(times)])
    dists = numpy.array([s.distance.kpc for s in o.SkyCoord(times)])
    assert numpy.all(
        numpy.fabs(ras - o.ra(times)) < 10.0**-13.0
    ), "Orbit SkyCoord ra and direct ra do not agree"
    assert numpy.all(
        numpy.fabs(decs - o.dec(times)) < 10.0**-13.0
    ), "Orbit SkyCoord dec and direct dec do not agree"
    assert numpy.all(
        numpy.fabs(dists - o.dist(times)) < 10.0**-13.0
    ), "Orbit SkyCoord distance and direct distance do not agree"
    # Check that the GC frame parameters are correctly propagated
    if not _APY3:
        return None  # not done in python 2
    o = Orbit(
        [120.0, 60.0, 2.0, 0.5, 0.4, 30.0],
        radec=True,
        ro=10.0,
        zo=1.0,
        solarmotion=[-10.0, 34.0, 12.0],
    )
    assert (
        numpy.fabs(
            o.SkyCoord().galcen_distance.to(units.kpc).value
            - numpy.sqrt(10.0**2.0 + 1.0**2.0)
        )
        < 10.0**-13.0
    ), "Orbit SkyCoord GC frame attributes are incorrect"
    assert (
        numpy.fabs(o.SkyCoord().z_sun.to(units.kpc).value - 1.0) < 10.0**-13.0
    ), "Orbit SkyCoord GC frame attributes are incorrect"
    assert numpy.all(
        numpy.fabs(
            o.SkyCoord().galcen_v_sun.d_xyz.to(units.km / units.s).value
            - numpy.array([10.0, 220.0 + 34.0, 12.0])
        )
        < 10.0**-13.0
    ), "Orbit SkyCoord GC frame attributes are incorrect"
    return None
//  [python]
def test_from_name_named():
    # Test that the values from the JSON file are correctly transferred
    import json

    # Read the JSON file
    import os

    import galpy.orbit
    from galpy.orbit import Orbit

    named_objects_file = os.path.join(
        os.path.dirname(os.path.realpath(galpy.orbit.__file__)), "named_objects.json"
    )
    with open(named_objects_file) as json_file:
        named_data = json.load(json_file)
    del named_data["_collections"]
    del named_data["_synonyms"]
    for obj in named_data:
        o = Orbit.from_name(obj)
        for attr in named_data[obj]:
            if "source" in attr or "dr2" in attr:
                continue
            # Skip entries with missing vlos for now
            if numpy.isnan(named_data[obj]["vlos"]):
                continue
            # Skip errors until we use them
            if attr == "pmcorr" or "_e" in attr:
                continue
            if attr == "ro" or attr == "vo" or attr == "zo" or attr == "solarmotion":
                assert n.all(
                    n.isclose(getattr(o, f"_{attr:s}"), named_data[obj][attr])
                )
            elif attr == "distance":
                assert n.isclose(o.dist(), named_data[obj][attr])
            else:
                assert n.isclose(getattr(o, f"{attr:s}")(), named_data[obj][attr])
    return None
//  [python]
def test_from_name_named():
    # Test that the values from the JSON file are correctly transferred
    import json

    # Read the JSON file
    import os

    import galpy.orbit
    from galpy.orbit import Orbit

    named_objects_file = os.path.join(
        os.path.dirname(os.path.realpath(galpy.orbit.__file__)), "named_objects.json"
    )
    with open(named_objects_file) as json_file:
        named_data = json.load(json_file)
    del named_data["_collections"]
    del named_data["_synonyms"]
    for obj in named_data:
        o = Orbit.from_name(obj)
        for attr in named_data[obj]:
            if "source" in attr or "dr2" in attr:
                continue
            # Skip entries with missing vlos for now
            if numpy.isnan(named_data[obj]["vlos"]):
                continue
            # Skip errors until we use them
            if attr == "pmcorr" or "_e" in attr:
                continue
            if attr == "ro" or attr == "vo" or attr == "zo" or attr == "solarmotion":
                assert numpy.all(
                    numpy.isclose(getattr(o, f"_{attr:s}"), named_data[obj][attr])
                )
            elif attr == "distance":
                assert numpy.isclose(o.dist(), named_data[obj][attr])
            else:
                assert numpy.isclose(getattr(o, f"{attr:s}")(), named_data[obj][attr])
    return None
//  [python]
def test_orbinterp_reset_integrateSOS():
    from galpy.orbit import Orbit
    from galpy.potential import MWPotential, MWPotential2014

    o = Orbit([1.0, 0.1, 1.1, 0.1, -0.03, numpy.pi])
    op = o()
    ts = numpy.linspace(0.0, 100.0, 10001)
    psis = numpy.linspace(0.0, 100.0, 10001)
    o.integrate(ts, MWPotential)
    o.R(numpy.linspace(0.0, o.t[-1], 1001))
    o.integrate_SOS(psis, MWPotential2014)
    op.integrate_SOS(psis, MWPotential2014)
    ts = o.t
    # If things are reset correctly, o and op should now agree on everything
    assert n.all(
        n.fabs(o.R(ts) - op.R(ts)) < 10.0**-10.0
    ), "Orbit R not reset correctly"
    assert n.all(
        n.fabs(o.vR(ts) - op.vR(ts)) < 10.0**-10.0
    ), "Orbit vR not reset correctly"
    assert n.all(
        n.fabs(o.vT(ts) - op.vT(ts)) < 10.0**-10.0
    ), "Orbit vT not reset correctly"
    assert n.all(
        n.fabs(o.z(ts) - op.z(ts)) < 10.0**-10.0
    ), "Orbit z not reset correctly"
    assert n.all(
        n.fabs(o.vz(ts) - op.vz(ts)) < 10.0**-10.0
    ), "Orbit vz not reset correctly"
    assert n.all(
        n.fabs(o.phi(ts) - op.phi(ts)) < 10.0**-10.0
    ), "Orbit phi not reset correctly"
    assert (
        n.fabs(o.rperi() - op.rperi()) < 10.0**-10.0
    ), "Orbit rperi not reset correctly"
    assert n.fabs(o.rap() - op.rap()) < 10.0**-10.0, "Orbit rap not reset correctly"
    assert n.fabs(o.e() - op.e()) < 10.0**-10.0, "Orbit e not reset correctly"
    return None
//  [python]
def test_orbinterp_reset_integrateSOS():
    from galpy.orbit import Orbit
    from galpy.potential import MWPotential, MWPotential2014

    o = Orbit([1.0, 0.1, 1.1, 0.1, -0.03, numpy.pi])
    op = o()
    ts = numpy.linspace(0.0, 100.0, 10001)
    psis = numpy.linspace(0.0, 100.0, 10001)
    o.integrate(ts, MWPotential)
    o.R(numpy.linspace(0.0, o.t[-1], 1001))
    o.integrate_SOS(psis, MWPotential2014)
    op.integrate_SOS(psis, MWPotential2014)
    ts = o.t
    # If things are reset correctly, o and op should now agree on everything
    assert numpy.all(
        numpy.fabs(o.R(ts) - op.R(ts)) < 10.0**-10.0
    ), "Orbit R not reset correctly"
    assert numpy.all(
        numpy.fabs(o.vR(ts) - op.vR(ts)) < 10.0**-10.0
    ), "Orbit vR not reset correctly"
    assert numpy.all(
        numpy.fabs(o.vT(ts) - op.vT(ts)) < 10.0**-10.0
    ), "Orbit vT not reset correctly"
    assert numpy.all(
        numpy.fabs(o.z(ts) - op.z(ts)) < 10.0**-10.0
    ), "Orbit z not reset correctly"
    assert numpy.all(
        numpy.fabs(o.vz(ts) - op.vz(ts)) < 10.0**-10.0
    ), "Orbit vz not reset correctly"
    assert numpy.all(
        numpy.fabs(o.phi(ts) - op.phi(ts)) < 10.0**-10.0
    ), "Orbit phi not reset correctly"
    assert (
        numpy.fabs(o.rperi() - op.rperi()) < 10.0**-10.0
    ), "Orbit rperi not reset correctly"
    assert numpy.fabs(o.rap() - op.rap()) < 10.0**-10.0, "Orbit rap not reset correctly"
    assert numpy.fabs(o.e() - op.e()) < 10.0**-10.0, "Orbit e not reset correctly"
    return None
//  [python]
def test_orbinterp_reset_integratedxdv():
    from galpy.orbit import Orbit
    from galpy.potential import MWPotential, MWPotential2014

    o = Orbit([1.0, 0.1, 1.1, numpy.pi])
    op = o()
    ts = numpy.linspace(0.0, 100.0, 10001)
    o.integrate_dxdv([1.0, 0.0, 0.0, 0.0], ts, MWPotential)
    o.R(numpy.linspace(0.0, o.t[-1], 1001))
    o.integrate_dxdv([1.0, 0.0, 0.0, 0.0], ts, MWPotential2014)
    op.integrate_dxdv([1.0, 0.0, 0.0, 0.0], ts, MWPotential2014)
    # If things are reset correctly, o and op should now agree on everything
    assert n.all(
        n.fabs(o.R(ts) - op.R(ts)) < 10.0**-10.0
    ), "Orbit R not reset correctly"
    assert n.all(
        n.fabs(o.vR(ts) - op.vR(ts)) < 10.0**-10.0
    ), "Orbit vR not reset correctly"
    assert n.all(
        n.fabs(o.vT(ts) - op.vT(ts)) < 10.0**-10.0
    ), "Orbit vT not reset correctly"
    assert n.all(
        n.fabs(o.phi(ts) - op.phi(ts)) < 10.0**-10.0
    ), "Orbit phi not reset correctly"
    assert (
        n.fabs(o.rperi() - op.rperi()) < 10.0**-10.0
    ), "Orbit rperi not reset correctly"
    assert n.fabs(o.rap() - op.rap()) < 10.0**-10.0, "Orbit rap not reset correctly"
    assert n.fabs(o.e() - op.e()) < 10.0**-10.0, "Orbit e not reset correctly"
    return None
//  [python]
def test_orbinterp_reset_integratedxdv():
    from galpy.orbit import Orbit
    from galpy.potential import MWPotential, MWPotential2014

    o = Orbit([1.0, 0.1, 1.1, numpy.pi])
    op = o()
    ts = numpy.linspace(0.0, 100.0, 10001)
    o.integrate_dxdv([1.0, 0.0, 0.0, 0.0], ts, MWPotential)
    o.R(numpy.linspace(0.0, o.t[-1], 1001))
    o.integrate_dxdv([1.0, 0.0, 0.0, 0.0], ts, MWPotential2014)
    op.integrate_dxdv([1.0, 0.0, 0.0, 0.0], ts, MWPotential2014)
    # If things are reset correctly, o and op should now agree on everything
    assert numpy.all(
        numpy.fabs(o.R(ts) - op.R(ts)) < 10.0**-10.0
    ), "Orbit R not reset correctly"
    assert numpy.all(
        numpy.fabs(o.vR(ts) - op.vR(ts)) < 10.0**-10.0
    ), "Orbit vR not reset correctly"
    assert numpy.all(
        numpy.fabs(o.vT(ts) - op.vT(ts)) < 10.0**-10.0
    ), "Orbit vT not reset correctly"
    assert numpy.all(
        numpy.fabs(o.phi(ts) - op.phi(ts)) < 10.0**-10.0
    ), "Orbit phi not reset correctly"
    assert (
        numpy.fabs(o.rperi() - op.rperi()) < 10.0**-10.0
    ), "Orbit rperi not reset correctly"
    assert numpy.fabs(o.rap() - op.rap()) < 10.0**-10.0, "Orbit rap not reset correctly"
    assert numpy.fabs(o.e() - op.e()) < 10.0**-10.0, "Orbit e not reset correctly"
    return None
//  [python]
def test_orbinterp_reset_bruteSOS():
    from galpy.orbit import Orbit
    from galpy.potential import MWPotential, MWPotential2014

    o = Orbit([1.0, 0.1, 1.1, 0.1, -0.03, numpy.pi])
    op = o()
    ts = numpy.linspace(0.0, 100.0, 10001)
    ts2 = numpy.linspace(0.0, 99.0, 10001)
    o.integrate(ts, MWPotential)
    o.R(numpy.linspace(0.0, o.t[-1], 1001))
    o.bruteSOS(ts2, MWPotential2014)
    op.bruteSOS(ts2, MWPotential2014)
    ts = o.t
    # If things are reset correctly, o and op should now agree on everything
    assert n.all(
        n.fabs(o.R(ts) - op.R(ts)) < 10.0**-10.0
    ), "Orbit R not reset correctly"
    assert n.all(
        n.fabs(o.vR(ts) - op.vR(ts)) < 10.0**-10.0
    ), "Orbit vR not reset correctly"
    assert n.all(
        n.fabs(o.vT(ts) - op.vT(ts)) < 10.0**-10.0
    ), "Orbit vT not reset correctly"
    assert n.all(
        n.fabs(o.z(ts) - op.z(ts)) < 10.0**-10.0
    ), "Orbit z not reset correctly"
    assert n.all(
        n.fabs(o.vz(ts) - op.vz(ts)) < 10.0**-10.0
    ), "Orbit vz not reset correctly"
    assert n.all(
        n.fabs(o.phi(ts) - op.phi(ts)) < 10.0**-10.0
    ), "Orbit phi not reset correctly"
    assert (
        n.fabs(o.rperi() - op.rperi()) < 10.0**-10.0
    ), "Orbit rperi not reset correctly"
    assert n.fabs(o.rap() - op.rap()) < 10.0**-10.0, "Orbit rap not reset correctly"
    assert n.fabs(o.e() - op.e()) < 10.0**-10.0, "Orbit e not reset correctly"
    return None
//  [python]
def test_orbinterp_reset_bruteSOS():
    from galpy.orbit import Orbit
    from galpy.potential import MWPotential, MWPotential2014

    o = Orbit([1.0, 0.1, 1.1, 0.1, -0.03, numpy.pi])
    op = o()
    ts = numpy.linspace(0.0, 100.0, 10001)
    ts2 = numpy.linspace(0.0, 99.0, 10001)
    o.integrate(ts, MWPotential)
    o.R(numpy.linspace(0.0, o.t[-1], 1001))
    o.bruteSOS(ts2, MWPotential2014)
    op.bruteSOS(ts2, MWPotential2014)
    ts = o.t
    # If things are reset correctly, o and op should now agree on everything
    assert numpy.all(
        numpy.fabs(o.R(ts) - op.R(ts)) < 10.0**-10.0
    ), "Orbit R not reset correctly"
    assert numpy.all(
        numpy.fabs(o.vR(ts) - op.vR(ts)) < 10.0**-10.0
    ), "Orbit vR not reset correctly"
    assert numpy.all(
        numpy.fabs(o.vT(ts) - op.vT(ts)) < 10.0**-10.0
    ), "Orbit vT not reset correctly"
    assert numpy.all(
        numpy.fabs(o.z(ts) - op.z(ts)) < 10.0**-10.0
    ), "Orbit z not reset correctly"
    assert numpy.all(
        numpy.fabs(o.vz(ts) - op.vz(ts)) < 10.0**-10.0
    ), "Orbit vz not reset correctly"
    assert numpy.all(
        numpy.fabs(o.phi(ts) - op.phi(ts)) < 10.0**-10.0
    ), "Orbit phi not reset correctly"
    assert (
        numpy.fabs(o.rperi() - op.rperi()) < 10.0**-10.0
    ), "Orbit rperi not reset correctly"
    assert numpy.fabs(o.rap() - op.rap()) < 10.0**-10.0, "Orbit rap not reset correctly"
    assert numpy.fabs(o.e() - op.e()) < 10.0**-10.0, "Orbit e not reset correctly"
    return None
//  [python]
def test_phi_range():
    # Test that the range returned by Orbit.phi is [-pi,pi],
    # example from Jeremy Webb
    from galpy.orbit import Orbit
    from galpy.potential import MWPotential2014
    import numpy as n

    o = Orbit()
    ts = n.linspace(0.0, -30, 5000)
    o.integrate(ts, MWPotential2014)
    assert n.all(o.phi(ts) <= n.pi), "o.phi does not return values <= pi"
    assert n.all(o.phi(ts) >= -n.pi), "o.phi does not return values >= pi"
    assert n.all(o.phi(ts[::-1]) <= n.pi), "o.phi does not return values <= pi"
    assert n.all(o.phi(ts[::-1]) >= -n.pi), "o.phi does not return values >= pi"
    # Also really interpolated
    its = n.linspace(0.0, -30, 5001)
    assert n.all(o.phi(its) <= n.pi), "o.phi does not return values <= pi"
    assert n.all(o.phi(its) >= -n.pi), "o.phi does not return values >= pi"
    return None
//  [python]
def test_phi_range():
    # Test that the range returned by Orbit.phi is [-pi,pi],
    # example from Jeremy Webb
    from galpy.orbit import Orbit
    from galpy.potential import MWPotential2014

    o = Orbit()
    ts = numpy.linspace(0.0, -30, 5000)
    o.integrate(ts, MWPotential2014)
    assert numpy.all(o.phi(ts) <= numpy.pi), "o.phi does not return values <= pi"
    assert numpy.all(o.phi(ts) >= -numpy.pi), "o.phi does not return values >= pi"
    assert numpy.all(o.phi(ts[::-1]) <= numpy.pi), "o.phi does not return values <= pi"
    assert numpy.all(o.phi(ts[::-1]) >= -numpy.pi), "o.phi does not return values >= pi"
    # Also really interpolated
    its = numpy.linspace(0.0, -30, 5001)
    assert numpy.all(o.phi(its) <= numpy.pi), "o.phi does not return values <= pi"
    assert numpy.all(o.phi(its) >= -numpy.pi), "o.phi does not return values >= pi"
    return None
//  [python]
def test_device_get_scalar(self):
    x = np.arange(12.).reshape((3, 4)).astype("float32")
    x = api.device_put(x)
    _check_instance(self, x)
    self.assertIsInstance(x.sharding, jax.sharding.SingleDeviceSharding)
    for s in x.addressable_shards:
      self.assertArraysEqual(s.data, x)
      self.assertEqual(s.replica_id, 0)
      self.assertEqual(s.index, (slice(None), slice(None)))
    y = [x, 2]
    y2 = api.device_get(y)
    self.assertIsInstance(y2, list)
    self.assertIsInstance(y2[0], np.ndarray)
    assert np.all(y2[0] == x)
    self.assertIsInstance(y2[1], int)
    self.assertEqual(y2[1], 2)
//  [python]
def issequence(x):
    """Test whether x is a sequence of numbers

    Parameters
    ----------
    x : sequence to test

    """
    out = True
    try:
        # can we get a length on the object
        len(x)
    except TypeError:
        return False
    # is the object not a string?
    out = n.all(n.isreal(x))
    return out
//  [python]
def issequence(x):
    """Test whether x is a sequence of numbers

    Parameters
    ----------
    x : sequence to test

    """
    out = True
    try:
        # can we get a length on the object
        len(x)
    except TypeError:
        return False
    # is the object not a string?
    out = np.all(np.isreal(x))
    return out
//  [python]
def test_device_put_and_get(self):
    x = np.arange(12.).reshape((3, 4)).astype("float32")
    dx = api.device_put(x)
    _check_instance(self, dx)
    self.assertIsInstance(dx, jax.Array)
    self.assertNotIsInstance(dx, np.ndarray)
    x2 = api.device_get(dx)
    self.assertNotIsInstance(x2, jax.Array)
    self.assertIsInstance(x2, np.ndarray)
    assert np.all(x == x2)

    y = [x, (2 * x, 3 * x)]
    dy = api.device_put(y)
    y2 = api.device_get(dy)
    self.assertIsInstance(y2, list)
    self.assertIsInstance(y2[0], np.ndarray)
    assert np.all(y2[0] == x)
    self.assertIsInstance(y2[1], tuple)
    self.assertIsInstance(y2[1][0], np.ndarray)
    assert np.all(y2[1][0] == 2 * x)
    self.assertIsInstance(y2[1][1], np.ndarray)
    assert np.all(y2[1][1] == 3 * x)
//  [python]
def prepare_ids_and_feats(dirs, weights=None, normalize=True):
    """複数のdescriptorをload, normalize, weighting, concatして一本のdescriptorに統合して出力

    :param dirs: descriptorのファイルを持つディレクトリのリスト
    :param weights: 各descriptorに適用する重み係数
    :param normalize: 出力ベクトルを正規化するか
    :return: concatされた一本のdescriptor
    """
    if weights is None:
        weights = [1.0 for _ in range(len(dirs))]

    ids_list, feats_list = [], []
    for f_dir, w in zip(dirs, weights):
        ids, feats = load_scattered_h5data(Path(f_dir).glob('*.h5'))
        feats = l2norm_numpy(feats) * w
        ids_list.append(ids)
        feats_list.append(feats)

    if len(ids_list) > 1:
        # 全てのidが同じ順番かチェック
        assert all([np.all(ids_list[0] == ids) for ids in ids_list[1:]])
        # idがユニークかチェック
        assert len(ids_list[0]) == len(np.unique(ids_list[0]))

    ids_list = ids_list[0]
    feats_list = np.concatenate(feats_list, axis=1)
    if normalize:
        feats_list = l2norm_numpy(feats_list)

    return ids_list, feats_list
//  [python]
def check_cut_datamap_weights(limits, data, weights, guarantee_limits):
    inside = None
    datanew = {}
    for ax in limits.axes:
        limit = limits.with_axes(ax)
        arr = data[ax]
        arr = znp.atleast_1d(arr)
        if not guarantee_limits and limit.has_limits:
            inside = limit.inside(arr) if inside is None else inside & limit.inside(arr)
        datanew[ax] = arr

    if inside is not None and not (run.executing_eagerly() and np.all(inside)):
        for ax, arr in datanew.items():
            datanew[ax] = arr[inside]
        if weights is not None:
            weights = weights[inside]
    return datanew, weights
//  [python]
def __init__(
        self,
        nodes: DataFrame,
        elements: DataFrame,
        crs: CRS = None,
        check_elements: bool = False,
    ):
        if check_elements:
            logging.debug('validating elements...')
            vertex_id_set = nodes.index
            for id, geom in elements.iterrows():
                if not n.all(n.in1d(geom[1:][~pandas.isna(geom[1:])].values, vertex_id_set)):
                    ValueError(
                        f'element "{id}" references nodes that do not exist ("{geom[1:].values}")'
                    )

        self.nodes = nodes
        self.elements = elements
        self.crs = crs
//  [python]
def __init__(
        self,
        nodes: DataFrame,
        elements: DataFrame,
        crs: CRS = None,
        check_elements: bool = False,
    ):
        if check_elements:
            logging.debug('validating elements...')
            vertex_id_set = nodes.index
            for id, geom in elements.iterrows():
                if not np.all(np.in1d(geom[1:][~pandas.isna(geom[1:])].values, vertex_id_set)):
                    ValueError(
                        f'element "{id}" references nodes that do not exist ("{geom[1:].values}")'
                    )

        self.nodes = nodes
        self.elements = elements
        self.crs = crs
//  [python]
def test_orbit_time():
    # Test that Orbit.time returns the time correctly, with units when that's
    # required
    from astropy import units as u

    from galpy.orbit import Orbit
    from galpy.potential import MWPotential2014
    from galpy.util import conversion

    ts = numpy.linspace(0.0, 1.0, 1001) * u.Gyr
    o = Orbit()
    o.integrate(ts, MWPotential2014)
    # No argument, in this case should be times in Gyr
    assert n.all(
        n.fabs((ts - o.time(quantity=True)) / ts[-1]).value < 1e-10
    ), "Orbit.time does not return the correct times"
    # with argument, should be time in Gyr
    assert n.all(
        n.fabs((ts - o.time(ts, quantity=True)) / ts[-1]).value < 1e-10
    ), "Orbit.time does not return the correct times"
    assert (
        n.fabs((ts[-1] - o.time(ts[-1], quantity=True)) / ts[-1]).value < 1e-10
    ), "Orbit.time does not return the correct times"
    # with argument without units --> units
    assert n.all(
        n.fabs(
            ts
            - o.time(
                ts.to(u.Gyr).value
                / conversion.time_in_Gyr(
                    MWPotential2014[0]._vo, MWPotential2014[0]._ro
                ),
                quantity=True,
            )
        ).value
        < 1e-10
    ), "Orbit.time does not return the correct times"
    assert (
        n.fabs(
            ts[-1]
            - o.time(
                ts[-1].to(u.Gyr).value
                / conversion.time_in_Gyr(
                    MWPotential2014[0]._vo, MWPotential2014[0]._ro
                ),
                quantity=True,
            )
        ).value
        < 1e-10
    ), "Orbit.time does not return the correct times"
    # Now should get without units
    o.turn_physical_off()
    assert n.all(
        n.fabs(
            ts.to(u.Gyr).value
            / conversion.time_in_Gyr(MWPotential2014[0]._vo, MWPotential2014[0]._ro)
            - o.time(
                ts.to(u.Gyr).value
                / conversion.time_in_Gyr(MWPotential2014[0]._vo, MWPotential2014[0]._ro)
            )
        )
        < 1e-10
    ), "Orbit.time does not return the correct times"
    assert (
        n.fabs(
            ts[-1].to(u.Gyr).value
            / conversion.time_in_Gyr(MWPotential2014[0]._vo, MWPotential2014[0]._ro)
            - o.time(
                ts[-1].to(u.Gyr).value
                / conversion.time_in_Gyr(MWPotential2014[0]._vo, MWPotential2014[0]._ro)
            )
        )
        < 1e-10
    ), "Orbit.time does not return the correct times"
    return None