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)
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)
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)
# instead of using other datasets for individual dSph, # determine Heliocentric-Rest-Frame Line-Of-Sight velocity of dwarf Vd # and position of dwarf (ad, dd) # from probability-of-membership weighted means directly Vd = np.sum(Vhel * PM) / np.sum(PM) # [km/s] ad = np.sum(alpha_s * PM) / np.sum(PM) # [arcsec] dd = np.sum(delta_s * PM) / np.sum(PM) # [arcsec] # determine distance to dwarf xs = alpha_s * DL # [pc] ys = delta_s * DL # [pc] PM0 = 1. * np.copy(PM) x0 = 1. * np.copy(xs) y0 = 1. * np.copy(ys) # [pc] # remove center displacement, already change x0 com_x, com_y, com_vz = com_shrinkcircle_v_2D(x0, y0, Vhel, PM) # [pc], [km/s] R0 = np.sqrt(x0**2 + y0**2) # sort by R0 so integral makes sense later order = np.argsort(R0) R0 = R0[order] PM0 = PM0[order] x0 = x0[order] y0 = y0[order] xs = xs[order] ys = ys[order] alpha_s = alpha_s[order] delta_s = delta_s[order] Vhel = Vhel[order] Vhel_err = Vhel_err[order] Fe = Fe[order] Fe_err = Fe_err[order]