Beispiel #1
0
def run(gp):
    import gr_params
    gpr = gr_params.grParams(gp)

    print('input: ', gpr.fil)
    x0, y0, vlos = np.genfromtxt(gpr.fil,
                                 skiprows=0,
                                 unpack=True,
                                 usecols=(0, 1, 5))

    # use only 3000 random particles:
    ind = np.arange(len(x0))
    np.random.shuffle(ind)
    ind = ind[:3000]
    x0 = x0[ind]
    y0 = y0[ind]
    vlos = vlos[ind]

    x0 *= 1000.  # [pc]
    y0 *= 1000.  # [pc]

    # shrinking sphere method
    pm = np.ones(len(x0))
    com_x, com_y, com_vz = gc.com_shrinkcircle_v_2D(x0, y0, vlos, pm)

    x0 -= com_x  # [pc]
    y0 -= com_y  # [pc]
    vlos -= com_vz  #[km/s]

    import gi_file as gf
    for pop in range(2):
        Rc = np.sqrt(x0**2 + y0**2)  # [pc]
        Rhalf = np.median(Rc)  # [pc]
        Rscale = Rhalf  # or gpr.r_DM # [pc]
        gp.Xscale.append(Rscale)  # [pc]

        print('Rscale = ', Rscale, ' pc')
        print('max(R) = ', max(Rc), ' pc')
        print('total number of stars: ', len(Rc))

        R0 = np.sqrt(x0**2 + y0**2) / Rscale
        sel = (R0 < gp.maxR)
        x = x0[sel] / Rscale
        y = y0[sel] / Rscale  # [Rscale]
        vz = vlos[sel]  # [km/s]
        m = np.ones(len(x))
        R = np.sqrt(x * x + y * y) * Rscale  # [pc]

        gf.write_Xscale(gp.files.get_scale_file(pop), np.median(R))

        c = open(gp.files.get_com_file(pop), 'w')
        print('# x [Xscale],','y [Xscale],','vLOS [km/s],','Xscale = ', \
              Rscale, ' pc', file=c)
        for k in range(len(x)):
            print(x[k], y[k], vz[k], file=c)  #[rscale], [rscale], [km/s]
        c.close()

        if gpr.showplots:
            gpr.show_part_pos(x, y, np.ones(len(x)), Rscale)
Beispiel #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)
Beispiel #3
0
def run(gp):
    import gr_params
    gpr = gr_params.grParams(gp)

    print('input: ', gpr.fil)
    x0,y0,vlos = np.genfromtxt(gpr.fil, skiprows=0, unpack =  True,
                               usecols = (0,1,5))

    # use only 3000 random particles:
    ind = np.arange(len(x0))
    np.random.shuffle(ind)
    ind = ind[:3000]
    x0 = x0[ind];    y0 = y0[ind];    vlos = vlos[ind]

    x0 *= 1000.                         # [pc]
    y0 *= 1000.                         # [pc]

    # shrinking sphere method
    pm = np.ones(len(x0))
    com_x, com_y, com_vz = gc.com_shrinkcircle_v_2D(x0, y0, vlos, pm)

    x0 -= com_x # [pc]
    y0 -= com_y # [pc]
    vlos -= com_vz #[km/s]

    import gi_file as gf
    for pop in range(2):
        Rc = np.sqrt(x0**2+y0**2) # [pc]
        Rhalf = np.median(Rc) # [pc]
        Rscale = Rhalf # or gpr.r_DM # [pc]
        gp.Xscale.append(Rscale) # [pc]

        print('Rscale = ', Rscale,' pc')
        print('max(R) = ', max(Rc),' pc')
        print('total number of stars: ', len(Rc))

        R0 = np.sqrt(x0**2+y0**2)/Rscale
        sel = (R0 < gp.maxR)
        x = x0[sel]/Rscale; y = y0[sel]/Rscale # [Rscale]
        vz = vlos[sel] # [km/s]
        m = np.ones(len(x))
        R = np.sqrt(x*x+y*y)*Rscale # [pc]

        gf.write_Xscale(gp.files.get_scale_file(pop), np.median(R))

        c = open(gp.files.get_com_file(pop), 'w')
        print('# x [Xscale],','y [Xscale],','vLOS [km/s],','Xscale = ', \
              Rscale, ' pc', file=c)
        for k in range(len(x)):
            print(x[k], y[k], vz[k], file=c) #[rscale], [rscale], [km/s]
        c.close()

        if gpr.showplots:
            gpr.show_part_pos(x, y, np.ones(len(x)), Rscale)
Beispiel #4
0
def run(gp):
    import gr_params
    gpr = gr_params.grParams(gp)
    gpr.fil = gpr.dir + "/deBoer/table1.dat"
    ALL = np.loadtxt(gpr.fil)
    RAh = ALL[:, 0]
    RAm = ALL[:, 1]
    RAs = ALL[:, 2]
    DEd = ALL[:, 3]
    DEm = ALL[:, 4]
    DEs = ALL[:, 5]
    # that's all we read in for now. Crude assumptions: each star belongs to Fornax, and has mass 1Msun

    # only use stars which are members of the dwarf
    sig = abs(RAh[0]) / RAh[0]
    RAh = RAh / sig
    xs = 15 * (RAh * 3600 + RAm * 60 + RAs) * sig  # [arcsec/15]
    sig = abs(DEd[0]) / DEd[0]
    DEd = DEd / sig
    ys = (DEd * 3600 + DEm * 60 + DEs) * sig  # [arcsec]
    arcsec = 2. * np.pi / (360. * 60. * 60)  # [pc]
    kpc = 1000  # [pc]
    DL = {
        1: lambda x: x * (138),  #+/- 8 for Fornax
        2: lambda x: x * (101),  #+/- 5 for Carina
        3: lambda x: x * (79),  #+/- 4 for Sculptor
        4: lambda x: x * (86),  #+/- 4 for Sextans
        5: lambda x: x * (80)  #+/- 10 for Draco
    }[gp.case](kpc)

    xs *= (arcsec * DL)  # [pc]
    ys *= (arcsec * DL)  # [pc]
    x0 = np.copy(xs)
    y0 = np.copy(ys)  # [pc]
    com_x, com_y = com_shrinkcircle_2D(x0, y0)  # [pc], [km/s]
    # from now on, work with 2D data only; z0 was only used to get center in (x,y) better
    # x0 -= com_x; 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] overall
    pop = 0
    pmr = (R0 < (gp.maxR * Rscale)
           )  # read max extension for data (rprior*Rscale) from gi_params
    x = 1. * x0[pmr]
    y = 1. * y0[pmr]
    R = np.sqrt(x * x + y * y)  # [pc]
    Rscalei = np.median(R)  # [pc]
    gf.write_Xscale(gp.files.get_scale_file(pop), Rscalei)  # [pc]
    gf.write_data_output(gp.files.get_com_file(pop), x / Rscalei, y / Rscalei,
                         np.zeros(len(x)), Rscalei)  # [pc]
Beispiel #5
0
def run(gp):
    import gr_params
    gpr = gr_params.grParams(gp)
    gpr.fil = gpr.dir+"/deBoer/table1.dat"
    ALL = np.loadtxt(gpr.fil)
    RAh = ALL[:,0]
    RAm = ALL[:,1]
    RAs = ALL[:,2]
    DEd = ALL[:,3]
    DEm = ALL[:,4]
    DEs = ALL[:,5]
    # that's all we read in for now. Crude assumptions: each star belongs to Fornax, and has mass 1Msun

    # only use stars which are members of the dwarf
    sig = abs(RAh[0])/RAh[0]
    RAh = RAh/sig
    xs = 15*(RAh*3600+RAm*60+RAs)*sig       # [arcsec/15]
    sig = abs(DEd[0])/DEd[0]
    DEd = DEd/sig
    ys = (DEd*3600+DEm*60+DEs)*sig          # [arcsec]
    arcsec = 2.*np.pi/(360.*60.*60) # [pc]
    kpc = 1000 # [pc]
    DL = {1: lambda x: x * (138),#+/- 8 for Fornax
          2: lambda x: x * (101),#+/- 5 for Carina
          3: lambda x: x * (79), #+/- 4 for Sculptor
          4: lambda x: x * (86), #+/- 4 for Sextans
          5: lambda x: x * (80)  #+/- 10 for Draco
      }[gp.case](kpc)

    xs *= (arcsec*DL) # [pc]
    ys *= (arcsec*DL) # [pc]
    x0 = np.copy(xs)
    y0 = np.copy(ys) # [pc]
    com_x, com_y = com_shrinkcircle_2D(x0, y0) # [pc], [km/s]
    # from now on, work with 2D data only; z0 was only used to get center in (x,y) better
    # x0 -= com_x; 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] overall
    pop = 0
    pmr = (R0<(gp.maxR*Rscale)) # read max extension for data (rprior*Rscale) from gi_params
    x=1.*x0[pmr]
    y=1.*y0[pmr]
    R = np.sqrt(x*x+y*y)            # [pc]
    Rscalei = np.median(R)          # [pc]
    gf.write_Xscale(gp.files.get_scale_file(pop), Rscalei) # [pc]
    gf.write_data_output(gp.files.get_com_file(pop), x/Rscalei, y/Rscalei, np.zeros(len(x)), Rscalei) # [pc]
Beispiel #6
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)
Beispiel #7
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)
Beispiel #8
0
def run(gp):
    import gr_params
    gpr = gr_params.grParams(gp)
    gpr.fil = gpr.dir+"/data/tracers.dat"
    A = np.loadtxt(gpr.fil, skiprows=25)
    RAh,RAm,RAs,DEd,DEm,DEs,Vlos,e_Vlos,Teff,e_Teff,logg,e_logg,Fe,e_Fe,Nobs = A.T
    # only use stars which have Mg measurements
    pm = (Nobs>0) # (PM>=0.95)*
    print("f_members = ", gh.pretty(1.*sum(pm)/len(pm)))
    RAh=RAh[pm]
    RAm=RAm[pm]
    RAs=RAs[pm]
    DEd=DEd[pm]
    DEm=DEm[pm]
    DEs=DEs[pm]
    Vlos=Vlos[pm]
    e_Vlos=e_Vlos[pm]
    Teff=Teff[pm]
    e_Teff=e_Teff[pm]
    logg=logg[pm]
    e_logg=e_logg[pm]
    Fe=Fe[pm]
    e_Fe=e_Fe[pm]
    Nobs = Nobs[pm]

    sig = abs(RAh[0])/RAh[0]
    #print('RAh: signum = ',gh.pretty(sig))
    RAh = RAh/sig
    xs = 15*(RAh*3600+RAm*60+RAs)*sig       # [arcsec/15]

    sig = abs(DEd[0])/DEd[0]
    #print('DEd: signum = ', gh.pretty(sig))
    DEd = DEd/sig
    ys = (DEd*3600+DEm*60+DEs)*sig          # [arcsec]

    arcsec = 2.*np.pi/(360.*60.*60) # [pc]

    kpc = 1000 # [pc]
    DL = {1: lambda x: x * (138),#+/- 8 for Fornax
          2: lambda x: x * (101),#+/- 5 for Carina
          3: lambda x: x * (79), #+/- 4 for Sculptor
          4: lambda x: x * (86), #+/- 4 for Sextans
          5: lambda x: x * (80)  #+/- 10 for Draco
      }[gp.case](kpc)

    xs *= (arcsec*DL) # [pc]
    ys *= (arcsec*DL) # [pc]

    x0 = np.copy(xs)
    y0 = np.copy(ys)    # [pc]
    vz0 = np.copy(Vlos) # [km/s]
    Fe0 = np.copy(Fe)

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

    # assign population
    if gp.pops == 2:
        # drawing of populations based on metallicity
        # get parameters from function in pymcmetal.py
        #[p, mu1, sig1, mu2, sig2] = np.loadtxt(gp.files.dir+'metalsplit.dat')
        #[pm1, pm2] = np.loadtxt(gp.files.dir+'metalsplit_assignment.dat')
        popass = np.loadtxt(gp.files.dir+'popass')
        pm1 = (popass==1)
        pm2 = (popass==2)

    elif gp.pops == 1:
        pm1 = (Teff >= 0)
        pm2 = (Teff <  0) # assign none, but of same length as xs

    x1, y1, vz1, Fe1, PM1 = select_pm(x0, y0, vz0, Fe, pm, pm1)
    x2, y2, vz2, Fe2, PM2 = select_pm(x0, y0, vz0, Fe, pm, pm2)

    # cutting pm_i to a maximum of ntracers_i particles each:
    ind1 = np.arange(len(x1))
    np.random.shuffle(ind1)     # random.shuffle already changes ind
    ind1 = ind1[:gp.ntracer[1-1]]

    ind2 = np.arange(len(x2))
    np.random.shuffle(ind2)     # random.shuffle already changes ind
    ind2 = ind2[:gp.ntracer[2-1]]

    x1, y1, vz1, Fe1, PMS1 = select_pm(x1, y1, vz1, Fe1, PM1, ind1)
    x2, y2, vz2, Fe2, PMS2 = select_pm(x2, y2, vz2, Fe2, PM2, ind2)

    x0, y0, vz0, pm1, pm2, pm = concat_pops(x1, x2, y1, y2, vz1, vz2, gp)

    # optimum: get 3D center of mass with means
    # com_x, com_y, com_z = com_mean(x0,y0,z0,PM0) # 3*[pc],  z component included if available

    com_x, com_y, com_vz = com_shrinkcircle_v_2D(x0, y0, vz0, pm) # [pc], [km/s]

    # from now on, work with 2D data only; z0 was only used to get center in (x,y) better
    # x0 -= com_x; 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] overall

    pop = -1
    for pmn in [pm, pm1, pm2]:
        pop = pop+1
        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, vz, Fe, PMN = select_pm(x0, y0, vz0, Fe0, pm, pmn)

        R = np.sqrt(x*x+y*y)            # [pc]
        Rscalei = np.median(R)          # [pc]
        gf.write_Xscale(gp.files.get_scale_file(pop), Rscalei) # [pc]
        gf.write_data_output(gp.files.get_com_file(pop), x/Rscalei, y/Rscalei, vz, Rscalei) # [pc]

        if gpr.showplots:
            gpr.show_part_pos(x, y, pmn, Rscale)
Beispiel #9
0
def run(gp):
    import gr_params
    gpr = gr_params.grParams(gp)
    gpr.fil = gpr.dir + "/data/tracers.dat"
    delim = [0, 22, 3, 3, 6, 4, 3, 5, 6, 6, 7, 5, 6, 5, 6, 5, 6]
    ID = np.genfromtxt(gpr.fil,
                       skiprows=29,
                       unpack=True,
                       usecols=(0, 1),
                       delimiter=delim)
    RAh, RAm, RAs, DEd, DEm, DEs, Vmag, VI, VHel, e_VHel, SigFe, e_SigFe, SigMg, e_SigMg, PM = np.genfromtxt(
        gpr.fil,
        skiprows=29,
        unpack=True,
        usecols=tuple(range(2, 17)),
        delimiter=delim,
        filling_values=-1)

    # only use stars which have Mg measurements
    pm = (SigMg > -1) * (PM >= 0.95)
    print("f_members = ", gh.pretty(1. * sum(pm) / len(pm)))
    ID = ID[1][pm]
    RAh = RAh[pm]
    RAm = RAm[pm]
    RAs = RAs[pm]
    DEd = DEd[pm]
    DEm = DEm[pm]
    DEs = DEs[pm]
    Vmag = Vmag[pm]
    VI = VI[pm]
    VHel = VHel[pm]
    e_VHel = e_VHel[pm]
    SigFe = SigFe[pm]
    e_SigFe = e_SigFe[pm]
    SigMg = SigMg[pm]
    e_SigMg = e_SigMg[pm]
    PM = PM[pm]

    Mg0 = SigMg
    sig = abs(RAh[0]) / RAh[0]
    RAh = RAh / sig
    xs = 15 * (RAh * 3600 + RAm * 60 + RAs) * sig  # [arcsec/15]

    sig = abs(DEd[0]) / DEd[0]
    DEd = DEd / sig
    ys = (DEd * 3600 + DEm * 60 + DEs) * sig  # [arcsec]

    arcsec = 2. * np.pi / (360. * 60. * 60)  # [pc]

    kpc = 1000  # [pc]
    DL = {
        1: lambda x: x * (138),  #+/- 8 for Fornax
        2: lambda x: x * (101),  #+/- 5 for Carina
        3: lambda x: x * (79),  #+/- 4 for Sculptor
        4: lambda x: x * (86),  #+/- 4 for Sextans
        5: lambda x: x * (80)  #+/- 10 for Draco
    }[gp.case](kpc)

    xs *= (arcsec * DL)  # [pc]
    ys *= (arcsec * DL)  # [pc]

    PM0 = np.copy(PM)
    x0 = np.copy(xs)
    y0 = np.copy(ys)  # [pc]
    vz0 = np.copy(VHel)  # [km/s]

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

    # assign population
    if gp.pops == 2:
        # drawing of populations based on metallicity
        # get parameters from function in pymcmetal.py
        #[p, mu1, sig1, mu2, sig2] = np.loadtxt(gp.files.dir+'metalsplit.dat')
        #[pm1, pm2] = np.loadtxt(gp.files.dir+'metalsplit_assignment.dat')
        popass = np.loadtxt(gp.files.dir + 'popass')
        pm1 = (popass == 1)
        pm2 = (popass == 2)

    elif gp.pops == 1:
        pm1 = (PM >= 0)
        pm2 = (PM < 0)  # assign none, but of same length as xs

    x1, y1, vz1, Mg1, PM1 = select_pm(x0, y0, vz0, Mg0, PM0, pm1)
    x2, y2, vz2, Mg2, PM2 = select_pm(x0, y0, vz0, Mg0, PM0, pm2)

    # cutting pm_i to a maximum of ntracers_i particles each:
    ind1 = np.arange(len(x1))
    np.random.shuffle(ind1)  # random.shuffle already changes ind
    ind1 = ind1[:gp.ntracer[1 - 1]]

    ind2 = np.arange(len(x2))
    np.random.shuffle(ind2)  # random.shuffle already changes ind
    ind2 = ind2[:gp.ntracer[2 - 1]]

    x1, y1, vz1, Mg1, PMS1 = select_pm(x1, y1, vz1, Mg1, PM1, ind1)
    x2, y2, vz2, Mg2, PMS2 = select_pm(x2, y2, vz2, Mg2, PM2, ind2)

    x0, y0, vz0, pm1, pm2, pm = concat_pops(x1, x2, y1, y2, vz1, vz2, gp)

    # optimum: get 3D center of mass with means
    # com_x, com_y, com_z = com_mean(x0,y0,z0,PM0) # 3*[pc],  z component included if available

    com_x, com_y, com_vz = com_shrinkcircle_v_2D(x0, y0, vz0,
                                                 pm)  # [pc], [km/s]

    # from now on, work with 2D data only; z0 was only used to get center in (x,y) better
    # x0 -= com_x; 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] overall

    pop = -1
    for pmn in [pm, pm1, pm2]:
        pop = pop + 1
        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, vz, Mg, PMN = select_pm(x0, y0, vz0, Mg0, PM0, pmn)

        R = np.sqrt(x * x + y * y)  # [pc]
        Rscalei = np.median(R)  # [pc]
        gf.write_Xscale(gp.files.get_scale_file(pop), Rscalei)  # [pc]
        gf.write_data_output(gp.files.get_com_file(pop), x / Rscalei,
                             y / Rscalei, vz, Rscalei)  # [pc]

        if gpr.showplots:
            gpr.show_part_pos(x, y, pmn, Rscale)
Beispiel #10
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)
Beispiel #11
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)