<commit_before>##########################TESTS ON MULTIPLE ORBITS#############################
import sys
import numpy
import pytest
from galpy import potential

# Test Orbits initialization
def test_initialization_vxvv():
    from galpy.orbit import Orbit, Orbits
    # 1D
    vxvvs= [[1.,0.1],[0.1,3.]]
    orbits= Orbits(vxvvs)
    assert orbits.dim() == 1, 'Orbit initialization with vxvv in 1D does not work as expected'
    assert orbits.phasedim() == 2, 'Orbit initialization with vxvv in 1D does not work as expected'
    assert numpy.fabs(orbits.x()[0]-1.) < 1e-10, 'Orbit initialization with vxvv in 1D does not work as expected'
    assert numpy.fabs(orbits.x()[1]-0.1) < 1e-10, 'Orbit initialization with vxvv in 1D does not work as expected'
    assert numpy.fabs(orbits.vx()[0]-0.1) < 1e-10, 'Orbit initialization with vxvv in 1D does not work as expected'
    assert numpy.fabs(orbits.vx()[1]-3.) < 1e-10, 'Orbit initialization with vxvv in 1D does not work as expected'
    # 2D, 3 phase-D
    vxvvs= [[1.,0.1,1.],[0.1,3.,1.1]]
    orbits= Orbits(vxvvs)
    assert orbits.dim() == 2, 'Orbit initialization with vxvv in 2D, 3 phase-D does not work as expected'
    assert orbits.phasedim() == 3, 'Orbit initialization with vxvv in 2D, 3 phase-D does not work as expected'
    assert numpy.fabs(orbits.R()[0]-1.) < 1e-10, 'Orbit initialization with vxvv in 2D, 3 phase-D does not work as expected'
    assert numpy.fabs(orbits.R()[1]-0.1) < 1e-10, 'Orbit initialization with vxvv in 2D, 3 phase-D does not work as expected'
    assert numpy.fabs(orbits.vR()[0]-0.1) < 1e-10, 'Orbit initialization with vxvv in 2D, 3 phase-D does not work as expected'
    assert numpy.fabs(orbits.vR()[1]-3.) < 1e-10, 'Orbit initialization with vxvv in 2D, 3 phase-D does not work as expected'
    assert numpy.fabs(orbits.vT()[0]-1.) < 1e-10, 'Orbit initialization with vxvv in 2D, 3 phase-D does not work as expected'
    assert numpy.fabs(orbits.vT()[1]-1.1) < 1e-10, 'Orbit initialization with vxvv in 2D, 3 phase-D does not work as expected'
    # 2D, 4 phase-D
    vxvvs= [[1.,0.1,1.,1.5],[0.1,3.,1.1,2.]]
    orbits= Orbits(vxvvs)
    assert orbits.dim() == 2, 'Orbit initialization with vxvv 2D, 4 phase-D does not work as expected'
    assert orbits.phasedim() == 4, 'Orbit initialization with vxvv 2D, 4 phase-D does not work as expected'
    assert numpy.fabs(orbits.R()[0]-1.) < 1e-10, 'Orbit initialization with vxvv 2D, 4 phase-D does not work as expected'<commit_msg>Add test to make sure that Orbit initialization with an array of SkyCoords does the right conversion (even though it doesn't make sense to initialize an Orbit with an array of coordinates); this will be relied upon to simplify the initialization of Orbits<commit_after>##########################TESTS ON MULTIPLE ORBITS#############################
import sys
import numpy
import astropy.units as u
import astropy.coordinates as apycoords
import pytest
from galpy import potential

# Test that initializing an Orbit (not an Orbits) with an array of SkyCoords
# processes the input correctly into the Orbit._orb.vxvv attribute;
# The Orbits class depends on this to process arrays SkyCoords itself quickly
def test_orbit_initialization_SkyCoordarray():
    from galpy.orbit import Orbit
    numpy.random.seed(1)
    nrand= 30
    ras= numpy.random.uniform(size=nrand)*360.*u.deg
    decs= 90.*(2.*numpy.random.uniform(size=nrand)-1.)*u.deg
    dists= numpy.random.uniform(size=nrand)*10.*u.kpc
    pmras= 20.*(2.*numpy.random.uniform(size=nrand)-1.)*20.*u.mas/u.yr
    pmdecs= 20.*(2.*numpy.random.uniform(size=nrand)-1.)*20.*u.mas/u.yr
    vloss= 200.*(2.*numpy.random.uniform(size=nrand)-1.)*u.km/u.s
    # Without any custom coordinate-transformation parameters
    co= apycoords.SkyCoord(ra=ras,dec=decs,distance=dists, 
                           pm_ra_cosdec=pmras,pm_dec=pmdecs,
                           radial_velocity=vloss,
                           frame='icrs')
    os= Orbit(co)
    vxvv= numpy.array(os._orb.vxvv).T
    for ii in range(nrand):
        to= Orbit(co[ii])
        assert numpy.all(numpy.fabs(numpy.array(to._orb.vxvv)-vxvv[ii]) < 1e-10), 'Orbit initialization with an array of SkyCoords does not give the same result as processing each SkyCoord individually'
    # With custom coordinate-transformation parameters
    v_sun= apycoords.CartesianDifferential([-11.1,215.,3.25]*u.km/u.s)
    co= apycoords.SkyCoord(ra=ras,dec=decs,distance=dists, 
                           pm_ra_cosdec=pmras,pm_dec=pmdecs,
                           radial_velocity=vloss,
                           frame='icrs',
                           galcen_distance=10.*u.kpc,z_sun=1.*u.kpc,
                           galcen_v_sun=v_sun)
    os= Orbit(co)
    vxvv= numpy.array(os._orb.vxvv).T
    for ii in range(nrand):
        to= Orbit(co[ii])
        assert numpy.all(numpy.fabs(numpy.array(to._orb.vxvv)-vxvv[ii]) < 1e-10), 'Orbit initialization with an array of SkyCoords does not give the same result as processing each SkyCoord individually'
    return None

# Test Orbits initialization
def test_initialization_vxvv():
    from galpy.orbit import Orbit, Orbits
    # 1D
    vxvvs= [[1.,0.1],[0.1,3.]]
    orbits= Orbits(vxvvs)
    assert orbits.dim() == 1, 'Orbit initialization with vxvv in 1D does not work as expected'
    assert orbits.phasedim() == 2, 'Orbit initialization with vxvv in 1D does not work as expected'
    assert numpy.fabs(orbits.x()[0]-1.) < 1e-10, 'Orbit initialization with vxvv in 1D does not work as expected'
    assert numpy.fabs(orbits.x()[1]-0.1) < 1e-10, 'Orbit initialization with vxvv in 1D does not work as expected'
    assert numpy.fabs(orbits.vx()[0]-0.1) < 1e-10, 'Orbit initialization with vxvv in 1D does not work as expected'
    assert numpy.fabs(orbits.vx()[1]-3.) < 1e-10, 'Orbit initialization with vxvv in 1D does not work as expected'
    # 2D, 3 phase-D
    vxvvs= [[1.,0.1,1.],[0.1,3.,1.1]]
    orbits= Orbits(vxvvs)
    assert orbits.dim() == 2, 'Orbit initialization with vxvv in 2D, 3 phase-D does not work as expected'
    assert orbits.phasedim() == 3, 'Orbit initialization with vxvv in 2D, 3 phase-D does not work as expected'
    assert numpy.fabs(orbits.R()[0]-1.) < 1e-10, 'Orbit initialization with vxvv in 2D, 3 phase-D does not work as expected'
    assert numpy.fabs(orbits.R()[1]-0.1) < 1e-10, 'Orbit initialization with vxvv in 2D, 3 phase-D does not work as expected'
    assert numpy.fabs(orbits.vR()[0]-0.1) < 1e-10, 'Orbit initialization with vxvv in 2D, 3 phase-D does not work as expected'
    assert numpy.fabs(orbits.vR()[1]-3.) < 1e-10, 'Orbit initialization with vxvv in 2D, 3 phase-D does not work as expected'
    assert numpy.fabs(orbits.vT()[0]-1.) < 1e-10, 'Orbit initialization with vxvv in 2D, 3 phase-D does not work as expected'
    assert numpy.fabs(orbits.vT()[1]-1.1) < 1e-10, 'Orbit initialization with vxvv in 2D, 3 phase-D does not work as expected'
    # 2D, 4 phase-D
    vxvvs= [[1.,0.1,1.,1.5],[0.1,3.,1.1,2.]]
    orbits= Orbits(vxvvs)
    assert orbits.dim() == 2, 'Orbit initialization with vxvv 2D, 4 phase-D does not work as expected'
    assert orbits.phasedim() == 4, 'Orbit initialization with vxvv 2D, 4 phase-D does not work as expected'
    assert numpy.fabs(orbits.R()[0]-1.) < 1e-10, 'Orbit initialization with vxvv 2D, 4 phase-D does not work as expected'
{'fraction_non_alphanumeric': 0.135789044447465, 'fraction_numerical': 0.04064156585564768, 'mean_word_length': 3.4139172165566887, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '728889', 'n_tokens_mistral': 2777, 'n_tokens_neox': 2550, 'n_words': 790}