def contour_singlebox(phi2, d, mu1, mu2, Vrad, Vc, q):
    ro = 8.5
    vo = Vc
    p = potential.LogarithmicHaloPotential(q=q, normalize=1)

    # ---------------------------------------------------------------
    # evaluating the x,y,z and vx,vy,vz from the function variables
    # ---------------------------------------------------------------
    phi1 = 34.776756565525091  # degrees
    lf, bf = mw.phi12_to_lb(phi1, phi2, degree=True)
    xf, yf, zf = bovy_coords.lbd_to_XYZ(lf, bf, d, degree=True)
    # guessed initial position in cylindrical coordinate
    Rf, zcylf, phif = xyz_to_cyl(xf, yf, zf)

    # convert proper motion in phi1 and phi2 coordinates to
    # proper motion in Galactic (vl,vb) coordinate
    vl, vb = mw.pmphi12_to_pmllpmbb(mu1, mu2, phi1, phi2, degree=True)

    # convert the vl, vb to proper motion in cartesian coordinate
    vxf, vyf, vzf = bovy_coords.vrpmllpmbb_to_vxvyvz(Vrad, vl, vb, lf, bf, d, degree=True)

    # convert vx,vy,vz to be in cylindrical coordinates
    vrf, vtf, vzff = vxvyvz_to_vrvtvz(xf, yf, zf, vxf, vyf, vzf)

    o = Orbit(vxvv=[Rf / ro, vrf / vo, vtf / vo, zcylf / ro, vzff / vo, phif], ro=ro, vo=vo)
    global time
    o.integrate(time, p)

    time = np.linspace(0.0, 1e1, 1e4)

    # Orbit in Galactic coordinates
    lval = o.ll(time, ro=ro, obs=[ro, 0.0, 0.0])
    bval = o.bb(time, ro=ro, obs=[ro, 0.0, 0.0])

    pmll = o.pmll(time, ro=ro, obs=[ro, 0.0, 0.0, -10.0, vo + 5.25, 7.17])
    pmbb = o.pmbb(time, ro=ro, obs=[ro, 0.0, 0.0, -10.0, vo + 5.25, 7.17])

    galpy_vel = mw.pmllpmbb_to_pmphi12(pmll, pmbb, lval, bval, degree=True)
    vrad_galpy = o.vlos(time, ro=ro, obs=[ro, 0.0, 0.0, -10.0, vo + 5.25, 7.17])

    phi12 = mw.lb_to_phi12(lval, bval, degree=True)
    phi12[phi12[:, 0] > 180, 0] -= 360.0

    L_pos = likelihood_all_test_sum(phi12[:, 0], phi1_pos, x_err_pos, phi12[:, 1], phi2_pos, phi2_err, time)
    L_dist = likelihood_all_test_sum(phi12[:, 0], phi1_dist, x_err_dist, o.dist(time), dist, dist_err, time)
    L_vrad = likelihood_all_test_sum(phi12[:, 0], phi1_vrad, x_err_vrad, vrad_galpy, Vrad, V_err, time)
    L_mu1 = likelihood_all_test_sum(phi12[:, 0], phi1_mu, x_err_mu, galpy_vel.T[0], mu1, sigma_mu, time)
    L_mu2 = likelihood_all_test_sum(phi12[:, 0], phi1_mu, x_err_mu, galpy_vel.T[1], mu2, sigma_mu, time)

    L_total = L_pos + L_dist + L_vrad + L_mu1 + L_mu2

    return L_total
示例#2
0
def check_phi12_to_cylind(phi1,phi2, d, degree = False):
    
    '''
    Parameters
    ----------------------------------------------------
        phi1 and phi2:
            position in stream coordinates
        
        d:
            distance in kpc
        
        
    Return
    ----------------------------------------------------
        position in cylindrical coordinates
    '''
    
    l, b          = mw.phi12_to_lb(phi1, phi2, degree)
    x, y, z       = bovy_coords.lbd_to_XYZ(l, b, d, degree)
    R, zcyl , phi = xyz_to_cyl(xf, yf, zf)
    return np.array([R, zcyl, phi])
示例#3
0
def optimizer_func(input,Vc,q):
    
    '''
    Parameters
    ----------------------------------------------------
        phi2:
            phi2 in degrees
        
        D:
            distance in kpc
        
        
        mu_phi1, mu_phi2:
            proper motion in phi1 and phi2 coordinates
        
        Vrad:
            radial velocity
    
        
    Return
    ----------------------------------------------------
        Log likelihood using the specified Vc,q, phi2,
        D, proper motions in stream coordinates and 
        the radial velocity.
    '''
    
    phi2    = input[0]
    D       = input[1]
    mu_phi1 = input[2]
    mu_phi2 = input[3]
    Vrad    = input[4]
    
    print "vc in function:", Vc
    print "q in function:" , q
    
    # choose a value of phi2 for the given phi1 (phi1 should stay constant from
    # initial conditions obtained above in degrees
    
    phi1i = -30. #phi12i_kop[0]
    phi2i = phi2
    
    
    # convert the phi1 and phi2 to be in cylindrical coordinate
    lf, bf        = mw.phi12_to_lb(phi1i, phi2i, degree=True)
    xf, yf, zf    = bovy_coords.lbd_to_XYZ(lf, bf, D, degree = True)
    
    
    # guessed initial position in cylindrical coordinate
    Rf,zcylf,phif = xyz_to_cyl(xf, yf, zf)
    
    
    # convert proper motion in phi1 and phi2 coordinates to
    # proper motion in Galactic (vl,vb) coordinate
    vl,vb = mw.pmphi12_to_pmllpmbb(mu_phi1, mu_phi2, phi1i, phi2i, degree = True)
    
    # convert the vl, vb to proper motion in cartesian coordinate
    vxf, vyf, vzf  = bovy_coords.vrpmllpmbb_to_vxvyvz(Vrad, vl, vb, lf, bf, D, degree = True)
    
    
    # convert vx,vy,vz to be in cylindrical coordinates
    vrf, vtf, vzff = vxvyvz_to_vrvtvz(xf, yf, zf, vxf, vyf, vzf)
    
    
    # use the above initial positions to calculate the potential and orbit
    ro = 8.5
    vo = Vc
    p  = potential.LogarithmicHaloPotential(q = q,normalize = 1)
    o  = Orbit(vxvv=[Rf/ro, vrf/vo, vtf/vo, zcylf/ro, vzff/vo, phif], ro = ro, vo = vo)
    o.integrate(time_glob,p)
    
    time = np.linspace(0.,1e1,1e4)

    # compute the likelihood with the above initial position
    lval = o.ll(time, ro = ro, obs = [ro,0.,0.])
    bval = o.bb(time, ro = ro, obs = [ro,0.,0.])
    
    pmll = o.pmll(time, ro = ro, obs = [ro, 0., 0., -10., vo+5.25, 7.17])
    pmbb = o.pmbb(time, ro = ro, obs = [ro, 0., 0., -10., vo+5.25, 7.17])
    
    galpy_vel  = mw.pmllpmbb_to_pmphi12(pmll,pmbb,lval,bval,degree = True)
    vrad_galpy = o.vlos(time, ro = ro, obs = [ro, 0., 0., -10., vo+5.25, 7.17])
    
    
    phi12 = mw.lb_to_phi12(lval, bval, degree = True)
    phi12[phi12[:,0] > 180,0]-= 360.
    
    # calculating likelihood for each set of parameters
    L_pos  = likelihood_all_test_sum(phi12[:,0], phi1_pos,  x_err_pos,  phi12[:,1],     phi2_pos, phi2_err, time)
    L_dist = likelihood_all_test_sum(phi12[:,0], phi1_dist, x_err_dist, o.dist(time),   dist,     dist_err, time)
    L_vrad = likelihood_all_test_sum(phi12[:,0], phi1_vrad, x_err_vrad, vrad_galpy,     Vrad_kop, V_err,    time)
    L_mu1  = likelihood_all_test_sum(phi12[:,0], phi1_mu,   x_err_mu,   galpy_vel.T[0], mu1,      sigma_mu, time)
    L_mu2  = likelihood_all_test_sum(phi12[:,0], phi1_mu,   x_err_mu,   galpy_vel.T[1], mu2,      sigma_mu, time)
    
    print "L position:", L_pos
    print "L dist:"    , L_dist
    print "L vrad:"    , L_vrad
    print "L mu1:"     , L_mu1
    print "L mu2:"     , L_mu2
    print
    
    L_total = L_pos + L_dist + L_vrad + L_mu1 + L_mu2
    
  
    # chi^2 = -2ln(L) where ln(L) = L_total
    chi2 = -2. * L_total


    print
    print "chi2: ",chi2
    print
    
    print "input:", input
    
    return chi2