Ejemplo n.º 1
0
def run(gp):
    import gr_params
    gpr = gr_params.grParams(gp)
    gu.G1__pcMsun_1km2s_2 = 1.  # as per definition
    gp.anM = 1. #
    gp.ana = 1. #

    print('grh_com: input: ', gpr.simpos)
    xall, yall, zall = np.loadtxt(gpr.simpos, skiprows=1, unpack=True) # 3*[gp.ana]
    vxall,vyall,vzall= np.loadtxt(gpr.simvel, skiprows=1, unpack=True) # 3*[gp.ana]
    nall = len(xall)                                                 # [1]

    # shuffle and restrict to ntracer random points
    ndm = int(min(gp.ntracer[0], nall-1))
    trace = random.sample(range(nall), nall)
    if gp.pops > 1:
        gh.LOG(1, 'implement more than 2 pops for hern')
        pdb.set_trace()

    PM = [1. for i in trace] # [1]=const, no prob. of membership info in dataset
    x  = [ xall[i]    for i in trace ] # [gp.ana]
    y  = [ yall[i]    for i in trace ] # [gp.ana]
    z  = [ zall[i]    for i in trace ] # [gp.ana]
    vz = [ vzall[i]   for i in trace ] # [km/s]
    PM = np.array(PM); x=np.array(x); y=np.array(y); z=np.array(z); vz=np.array(vz)

    com_x, com_y, com_z, com_vz = com_shrinkcircle_v(x,y,z,vz,PM) # 3*[gp.ana], [velocity]
    print('COM [gp.ana]: ', com_x, com_y, com_z, com_vz)

    xnew = (x-com_x) #*gp.ana      # [pc]
    ynew = (y-com_y) #*gp.ana      # [pc]
    #znew = (z-com_z) # *gp.ana      # [pc]
    vznew = (vz-com_vz) #*1e3*np.sqrt(gu.G1__pcMsun_1km2s_2*gp.anM/gp.ana) # [km/s], from conversion from system with L=G=M=1

    R0 = np.sqrt(xnew**2+ynew**2)   # [pc]
    Rhalf = np.median(R0)           # [pc]
    Rscale = Rhalf                  # or gpr.r_DM # [pc]

    print('Rscale/pc = ', Rscale)

    # only for 0 (all) and 1 (first and only population)
    for pop in range(gp.pops+1):
        crscale = open(gp.files.get_scale_file(pop),'w')
        print('# Rscale in [pc],',' surfdens_central (=dens0) in [Munit/rscale**2],',\
              ' and totmass_tracers [Munit],',\
              ' and max(sigma_LOS) in [km/s]', file=crscale)
        print(Rscale, file=crscale)
        crscale.close()

        gh.LOG(2, 'grh_com: output: ', gp.files.get_com_file(pop))
        filepos = open(gp.files.get_com_file(pop), 'w')
        print('# x [Rscale]','y [Rscale]','vLOS [km/s]', file=filepos)
        for k in range(ndm):
            print(xnew[k]/Rscale, ynew[k]/Rscale, vznew[k], file=filepos)
        filepos.close()
        gh.LOG(2, '')
Ejemplo n.º 2
0
def run(gp):
    import gr_params
    gpr = gr_params.grParams(gp)
    print('input: ', gpr.fil)
    M0,x0,y0,z0,vx0, vy0, vz0, comp0 = read_data(gpr.fil)
    # [Msun], 3*[pc], 3*[km/s], [1]

    # assign population
    if gp.pops==2:
        pm1 = (comp0 == 1) # will be overwritten below if gp.metalpop
        pm2 = (comp0 == 2) # same same
    elif gp.pops==1:
        pm1 = (comp0 < 3)
        pm2 = (comp0 == -1) # assign none, but of same length as comp0

    # cut to subsets
    ind1 = gh.draw_random_subset(x1, gp.ntracer[1-1])
    M1, x1, y1, z1, vx1, vy1, vz1, comp1 = select_pm(M1, x1, y1, z1, vx1, vy1, vz1, comp1, ind1)

    ind2 = gh.draw_random_subset(x2, gp.ntracer[2-1])
    M2, x2, y2, z2, vx2, vy2, vz2, comp2 = select_pm(M2, x2, y2, z2, vx2, vy2, vz2, comp2, ind2)

    # use vz for no contamination, or vb for with contamination
    M0, x0, y0, z0, vx0, vy0, vz0 = concat_pops(M1, M2, x1, x2, y1, y2, z1, z2, vx1, vx2, vy1, vy2, vz1, vz2, gp)
    com_x, com_y, com_z, com_vz = com_shrinkcircle_v(x0, y0, z0, vz0, pm0) # [pc]
    print('COM [pc]: ', com_x, com_y, com_z)   # [pc]
    print('VOM [km/s]', com_vz)                # [km/s]

    # from now on, work with 2D data only; z0 was only used to get
    # center in (x,y) better
    x0 -= com_x # [pc]
    y0 -= com_y # [pc]
    vz0 -= com_vz # [km/s]

    R0 = np.sqrt(x0**2+y0**2) # [pc]
    Rhalf = np.median(R0) # [pc]
    Rscale = Rhalf        # [pc] from all tracer points

    pop = -1
    for pmn in [pm, pm1, pm2]:
        pop = pop + 1                    # population number
        pmr = ( R0 < (gp.maxR*Rscale) )  # read max extension for data
                                         #(rprior*Rscale) from
                                         #gi_params
        pmn = pmn*pmr                    # [1]
        print("fraction of members = ", 1.0*sum(pmn)/len(pmn))

        x, y, z, comp, vz, vb, Mg, PMN = select_pm(x0, y0, z0, comp0, vz0, vb0, Mg0, PM0, pmn)
        R = np.sqrt(x*x+y*y)             # [pc]
        Rscalei = np.median(R)
        gf.write_Xscale(gp.files.get_scale_file(pop), Rscalei)
        gf.write_data_output(gp.files.get_com_file(pop), x/Rscalei, y/Rscalei, vz, Rscalei)

        if gpr.showplots:
            gpr.show_part_pos(x, y, pmn, Rscale)
Ejemplo n.º 3
0
def run(gp):
    import gr_params
    gpr = gr_params.grParams(gp)
    print('input:', gpr.fil)
    x0, y0, z0, vx, vy, vz = np.transpose(np.loadtxt(gpr.fil))
    # for purely tangential beta=-0.5 models, have units of kpc instead of pc
    if gp.case == 9 or gp.case == 10:
        x0 *= 1000.  # [pc]
        y0 *= 1000.  # [pc]
        z0 *= 1000.  # [pc]
    # cutting pm_i to a maximum of ntracers particles:
    import gi_helper as gh
    ind1 = gh.draw_random_subset(x0, gp.ntracer[1 - 1])
    x0, y0, z0, vz0 = select_pm(x0, y0, z0, vz, ind1)

    PM = np.ones(
        len(x0))  # assign all particles the full probability of membership
    import gi_centering as glc
    com_x, com_y, com_z, com_vz = glc.com_shrinkcircle_v(x0, y0, z0, vz, PM)
    # from now on, work with 2D data only;
    # z0 was only used to get center in (x,y) better
    x0 -= com_x  # [pc]
    y0 -= com_y  # [pc]
    vz -= com_vz  # [km/s]
    R0 = np.sqrt(x0 * x0 + y0 * y0)  # [pc]
    Rscale = np.median(R0)  # [pc]
    import gi_file as gf
    for pop in range(gp.pops + 1):  # gp.pops +1 for all components together
        pmr = (R0 < (gp.maxR * Rscale))
        #m = np.ones(len(R0))
        x = x0[pmr]  # [pc]
        y = y0[pmr]  # [pc]
        R = np.sqrt(x * x + y * y)  # [pc]
        Rscalei = np.median(R)
        # print("x y z" on first line, to interprete data later on)
        gf.write_Xscale(gp.files.get_scale_file(pop), Rscalei)
        gf.write_data_output(gp.files.get_com_file(pop), x / Rscalei,
                             y / Rscalei, vz, Rscalei)
Ejemplo n.º 4
0
def run(gp):
    import gr_params
    gpr = gr_params.grParams(gp)
    print('input:', gpr.fil)
    x0, y0, z0, vx, vy, vz = np.transpose(np.loadtxt(gpr.fil))
    # for purely tangential beta=-0.5 models, have units of kpc instead of pc
    if gp.case == 9 or gp.case == 10:
        x0 *= 1000. # [pc]
        y0 *= 1000. # [pc]
        z0 *= 1000. # [pc]
    # cutting pm_i to a maximum of ntracers particles:
    import gi_helper as gh
    ind1 = gh.draw_random_subset(x0, gp.ntracer[1-1])
    x0, y0, z0, vz0 = select_pm(x0, y0, z0, vz, ind1)

    PM = np.ones(len(x0)) # assign all particles the full probability of membership
    import gi_centering as glc
    com_x, com_y, com_z, com_vz = glc.com_shrinkcircle_v(x0, y0, z0, vz, PM)
    # from now on, work with 2D data only;
    # z0 was only used to get center in (x,y) better
    x0 -= com_x  # [pc]
    y0 -= com_y  # [pc]
    vz -= com_vz # [km/s]
    R0 = np.sqrt(x0*x0+y0*y0) # [pc]
    Rscale = np.median(R0) # [pc]
    import gi_file as gf
    for pop in range(gp.pops+1):      # gp.pops +1 for all components together
        pmr = (R0<(gp.maxR*Rscale))
        #m = np.ones(len(R0))
        x = x0[pmr] # [pc]
        y = y0[pmr] # [pc]
        R = np.sqrt(x*x+y*y) # [pc]
        Rscalei = np.median(R)
        # print("x y z" on first line, to interprete data later on)
        gf.write_Xscale(gp.files.get_scale_file(pop), Rscalei)
        gf.write_data_output(gp.files.get_com_file(pop), x/Rscalei, y/Rscalei, vz, Rscalei)
Ejemplo n.º 5
0
def run(gp):
    import gr_params
    gpr = gr_params.grParams(gp)
    print('input: ', gpr.fil)
    x0,y0,z0,vb0,vz0,Mg0,PM0,comp0 = read_data(gpr.fil)
    # [pc], [km/s], [1]

    # only use stars which are members of the dwarf: exclude pop3 by
    # construction
    pm = (PM0 >= gpr.pmsplit) # exclude foreground contamination,
                              #outliers

    x0, y0, z0, comp0, vb0, vz0, Mg0, PM0 = select_pm(x0, y0, z0, comp0, vb0, vz0, Mg0, PM0, pm)

    # assign population
    if gp.pops==2:
        pm1 = (comp0 == 1) # will be overwritten below if gp.metalpop
        pm2 = (comp0 == 2) # same same
    elif gp.pops==1:
        pm1 = (comp0 < 3)
        pm2 = (comp0 == -1) # assign none, but of same length as comp0

    if gp.metalpop:
        # drawing of populations based on metallicity get parameters
        # from function in pymcmetal.py

        import pickle
        fi = open('metalsplit.dat', 'rb')
        DATA = pickle.load(fi)
        fi.close()
        p, mu1, sig1, mu2, sig2, M, pm1, pm2 = DATA

    x1, y1, z1, comp1, vb1, vz1, Mg1, PM1 = select_pm(x0, y0, z0, comp0, vb0, vz0, Mg0, PM0, pm1)
    x2, y2, z2, comp2, vb2, vz2, Mg2, PM2 = select_pm(x0, y0, z0, comp0, vb0, vz0, Mg0, PM0, pm2)

    # cut to subsets
    ind1 = gh.draw_random_subset(x1, gp.ntracer[1-1])
    x1, y1, z1, comp1, vb1, vz1, Mg1, PM1 = select_pm(x1, y1, z1, comp1, vb1, vz1, Mg1, PM1, ind1)

    ind2 = gh.draw_random_subset(x2, gp.ntracer[2-1])
    x2, y2, z2, comp2, vb2, vz2, Mg2, PM2 = select_pm(x2, y2, z2, comp2, vb2, vz2, Mg2, PM2, ind2)

    # use vz for no contamination, or vb for with contamination
    x0, y0, z0, vz0, pm1, pm2, pm = concat_pops(x1, x2, y1, y2, z1, z2, vz1, vz2, gp)
    com_x, com_y, com_z, com_vz = com_shrinkcircle_v(x0, y0, z0, vz0, pm) # [pc]
    print('COM [pc]: ', com_x, com_y, com_z)   # [pc]
    print('VOM [km/s]', com_vz)                # [km/s]

    # from now on, work with 2D data only; z0 was only used to get
    # center in (x,y) better
    x0 -= com_x # [pc]
    y0 -= com_y # [pc]
    vz0 -= com_vz # [km/s]

    R0 = np.sqrt(x0**2+y0**2) # [pc]
    Rhalf = np.median(R0) # [pc]
    Rscale = Rhalf        # [pc] from all tracer points

    pop = -1
    for pmn in [pm, pm1, pm2]:
        pop = pop + 1                    # population number
        pmr = ( R0 < (gp.maxR*Rscale) )  # read max extension for data
                                         #(rprior*Rscale) from
                                         #gi_params
        pmn = pmn*pmr                    # [1]
        print("fraction of members = ", 1.0*sum(pmn)/len(pmn))

        x, y, z, comp, vz, vb, Mg, PMN = select_pm(x0, y0, z0, comp0, vz0, vb0, Mg0, PM0, pmn)
        R = np.sqrt(x*x+y*y)             # [pc]
        Rscalei = np.median(R)
        gf.write_Xscale(gp.files.get_scale_file(pop), Rscalei)
        gf.write_data_output(gp.files.get_com_file(pop), x/Rscalei, y/Rscalei, vz, Rscalei)

        if gpr.showplots:
            gpr.show_part_pos(x, y, pmn, Rscale)
Ejemplo n.º 6
0
def run(gp):
    import gr_params
    gpr = gr_params.grParams(gp)
    gu.G1__pcMsun_1km2s_2 = 1.  # as per definition
    gp.anM = 1.  #
    gp.ana = 1.  #

    print('grh_com: input: ', gpr.simpos)
    xall, yall, zall = np.loadtxt(gpr.simpos, skiprows=1,
                                  unpack=True)  # 3*[gp.ana]
    vxall, vyall, vzall = np.loadtxt(gpr.simvel, skiprows=1,
                                     unpack=True)  # 3*[gp.ana]
    nall = len(xall)  # [1]

    # shuffle and restrict to ntracer random points
    ndm = int(min(gp.ntracer[0], nall - 1))
    trace = random.sample(range(nall), nall)
    if gp.pops > 1:
        gh.LOG(1, 'implement more than 2 pops for hern')
        pdb.set_trace()

    PM = [1.
          for i in trace]  # [1]=const, no prob. of membership info in dataset
    x = [xall[i] for i in trace]  # [gp.ana]
    y = [yall[i] for i in trace]  # [gp.ana]
    z = [zall[i] for i in trace]  # [gp.ana]
    vz = [vzall[i] for i in trace]  # [km/s]
    PM = np.array(PM)
    x = np.array(x)
    y = np.array(y)
    z = np.array(z)
    vz = np.array(vz)

    com_x, com_y, com_z, com_vz = com_shrinkcircle_v(
        x, y, z, vz, PM)  # 3*[gp.ana], [velocity]
    print('COM [gp.ana]: ', com_x, com_y, com_z, com_vz)

    xnew = (x - com_x)  #*gp.ana      # [pc]
    ynew = (y - com_y)  #*gp.ana      # [pc]
    #znew = (z-com_z) # *gp.ana      # [pc]
    vznew = (
        vz - com_vz
    )  #*1e3*np.sqrt(gu.G1__pcMsun_1km2s_2*gp.anM/gp.ana) # [km/s], from conversion from system with L=G=M=1

    R0 = np.sqrt(xnew**2 + ynew**2)  # [pc]
    Rhalf = np.median(R0)  # [pc]
    Rscale = Rhalf  # or gpr.r_DM # [pc]

    print('Rscale/pc = ', Rscale)

    # only for 0 (all) and 1 (first and only population)
    for pop in range(gp.pops + 1):
        crscale = open(gp.files.get_scale_file(pop), 'w')
        print('# Rscale in [pc],',' surfdens_central (=dens0) in [Munit/rscale**2],',\
              ' and totmass_tracers [Munit],',\
              ' and max(sigma_LOS) in [km/s]', file=crscale)
        print(Rscale, file=crscale)
        crscale.close()

        gh.LOG(2, 'grh_com: output: ', gp.files.get_com_file(pop))
        filepos = open(gp.files.get_com_file(pop), 'w')
        print('# x [Rscale]', 'y [Rscale]', 'vLOS [km/s]', file=filepos)
        for k in range(ndm):
            print(xnew[k] / Rscale, ynew[k] / Rscale, vznew[k], file=filepos)
        filepos.close()
        gh.LOG(2, '')
Ejemplo n.º 7
0
def run(gp):
    import gr_params
    gpr = gr_params.grParams(gp)
    print('input: ', gpr.fil)
    x0, y0, z0, vb0, vz0, Mg0, PM0, comp0 = read_data(gpr.fil)
    # [pc], [km/s], [1]

    # only use stars which are members of the dwarf: exclude pop3 by
    # construction
    pm = (PM0 >= gpr.pmsplit)  # exclude foreground contamination,
    #outliers

    x0, y0, z0, comp0, vb0, vz0, Mg0, PM0 = select_pm(x0, y0, z0, comp0, vb0,
                                                      vz0, Mg0, PM0, pm)

    # assign population
    if gp.pops == 2:
        pm1 = (comp0 == 1)  # will be overwritten below if gp.metalpop
        pm2 = (comp0 == 2)  # same same
    elif gp.pops == 1:
        pm1 = (comp0 < 3)
        pm2 = (comp0 == -1)  # assign none, but of same length as comp0

    if gp.metalpop:
        # drawing of populations based on metallicity get parameters
        # from function in pymcmetal.py

        import pickle
        fi = open('metalsplit.dat', 'rb')
        DATA = pickle.load(fi)
        fi.close()
        p, mu1, sig1, mu2, sig2, M, pm1, pm2 = DATA

    x1, y1, z1, comp1, vb1, vz1, Mg1, PM1 = select_pm(x0, y0, z0, comp0, vb0,
                                                      vz0, Mg0, PM0, pm1)
    x2, y2, z2, comp2, vb2, vz2, Mg2, PM2 = select_pm(x0, y0, z0, comp0, vb0,
                                                      vz0, Mg0, PM0, pm2)

    # cut to subsets
    ind1 = gh.draw_random_subset(x1, gp.ntracer[1 - 1])
    x1, y1, z1, comp1, vb1, vz1, Mg1, PM1 = select_pm(x1, y1, z1, comp1, vb1,
                                                      vz1, Mg1, PM1, ind1)

    ind2 = gh.draw_random_subset(x2, gp.ntracer[2 - 1])
    x2, y2, z2, comp2, vb2, vz2, Mg2, PM2 = select_pm(x2, y2, z2, comp2, vb2,
                                                      vz2, Mg2, PM2, ind2)

    # use vz for no contamination, or vb for with contamination
    x0, y0, z0, vz0, pm1, pm2, pm = concat_pops(x1, x2, y1, y2, z1, z2, vz1,
                                                vz2, gp)
    com_x, com_y, com_z, com_vz = com_shrinkcircle_v(x0, y0, z0, vz0,
                                                     pm)  # [pc]
    print('COM [pc]: ', com_x, com_y, com_z)  # [pc]
    print('VOM [km/s]', com_vz)  # [km/s]

    # from now on, work with 2D data only; z0 was only used to get
    # center in (x,y) better
    x0 -= com_x  # [pc]
    y0 -= com_y  # [pc]
    vz0 -= com_vz  # [km/s]

    R0 = np.sqrt(x0**2 + y0**2)  # [pc]
    Rhalf = np.median(R0)  # [pc]
    Rscale = Rhalf  # [pc] from all tracer points

    pop = -1
    for pmn in [pm, pm1, pm2]:
        pop = pop + 1  # population number
        pmr = (R0 < (gp.maxR * Rscale))  # read max extension for data
        #(rprior*Rscale) from
        #gi_params
        pmn = pmn * pmr  # [1]
        print("fraction of members = ", 1.0 * sum(pmn) / len(pmn))

        x, y, z, comp, vz, vb, Mg, PMN = select_pm(x0, y0, z0, comp0, vz0, vb0,
                                                   Mg0, PM0, pmn)
        R = np.sqrt(x * x + y * y)  # [pc]
        Rscalei = np.median(R)
        gf.write_Xscale(gp.files.get_scale_file(pop), Rscalei)
        gf.write_data_output(gp.files.get_com_file(pop), x / Rscalei,
                             y / Rscalei, vz, Rscalei)

        if gpr.showplots:
            gpr.show_part_pos(x, y, pmn, Rscale)