Beispiel #1
0
def test_dl_to_rphi_2d():
    #This is a tangent point
    l= numpy.arcsin(0.75)
    d= 6./numpy.tan(l)
    r,phi= bovy_coords.dl_to_rphi_2d(d,l,degree=False,ro=8.,phio=0.)
    assert numpy.fabs(r-6.) < 10.**-10., 'dl_to_rphi_2d conversion did not work as expected'
    assert numpy.fabs(phi-numpy.arccos(0.75)) < 10.**-10., 'dl_to_rphi_2d conversion did not work as expected'
    #This is a different point
    d,l= 2., 45.
    r,phi= bovy_coords.dl_to_rphi_2d(d,l,degree=True,ro=2.*numpy.sqrt(2.),
                                     phio=10.)
    assert numpy.fabs(r-2.) < 10.**-10., 'dl_to_rphi_2d conversion did not work as expected'
    assert numpy.fabs(phi-55.) < 10.**-10., 'dl_to_rphi_2d conversion did not work as expected'
    #This is a different point, for array
    d,l= 2., 45.
    os= numpy.ones(2)
    r,phi= bovy_coords.dl_to_rphi_2d(os*d,os*l,degree=True,
                                     ro=2.*numpy.sqrt(2.),
                                     phio=0.)
    assert numpy.all(numpy.fabs(r-2.) < 10.**-10.), 'dl_to_rphi_2d conversion did not work as expected'
    assert numpy.all(numpy.fabs(phi-45.) < 10.**-10.), 'dl_to_rphi_2d conversion did not work as expected'
    #This is a different point, for list (which I support for some reason)
    d,l= 2., 45.
    r,phi= bovy_coords.dl_to_rphi_2d([d,d],[l,l],degree=True,
                                     ro=2.*numpy.sqrt(2.),
                                     phio=0.)
    r= numpy.array(r)
    phi= numpy.array(phi)
    assert numpy.all(numpy.fabs(r-2.) < 10.**-10.), 'dl_to_rphi_2d conversion did not work as expected'
    assert numpy.all(numpy.fabs(phi-45.) < 10.**-10.), 'dl_to_rphi_2d conversion did not work as expected'
    return None
def mvlosnonaxi(params, interpObj, interpObjAxi, thesedata, options, logpiso,
                phio):
    l = thesedata['GLON'] * _DEGTORAD
    b = thesedata['GLAT'] * _DEGTORAD
    cosb = math.cos(b)
    sinb = math.sin(b)
    out = 0.
    norm = 0.
    ds = numpy.linspace(_BINTEGRATEDMAX, _BINTEGRATEDMIN,
                        _BINTEGRATENBINS) / params[1] / _REFR0
    for ii in range(_BINTEGRATENBINS):
        #Calculate R and phi
        R, phi = bovy_coords.dl_to_rphi_2d(ds[ii], l, degree=False, phio=phio)
        if R < 0.5 or R > 2.: continue  #Not in the model
        logpd = _logpd(params, ds[ii], l, b, 0., 0., None, options, R, phi,
                       cosb, sinb, logpiso[ii])
        out += math.exp(logpd) * (
            (interpObj.meanvt(R, phi) * numpy.sin(phi + l - phio) -
             interpObj.meanvr(R, phi) * numpy.cos(phi + l - phio)) -
            (interpObjAxi.meanvt(R, phi) * numpy.sin(phi + l - phio) -
             interpObjAxi.meanvr(R, phi) * numpy.cos(phi + l - phio)))
        norm += math.exp(logpd)
    if norm == 0.: return 0.
    out /= norm
    #if l < 35.*_DEGTORAD: print out
    if options.dwarf:
        out *= (1. - params[5 - options.nooutliermean])
        R, phi = 1., phio
        out += params[5 - options.nooutliermean] * (
            (interpObj.meanvt(R, phi) * numpy.sin(phi + l - phio) -
             interpObj.meanvr(R, phi) * numpy.cos(phi + l - phio)) -
            (interpObjAxi.meanvt(R, phi) * numpy.sin(phi + l - phio) -
             interpObjAxi.meanvr(R, phi) * numpy.cos(phi + l - phio)))
    return out[0][0]
def mvlosnonaxi(params, interpObj, interpObjAxi, thesedata, options, logpiso, phio):
    l = thesedata["GLON"] * _DEGTORAD
    b = thesedata["GLAT"] * _DEGTORAD
    cosb = math.cos(b)
    sinb = math.sin(b)
    out = 0.0
    norm = 0.0
    ds = numpy.linspace(_BINTEGRATEDMAX, _BINTEGRATEDMIN, _BINTEGRATENBINS) / params[1] / _REFR0
    for ii in range(_BINTEGRATENBINS):
        # Calculate R and phi
        R, phi = bovy_coords.dl_to_rphi_2d(ds[ii], l, degree=False, phio=phio)
        if R < 0.5 or R > 2.0:
            continue  # Not in the model
        logpd = _logpd(params, ds[ii], l, b, 0.0, 0.0, None, options, R, phi, cosb, sinb, logpiso[ii])
        out += math.exp(logpd) * (
            (
                interpObj.meanvt(R, phi) * numpy.sin(phi + l - phio)
                - interpObj.meanvr(R, phi) * numpy.cos(phi + l - phio)
            )
            - (
                interpObjAxi.meanvt(R, phi) * numpy.sin(phi + l - phio)
                - interpObjAxi.meanvr(R, phi) * numpy.cos(phi + l - phio)
            )
        )
        norm += math.exp(logpd)
    if norm == 0.0:
        return 0.0
    out /= norm
    # if l < 35.*_DEGTORAD: print out
    if options.dwarf:
        out *= 1.0 - params[5 - options.nooutliermean]
        R, phi = 1.0, phio
        out += params[5 - options.nooutliermean] * (
            (
                interpObj.meanvt(R, phi) * numpy.sin(phi + l - phio)
                - interpObj.meanvr(R, phi) * numpy.cos(phi + l - phio)
            )
            - (
                interpObjAxi.meanvt(R, phi) * numpy.sin(phi + l - phio)
                - interpObjAxi.meanvr(R, phi) * numpy.cos(phi + l - phio)
            )
        )
    return out[0][0]