示例#1
0
def sample_spraydf(N,
                   barpot,
                   stream='Pal5',
                   fo='sample_trailing.dat',
                   trailing=True,
                   Mprogenitor=50000.,
                   tage=5.,
                   write=False):
    '''
        Sample N points for a given stream using the Particle-Spray framework
        Effects of progenitor's motion is considered
        '''
    print(
        "WARNING: Using particle spray technique, effects of progenitor's orbit incorporated"
    )

    if stream == 'Pal5':
        o = Orbit([229.018, -0.124, 23.2, -2.296, -2.257, -58.7],
                  radec=True,
                  ro=ro,
                  vo=vo,
                  solarmotion=[-11.1, 24., 7.25])

        #convert to galpy units
        orb = Orbit(o._orb.vxvv)

    elif stream == 'GD1':
        o = Orbit(phi12_to_lb_6d(0, -0.82, 10.1, -8.5, -2.15, -257.),
                  lb=True,
                  solarmotion=[-11.1, 24., 7.25],
                  ro=8.,
                  vo=220.)
        #convert to galpy units
        orb = Orbit(o._orb.vxvv)

    fo = stream + fo
    if trailing:
        spdft = streamspraydf.streamspraydf(Mprogenitor * u.Msun,
                                            progenitor=orb,
                                            pot=barpot,
                                            leading=False,
                                            tdisrupt=tage * u.Gyr)
        RvR, dt = spdft.sample(n=N, returndt=True, integrate=True)
        R = RvR[0]
        vR = RvR[1]
        vT = RvR[2]
        z = RvR[3]
        vz = RvR[4]
        phi = RvR[5]

        fo = open(fo, 'w')

    else:
        spdf = streamspraydf.streamspraydf(Mprogenitor * u.Msun,
                                           progenitor=orb,
                                           pot=barpot,
                                           tdisrupt=tage * u.Gyr)
        RvR, dt = spdf.sample(n=N, returndt=True, integrate=True)
        R = RvR[0]
        vR = RvR[1]
        vT = RvR[2]
        z = RvR[3]
        vz = RvR[4]
        phi = RvR[5]
        fo_lead = fo.replace('trailing', 'leading')
        fo = open(fo_lead, 'w')

    if write:

        fo.write("#R   phi   z   vR    vT    vz    ts" + "\n")

        for jj in range(N):
            fo.write(
                str(R[jj]) + "   " + str(phi[jj]) + "   " + str(z[jj]) +
                "   " + str(vR[jj]) + "   " + str(vT[jj]) + "   " +
                str(vz[jj]) + "   " + str(dt[jj]) + "\n")

        fo.close()

    else:

        return (R, phi, z, vR, vT, vz, dt)
示例#2
0
def sample_spraydf_noprog(N,
                          barpot,
                          nobarpot,
                          fo='sample_trailing.dat',
                          stream='Pal5',
                          Mprogenitor=50000.,
                          tage=5.,
                          write=False,
                          trailing=True):
    '''
        Sample N points for a given stream using the Particle-Spray framework
        Effects of progenitor's motion is not considered
        '''
    print(
        "WARNING: Using particle spray technique, effects of progenitor's orbit neglected."
    )

    if stream == 'Pal5':
        o = Orbit([229.018, -0.124, 23.2, -2.296, -2.257, -58.7],
                  radec=True,
                  ro=ro,
                  vo=vo,
                  solarmotion=[-11.1, 24., 7.25])

        #convert to galpy units
        orb = Orbit(o._orb.vxvv)

    elif stream == 'GD1':
        o = Orbit(phi12_to_lb_6d(0, -0.82, 10.1, -8.5, -2.15, -257.),
                  lb=True,
                  solarmotion=[-11.1, 24., 7.25],
                  ro=8.,
                  vo=220.)
        #convert to galpy units
        orb = Orbit(o._orb.vxvv)

    if trailing:
        spdft = streamspraydf.streamspraydf(Mprogenitor * u.Msun,
                                            progenitor=orb,
                                            pot=nobarpot,
                                            leading=False,
                                            tdisrupt=tage * u.Gyr)
        RvR, dt = spdft.sample(n=N, returndt=True, integrate=False)
        R = RvR[0]
        vR = RvR[1]
        vT = RvR[2]
        z = RvR[3]
        vz = RvR[4]
        phi = RvR[5]

        fo = open(fo, 'w')

    else:
        spdf = streamspraydf.streamspraydf(Mprogenitor * u.Msun,
                                           progenitor=orb,
                                           pot=nobarpot,
                                           tdisrupt=tage * u.Gyr)
        RvR, dt = spdf.sample(n=N, returndt=True, integrate=False)
        R = RvR[0]
        vR = RvR[1]
        vT = RvR[2]
        z = RvR[3]
        vz = RvR[4]
        phi = RvR[5]
        fo_lead = fo.replace('trailing', 'leading')
        fo = open(fo_lead, 'w')

    finalR = numpy.empty(N)
    finalvR = numpy.empty(N)
    finalvT = numpy.empty(N)
    finalvz = numpy.empty(N)
    finalphi = numpy.empty(N)
    finalz = numpy.empty(N)
    tt = numpy.empty(N)

    for ii in range(N):

        orb = Orbit([R[ii], vR[ii], vT[ii], z[ii], vz[ii], phi[ii]])
        orb.turn_physical_off()

        ts_future = numpy.linspace(-dt[ii], 0., 1001)
        #forward integrate in barred potential
        orb.integrate(ts_future, barpot)
        finalR[ii] = orb.R(ts_future[-1])
        finalphi[ii] = orb.phi(ts_future[-1])
        finalz[ii] = orb.z(ts_future[-1])
        finalvR[ii] = orb.vR(ts_future[-1])
        finalvT[ii] = orb.vT(ts_future[-1])
        finalvz[ii] = orb.vz(ts_future[-1])
        tt[ii] = dt[ii]

    if write:

        fo.write("#R   phi   z   vR    vT    vz    ts" + "\n")

        for jj in range(N):
            fo.write(
                str(finalR[jj]) + "   " + str(finalphi[jj]) + "   " +
                str(finalz[jj]) + "   " + str(finalvR[jj]) + "   " +
                str(finalvT[jj]) + "   " + str(finalvz[jj]) + "   " +
                str(tt[jj]) + "\n")

        fo.close()

    else:
        return (finalR, finalphi, finalz, finalvR, finalvT, finalvz, tt)
示例#3
0
def setup_gd1model(leading=True,
                   pot=MWPotential2014,
                   timpact=None,
                   hernquist=True,
                   age=9.,
                   singleImpact=False,
                   length_factor=1.,
                   **kwargs):
    #lp= LogarithmicHaloPotential(normalize=1.,q=0.9)
    aAI = actionAngleIsochroneApprox(pot=pot, b=0.8)
    #obs= Orbit([1.56148083,0.35081535,-1.15481504,0.88719443,
    #            -0.47713334,0.12019596])
    #progenitor pos and vel from Bovy 1609.01298 and with corrected proper motion
    obs = Orbit(phi12_to_lb_6d(0, -0.82, 10.1, -8.5, -2.15, -257.),
                lb=True,
                solarmotion=[-11.1, 24., 7.25],
                ro=8.,
                vo=220.)

    sigv = 0.365 / 2. * (9. / age)  #km/s, /2 bc tdis x2, adjust for diff. age
    if timpact is None:
        sdf = streamdf(sigv / 220.,
                       progenitor=obs,
                       pot=pot,
                       aA=aAI,
                       leading=leading,
                       nTrackChunks=11,
                       vsun=[-11.1, 244., 7.25],
                       tdisrupt=age / bovy_conversion.time_in_Gyr(V0, R0),
                       Vnorm=V0,
                       Rnorm=R0)
    elif singleImpact:
        sdf = streamgapdf(sigv / 220.,
                          progenitor=obs,
                          pot=pot,
                          aA=aAI,
                          leading=leading,
                          nTrackChunks=11,
                          vsun=[-11.1, 244., 7.25],
                          tdisrupt=age / bovy_conversion.time_in_Gyr(V0, R0),
                          Vnorm=V0,
                          Rnorm=R0,
                          timpact=timpact,
                          spline_order=3,
                          hernquist=hernquist,
                          **kwargs)
    else:
        sdf = streampepperdf(sigv / 220.,
                             progenitor=obs,
                             pot=pot,
                             aA=aAI,
                             leading=leading,
                             nTrackChunks=101,
                             vsun=[-11.1, 244., 7.25],
                             tdisrupt=age /
                             bovy_conversion.time_in_Gyr(V0, R0),
                             Vnorm=V0,
                             Rnorm=R0,
                             timpact=timpact,
                             spline_order=1,
                             hernquist=hernquist,
                             length_factor=length_factor)
    #sdf.turn_physical_off()  #original
    obs.turn_physical_off()
    return sdf