Beispiel #1
0
def test_orbmethods():
    from galpy.orbit import Orbit
    from galpy.potential import MWPotential2014
    # 8/17/2019: added explicit z=0.025, because that was the default at the
    # time of the galpy paper, but the default has been changed
    o = Orbit([0.8, 0.3, 0.75, 0., 0.2, 0.],
              zo=0.025)  # setup R,vR,vT,z,vz,phi
    times = numpy.linspace(0., 10., 1001)  # Output times
    o.integrate(times, MWPotential2014)  # Integrate
    o.E()  # Energy
    assert numpy.fabs(o.E() + 1.2547650648697966
                      ) < 10.**-5., 'Orbit method does not work as expected'
    o.L()  # Angular momentum
    assert numpy.all(
        numpy.fabs(o.L() - numpy.array([[0., -0.16, 0.6]])) < 10.**-5.
    ), 'Orbit method does not work as expected'
    o.Jacobi(OmegaP=0.65)  #Jacobi integral E-OmegaP Lz
    assert numpy.fabs(o.Jacobi(OmegaP=0.65) - numpy.array([-1.64476506])
                      ) < 10.**-5., 'Orbit method does not work as expected'
    o.ER(times[-1]), o.Ez(times[-1])  # Rad. and vert. E at end
    assert numpy.fabs(o.ER(times[-1]) + 1.27601734263047
                      ) < 10.**-5., 'Orbit method does not work as expected'
    assert numpy.fabs(o.Ez(times[-1]) - 0.021252201847851909
                      ) < 10.**-5., 'Orbit method does not work as expected'
    o.rperi(), o.rap(), o.zmax()  # Peri-/apocenter r, max. |z|
    assert numpy.fabs(o.rperi() - 0.44231993168097
                      ) < 10.**-5., 'Orbit method does not work as expected'
    assert numpy.fabs(o.rap() - 0.87769030382105
                      ) < 10.**-5., 'Orbit method does not work as expected'
    assert numpy.fabs(o.zmax() - 0.077452357289016
                      ) < 10.**-5., 'Orbit method does not work as expected'
    o.e()  # eccentricity (rap-rperi)/(rap+rperi)
    assert numpy.fabs(o.e() - 0.32982348199330563
                      ) < 10.**-5., 'Orbit method does not work as expected'
    o.R(2., ro=8.)  # Cylindrical radius at time 2. in kpc
    assert numpy.fabs(o.R(2., ro=8.) - 3.5470772876920007
                      ) < 10.**-3., 'Orbit method does not work as expected'
    o.vR(5., vo=220.)  # Cyl. rad. velocity at time 5. in km/s
    assert numpy.fabs(o.vR(5., vo=220.) - 45.202530965094553
                      ) < 10.**-3., 'Orbit method does not work as expected'
    o.ra(1.), o.dec(1.)  # RA and Dec at t=1. (default settings)
    # 5/12/2016: test weakened, because improved galcen<->heliocen
    #            transformation has changed these, but still close
    assert numpy.fabs(o.ra(1.) - numpy.array([288.19277])
                      ) < 10.**-1., 'Orbit method does not work as expected'
    assert numpy.fabs(o.dec(1.) - numpy.array([18.98069155])
                      ) < 10.**-1., 'Orbit method does not work as expected'
    o.jr(type='adiabatic'), o.jz()  # R/z actions (ad. approx.)
    assert numpy.fabs(o.jr(type='adiabatic') - 0.05285302231137586
                      ) < 10.**-3., 'Orbit method does not work as expected'
    assert numpy.fabs(o.jz() - 0.006637988850751242
                      ) < 10.**-3., 'Orbit method does not work as expected'
    # Rad. period w/ Staeckel approximation w/ focal length 0.5,
    o.Tr(type='staeckel', delta=0.5, ro=8., vo=220.)  # in Gyr
    assert numpy.fabs(
        o.Tr(type='staeckel', delta=0.5, ro=8., vo=220.) - 0.1039467864018446
    ) < 10.**-3., 'Orbit method does not work as expected'
    o.plot(d1='R', d2='z')  # Plot the orbit in (R,z)
    o.plot3d()  # Plot the orbit in 3D, w/ default [x,y,z]
    return None
def test_energy_momentum_of_sun():
    o = Orbit()  # create sun's orbit
    o.turn_physical_off()
    ts = np.linspace(0, 1000, 100000)
    o.integrate(ts, MWPotential2014)
    print('galpy energy = ', o.E())
    coord = np.array([o.x(), o.y(), o.z(), o.vx(), o.vy(), o.vz()])
    print('my energy = ', Energy(coord))
    print(o.E() == Energy(coord))
    print('galpy momentum = ', o.L()[0][2])
    print('my momentum = ', L_z(coord))
    print(o.L()[0][2] == L_z(coord))
Beispiel #3
0
        vhel_mc[dist_mc < 0] = 0.0
        pmdec_mc[dist_mc < 0] = 0.0
        dist_mc[dist_mc < 0] = 0.0

    for j in range(nmc):
        op= Orbit(vxvv=[ra[i],dec[i],dist_mc[j],pmra_mc[j],pmdec_mc[j],vhel_mc[j]],\
          radec=True,uvw=False,ro=8.0, vo=220.0,zo=zsun, \
          solarmotion=[-usun,vsun,wsun])
        op.integrate(ts, MWPotential2014)
        rap_mc[j] = op.rap()
        rperi_mc[j] = op.rperi()
        rmean_mc[j] = 0.5 * (rap_mc[j] + rperi_mc[j])
        zmax_mc[j] = op.zmax()
        ecc_mc[j] = op.e()
        ene_mc[j] = op.E()
        lz_mc[j] = op.L(0.0)[0][2]
        vphi_mc[j] = op.vphi(0.0)
        vrad_mc[j] = op.vR(0.0)
    # taking mean and std
    rap[i] = rap_mc.mean()
    rap_err[i] = rap_mc.std()
    rperi[i] = rperi_mc.mean()
    rperi_err[i] = rperi_mc.std()
    rmean[i] = rmean_mc.mean()
    rmean_err[i] = rmean_mc.std()
    zmax[i] = zmax_mc.mean()
    zmax_err[i] = zmax_mc.std()
    ecc[i] = ecc_mc.mean()
    ecc_err[i] = ecc_mc.std()
    ene[i] = ene_mc.mean()
    ene_err[i] = ene_mc.std()
Beispiel #4
0
print 'Join'
galah = join(galah, gaia, keys='sobject_id', join_type='left')

# orbit of a Solar-like object, used to normalise L_z
ts = np.linspace(0., 500, 5e4) * un.Myr
orbit_sun = Orbit(vxvv=[
    0. * un.deg, 0. * un.deg, 0.00001 * un.pc, 0. * un.mas / un.yr,
    0. * un.mas / un.yr, 0. * un.km / un.s
],
                  radec=True,
                  ro=8.2,
                  vo=238.,
                  zo=0.025,
                  solarmotion=[-11., 10., 7.25])
orbit_sun.turn_physical_on()
L_ang_sun = orbit_sun.L()
print L_ang_sun

z_min = []
z_max = []
z_abs_max = []
L_ang = []
L_ang_z = []
vy = []
vx_vz = []
suffix = ''

# optional filters
# exclude data with large relative parallax error
# carbon_s = carbon_s[carbon_s['parallax_error']/carbon_s['parallax'] < 0.2]
# exclude far away stars