def sgr_lam_split(stripes, params): # get lambda for stripes holder = [] for i in range(len(stripes)): mu, r, theta, phi, wedge = eval(params[i][4]), eval(params[i][5]), \ eval(params[i][6]), eval(params[i][7]), stripes[i] x, y, z = coor.stream2xyz(0.0, 0.0, 0.0, mu, r, theta * deg, phi * deg, wedge) Xs, Ys, Zs, lam, beta, r = sl.law_xyz2sgr_sun(x, y, z) #if lam > 180.0: lam = lam - 360.0 #lam = -lam print lam, beta, r, stripes[i] holder.append([lam, beta, r]) Xs, Ys, Zs, lam, beta, r = sl.law_xyz2sgr_sun(14.655646, 2.270431, -5.887377) print lam, beta, r # get lambda range for northern Sgr 15 N stripes, 0-14 -> 9-23 low_lam, high_lam = 200.0, 314.8 # from Sgr stripes: (200.025901082, 314.707561185) size = (high_lam - low_lam) / 15.0 print "# - LAMBDA BIN SIZE: {0}".format(size) for h in range(15): array = [] lam_min, lam_max = low_lam + (size * h), low_lam + (size * (h + 1)) for i in range(15): if stripes[i] == 9: num = "09" else: num = str(stripes[i]) name = "./sim_streams/sim_stripe_" + num + ".txt" Sgr = open(name, "r") for line in Sgr: if line.strip() == "": continue if line.strip()[0] == "#": continue l, b, r, f = line.strip().split() x, y, z = coor.lbr2xyz(float(l), float(b), float(r)) Xs, Ys, Zs, lam, beta, r = sl.law_xyz2sgr_sun(x, y, z) #if lam > high_lam: high_lam = lam #if lam < low_lam: low_lam = lam if lam > lam_min: if lam <= lam_max: array.append([lam, beta, r, eval(f)]) Sgr.close() print "# - Stripe " + num + " successfully read in" fi.write_data(sc.array(array), "lamsim_out_" + str(h) + ".txt", header="Lambda {0}:{1}, lam, beta, r".format( lam_min, lam_max)) #print low_lam, high_lam # bin stripes in lambda, g # correct stripes for detection, FTO efficiencies # reflect stars about midpoint to correct for missing data on far end print "### --- Done"
def sgr_density_south(stripes, params): out = [] for i in range(15, 18): mu, r, theta, phi, wedge = eval(params[i][4]), eval(params[i][5]), \ eval(params[i][6]), eval(params[i][7]), stripes[i] print mu, r, theta, phi x, y, z = coor.stream2xyz(0.0, 0.0, 0.0, mu, r, theta, phi, wedge) Xs, Ys, Zs, lam, beta, r = sl.law_xyz2sgr_sun(x, y, z) print lam, beta, r, stripes[i] name = "./sep_lbr/s1-" + str(stripes[i]) + ".txt" data = fi.read_data(name, echo=1) wedge_norm = coor.stripe_normal(stripes[i]) plane_norm = [ 0.03176573688051381, 0.98687684085235916, 0.15831942063343135 ] stream_norm = [ sc.cos(phi) * sc.sin(theta), sc.sin(phi) * sc.sin(theta), sc.cos(theta) ] print wedge_norm, stream_norm dotty = wedge_norm[0] * stream_norm[0] + wedge_norm[1] * stream_norm[ 1] + wedge_norm[2] * stream_norm[2] #dotty2 = plane_norm[0]*wedge_norm[0] + plane_norm[1]*stream_norm[1] + plane_norm[2]*stream_norm[2] if dotty > 1.0: print "!!! Not a valid dot-product: {0}".format(dotty) H = abs(2.5 / dotty) #H2 = 2.5 / sc.sqrt(1 - (dotty2*dotty2)) print "H = ", H, dotty, sc.arccos(dotty) * 180.0 / ma.pi #, H2 count, in_1, in_2 = 0, 0.0, 0.0 lam_low, lam_high = 360.0, 0.0 for j in range(len(data[:, 0])): l, b, r = data[j, 0], data[j, 1], data[j, 2] count = count + 1 # Correct for completeness Deff = 1.0 / SDSS_eff(r) in_1 = in_1 + Deff in_2 = in_2 + Deff + 1.0 / TO_eff(r) x, y, z = coor.lbr2xyz(l, b, r) Xs, Ys, Zs, lam2, beta2, r2 = sl.law_xyz2sgr_sun(x, y, z) if lam2 < lam_low: lam_low = lam2 if lam2 > lam_high: lam_high = lam2 out.append([lam, count, in_1, in_2, in_2 / H]) print "--- Lambda Range: {0}:{1}".format(lam_low, lam_high) print "### Number of stars in stream: {0}".format(count) print "### Corrected for SDSS Eff.: {0}".format(in_1) print "### Corrected for SDSS/FTO Eff: {0}".format(in_2) for o in out: print o return sc.array(out)
def show_lambda(): data = fi.read_data("./sep_lbr/s1-79.txt") x, y, z = coor.lbr2xyz(data[:, 0], data[:, 1], data[:, 2]) Xs, Ys, Zs, lam1, beta, r = sl.law_xyz2sgr_sun(x, y, z) data = fi.read_data("./sep_lbr/s1-82.txt") x, y, z = coor.lbr2xyz(data[:, 0], data[:, 1], data[:, 2]) Xs, Ys, Zs, lam2, beta, r = sl.law_xyz2sgr_sun(x, y, z) data = fi.read_data("./sep_lbr/s1-86.txt") x, y, z = coor.lbr2xyz(data[:, 0], data[:, 1], data[:, 2]) Xs, Ys, Zs, lam3, beta, r = sl.law_xyz2sgr_sun(x, y, z) plt.figure() plt.hist(lam3, 20) plt.hist(lam2, 20) plt.hist(lam1, 20) plt.show() plt.close('all')
def sgr_sim_density(stripes, params): SGA = fi.read_data("../sgrnorth_paper/stream_gen_analysis.txt", ",") low_lam, high_lam = 200.0, 314.8 # from Sgr stripes: (200.025901082, 314.707561185) size = (high_lam - low_lam) / 15.0 N_stars = [ 19386, 18734, 11096, 17044, 18736, 15409, 12519, 12248, 8853, 7328, 5479, 4450, 3486, 2425, 971, 9511, 16119, 16603 ] south = [79, 82, 86] out = [] for i in range(15): print "# - Lambda wedge {0}:".format(i) num = str(i) name = "./sim_streams/lamsim_out_" + num + ".txt" data = fi.read_data(name, echo=1) total = len(data[:, 0]) other = sc.sum(data[:, 3]) length = 7.653333333 # bin size out.append([(low_lam + (size * i) + (size * 0.5)), total - other, total, 0.0, total / length]) for i in range(15, 18): print "# - Southern wedge {0}:".format(south[i - 15]) data = fi.read_data("./sim_streams/sim_stripe_" + str(south[i - 15]) + ".txt") total = len(data[:, 0]) other = sc.sum(data[:, 3]) length = SGA[i, 3] mu, r, theta, phi, wedge = eval(params[i][4]), eval(params[i][5]), \ eval(params[i][6]), eval(params[i][7]), stripes[i] x, y, z = coor.stream2xyz(0.0, 0.0, 0.0, mu, r, theta, phi, wedge) Xs, Ys, Zs, lam, beta, r = sl.law_xyz2sgr_sun(x, y, z) out.append([lam, total - other, total, 0.0, total / length]) fi.write_data(sc.array(out), "sgrNorth_density_sim.txt", ",", " lam(mid), count, SDSS Deff, SDSS/FTO Deff, per degree")
def sgr_sim_density(stripes, params): SGA = fi.read_data("../sgrnorth_paper/stream_gen_analysis.txt", ",") low_lam, high_lam = 200.0, 314.8 # from Sgr stripes: (200.025901082, 314.707561185) size = (high_lam - low_lam) / 15.0 N_stars = [19386, 18734, 11096, 17044, 18736, 15409, 12519, 12248, 8853, 7328, 5479, 4450, 3486, 2425, 971, 9511, 16119, 16603] south = [79, 82, 86] out = [] for i in range(15): print "# - Lambda wedge {0}:".format(i) num = str(i) name = "./sim_streams/lamsim_out_"+num+".txt" data = fi.read_data(name, echo=1) total = len(data[:,0]) other = sc.sum(data[:,3]) length = 7.653333333 # bin size out.append([(low_lam+(size*i)+(size*0.5)), total-other, total, 0.0, total/length]) for i in range(15,18): print "# - Southern wedge {0}:".format(south[i-15]) data = fi.read_data("./sim_streams/sim_stripe_"+str(south[i-15])+".txt") total = len(data[:,0]) other = sc.sum(data[:,3]) length = SGA[i,3] mu, r, theta, phi, wedge = eval(params[i][4]), eval(params[i][5]), \ eval(params[i][6]), eval(params[i][7]), stripes[i] x,y,z = coor.stream2xyz(0.0, 0.0, 0.0, mu, r, theta, phi, wedge) Xs, Ys, Zs, lam, beta, r = sl.law_xyz2sgr_sun(x,y,z) out.append([lam, total-other, total, 0.0, total/length]) fi.write_data(sc.array(out), "sgrNorth_density_sim.txt", ",", " lam(mid), count, SDSS Deff, SDSS/FTO Deff, per degree")
def make_coord_table(stripes, params): """ Makes a table of the Sgr dections, in standard coordinates Stripe #, x, y, z, l, b, lam, beta, new_lam, new_beta, R""" Sgr_lbr = [5.6, -14.2, 24.0] Sgr_xyz = [14.655645800014774, 2.2704309216189817, -5.8873772610912614] Stream_North = [-0.199, 0.935, 0.293, -0.988] Stream_South = [0.032, 0.987, 0.158, -1.073] coords = [] for i, stripe in enumerate(stripes): mu, r, theta, phi = eval(params[i][4]), eval(params[i][5]), \ eval(params[i][6]), eval(params[i][7]) x, y, z = coor.stream2xyz(0.0, 0.0, 0.0, mu, r, theta*deg, phi*deg, stripe) l,b,r = coor.xyz2lbr(x,y,z) Xs, Ys, Zs, lam, beta, rs = sl.law_xyz2sgr_sun(x,y,z) if lam > 180.0: lam = lam - 360.0 # Just going to use Sgr North plane for now xp, yp, zp = coor.xyz2plane(x,y,z, new_x=Sgr_xyz, plane=Stream_North, origin=-8.5) long, lat, rp = coor.xyz2longlat(xp,yp,zp) print r, rs, rp coords.append([stripe, x, y, z, l, b, lam, beta, long, lat, r]) # Now make table coord_table = tex.DataTable(sc.array(coords), 'lcccccccccc', "Sagittarius Stream Centers", "coordtable", ["Stripe",r"$X_{GC}$",r"$Y_{GC}$",r"$Z_{GC}$",r"$l$",r"$b$", r"$\Lambda_{LM}$",r"$\Beta_{LM}$",r"$\Lambda_{new}$", r"$\Beta_{new}$", r"$R_{\sun} (kpc)$"]) tex.deluxe_table(coord_table, roundoff=1) """Sgr_lbr = [5.6, -14.2, 24.0]
def show_lambda(): data = fi.read_data("./sep_lbr/s1-79.txt") x,y,z = coor.lbr2xyz(data[:,0],data[:,1],data[:,2]) Xs,Ys,Zs,lam1,beta,r = sl.law_xyz2sgr_sun(x,y,z) data = fi.read_data("./sep_lbr/s1-82.txt") x,y,z = coor.lbr2xyz(data[:,0],data[:,1],data[:,2]) Xs,Ys,Zs,lam2,beta,r = sl.law_xyz2sgr_sun(x,y,z) data = fi.read_data("./sep_lbr/s1-86.txt") x,y,z = coor.lbr2xyz(data[:,0],data[:,1],data[:,2]) Xs,Ys,Zs,lam3,beta,r = sl.law_xyz2sgr_sun(x,y,z) plt.figure() plt.hist(lam3, 20) plt.hist(lam2, 20) plt.hist(lam1, 20) plt.show() plt.close('all')
def sgr_lam_split(stripes, params): # get lambda for stripes holder = [] for i in range(len(stripes)): mu, r, theta, phi, wedge = eval(params[i][4]), eval(params[i][5]), \ eval(params[i][6]), eval(params[i][7]), stripes[i] x,y,z = coor.stream2xyz(0.0, 0.0, 0.0, mu, r, theta*deg, phi*deg, wedge) Xs, Ys, Zs, lam, beta, r = sl.law_xyz2sgr_sun(x,y,z) #if lam > 180.0: lam = lam - 360.0 #lam = -lam print lam, beta, r, stripes[i] holder.append([lam, beta, r]) Xs, Ys, Zs, lam, beta, r = sl.law_xyz2sgr_sun(14.655646, 2.270431, -5.887377) print lam, beta, r # get lambda range for northern Sgr 15 N stripes, 0-14 -> 9-23 low_lam, high_lam = 200.0, 314.8 # from Sgr stripes: (200.025901082, 314.707561185) size = (high_lam - low_lam) / 15.0 print "# - LAMBDA BIN SIZE: {0}".format(size) for h in range(15): array = [] lam_min, lam_max = low_lam+(size*h), low_lam+(size*(h+1)) for i in range(15): if stripes[i] == 9: num = "09" else: num = str(stripes[i]) name = "./sim_streams/sim_stripe_"+num+".txt" Sgr = open(name, "r") for line in Sgr: if line.strip() == "": continue if line.strip()[0] == "#": continue l,b,r,f = line.strip().split() x,y,z = coor.lbr2xyz(float(l), float(b), float(r)) Xs, Ys, Zs, lam, beta, r = sl.law_xyz2sgr_sun(x,y,z) #if lam > high_lam: high_lam = lam #if lam < low_lam: low_lam = lam if lam > lam_min: if lam <= lam_max: array.append([lam, beta, r, eval(f)]) Sgr.close() print "# - Stripe "+num+" successfully read in" fi.write_data(sc.array(array), "lamsim_out_"+str(h)+".txt", header="Lambda {0}:{1}, lam, beta, r".format(lam_min, lam_max)) #print low_lam, high_lam # bin stripes in lambda, g # correct stripes for detection, FTO efficiencies # reflect stars about midpoint to correct for missing data on far end print "### --- Done"
def astro_test(): """ """ Sgr_lbr = [5.6, -14.2, 24.0] Sgr = coor.lbr2xyz(Sgr_lbr[0], Sgr_lbr[1], Sgr_lbr[2]) print Sgr # (14.655645800014774, 2.2704309216189817, -5.8873772610912614) Law = [-0.064, 0.970, 0.233, 0.23] #GC-centered Mine = [-0.203, 0.933, 0.298, -1.193] lam = [75.0, 85.0, 95.0, 105.0, 115.0] beta = [9.5, 10.3, 10.3, 10.7, 11.8] t = sc.arange(0.0, 2.0 * ma.pi, ma.pi / 16.0) xx = 10.0 * sc.cos(t) zz = 10.0 * sc.sin(t) x = xx #[Sgr[0], 1.0, 0.0] y = sc.zeros(len(xx)) #[Sgr[1], 0.0, 1.0] z = zz #[Sgr[2], 0.0, 0.0] # XXXXXXXX NEED SUN-CENTER LAW PLANE! lps, bps, rps = [], [], [] lams, betas, rs = [], [], [] for i in range(len(x)): xp, yp, zp = coor.xyz2plane(-x[i], y[i], z[i], new_x=Sgr, plane=Law, origin=sun[0]) lp, bp, rp = coor.xyz2longlat(xp, yp, zp) lps.append(lp) bps.append(bp) rps.append(rp) print lp, bp, rp Xs, Ys, Zs, lam, beta, r = sl.law_xyz2sgr_sun(x[i], y[i], z[i]) #, Xsun=dsun) print lam, beta, r lams.append(lam) betas.append(beta) rs.append(r) plt.figure(1) plt.scatter(lps, bps, c='b') plt.scatter(lams, betas, c='g') plt.show() #print Sgr #print coor.xyz2plane(2.0, 0.0, 0.0, [0.0,1.0,0.0], [0.0, 0.0, 1.0, 0.0]) #print xyz2plane(Sgr[0], Sgr[1], Sgr[2], [2.22222222, 3.333333333, 4.444444444], [0.0326, 0.988, 0.153, 0.0]) #print coor.xyz2plane(Sgr[0], Sgr[1], Sgr[2], list(Sgr), Law) #print coor.xyz2lambeta(Sgr[0], Sgr[1], Sgr[2], list(Sgr), Law) #print coor.xyz2plane_old(Sgr[0], Sgr[1], Sgr[2], list(Sgr), Law) #print coor.plane2xyz(15.955954308821331, 4.1893571944839891e-16, 0.12264161315188961, list(Sgr), Law) #print plane2xyz(24.0-8.5, 0.0, 0.0, list(Sgr), Law) #print plane2xyz(15.955659255114893, -0.068783217539582636, 0.14044740696010716, list(Sgr), Law) #print coor.rot_3D(Sgr[0], Sgr[1], Sgr[2], "zxz", [-183.8*rad, 76.5*rad, 201.6*rad]) print
def sgr_density_south(stripes, params): out = [] for i in range(15, 18): mu, r, theta, phi, wedge = eval(params[i][4]), eval(params[i][5]), \ eval(params[i][6]), eval(params[i][7]), stripes[i] print mu, r, theta, phi x,y,z = coor.stream2xyz(0.0, 0.0, 0.0, mu, r, theta, phi, wedge) Xs, Ys, Zs, lam, beta, r = sl.law_xyz2sgr_sun(x,y,z) print lam, beta, r, stripes[i] name = "./sep_lbr/s1-"+str(stripes[i])+".txt" data = fi.read_data(name, echo=1) wedge_norm = coor.stripe_normal(stripes[i]) plane_norm = [0.03176573688051381, 0.98687684085235916, 0.15831942063343135] stream_norm = [sc.cos(phi)*sc.sin(theta), sc.sin(phi)*sc.sin(theta), sc.cos(theta)] print wedge_norm, stream_norm dotty = wedge_norm[0]*stream_norm[0] + wedge_norm[1]*stream_norm[1] + wedge_norm[2]*stream_norm[2] #dotty2 = plane_norm[0]*wedge_norm[0] + plane_norm[1]*stream_norm[1] + plane_norm[2]*stream_norm[2] if dotty > 1.0: print "!!! Not a valid dot-product: {0}".format(dotty) H = abs(2.5 / dotty) #H2 = 2.5 / sc.sqrt(1 - (dotty2*dotty2)) print "H = ", H, dotty, sc.arccos(dotty)*180.0/ma.pi #, H2 count, in_1, in_2 = 0, 0.0, 0.0 lam_low, lam_high = 360.0, 0.0 for j in range(len(data[:,0])): l, b, r = data[j,0], data[j,1], data[j,2] count = count + 1 # Correct for completeness Deff = 1.0/SDSS_eff(r) in_1 = in_1 + Deff in_2 = in_2 + Deff + 1.0/TO_eff(r) x,y,z = coor.lbr2xyz(l,b,r) Xs, Ys, Zs, lam2, beta2, r2 = sl.law_xyz2sgr_sun(x,y,z) if lam2 < lam_low: lam_low = lam2 if lam2 > lam_high: lam_high = lam2 out.append([lam, count, in_1, in_2, in_2/H]) print "--- Lambda Range: {0}:{1}".format(lam_low, lam_high) print "### Number of stars in stream: {0}".format(count) print "### Corrected for SDSS Eff.: {0}".format(in_1) print "### Corrected for SDSS/FTO Eff: {0}".format(in_2) for o in out: print o return sc.array(out)
def astro_test(): """ """ Sgr_lbr = [5.6, -14.2, 24.0] Sgr = coor.lbr2xyz(Sgr_lbr[0], Sgr_lbr[1], Sgr_lbr[2]) print Sgr # (14.655645800014774, 2.2704309216189817, -5.8873772610912614) Law = [-0.064, 0.970, 0.233, 0.23] #GC-centered Mine = [-0.203, 0.933, 0.298, -1.193] lam = [75.0, 85.0, 95.0, 105.0, 115.0] beta = [9.5, 10.3, 10.3, 10.7, 11.8] t = sc.arange(0.0, 2.0*ma.pi, ma.pi/16.0) xx = 10.0*sc.cos(t) zz = 10.0*sc.sin(t) x = xx #[Sgr[0], 1.0, 0.0] y = sc.zeros(len(xx)) #[Sgr[1], 0.0, 1.0] z = zz #[Sgr[2], 0.0, 0.0] # XXXXXXXX NEED SUN-CENTER LAW PLANE! lps, bps, rps = [], [], [] lams, betas, rs = [], [], [] for i in range(len(x)): xp, yp, zp = coor.xyz2plane(-x[i],y[i],z[i], new_x=Sgr, plane=Law, origin=sun[0]) lp, bp, rp = coor.xyz2longlat(xp,yp,zp) lps.append(lp); bps.append(bp); rps.append(rp) print lp, bp, rp Xs, Ys, Zs, lam, beta, r = sl.law_xyz2sgr_sun(x[i],y[i],z[i]) #, Xsun=dsun) print lam, beta, r lams.append(lam); betas.append(beta); rs.append(r) plt.figure(1) plt.scatter(lps, bps, c='b') plt.scatter(lams, betas, c='g') plt.show() #print Sgr #print coor.xyz2plane(2.0, 0.0, 0.0, [0.0,1.0,0.0], [0.0, 0.0, 1.0, 0.0]) #print xyz2plane(Sgr[0], Sgr[1], Sgr[2], [2.22222222, 3.333333333, 4.444444444], [0.0326, 0.988, 0.153, 0.0]) #print coor.xyz2plane(Sgr[0], Sgr[1], Sgr[2], list(Sgr), Law) #print coor.xyz2lambeta(Sgr[0], Sgr[1], Sgr[2], list(Sgr), Law) #print coor.xyz2plane_old(Sgr[0], Sgr[1], Sgr[2], list(Sgr), Law) #print coor.plane2xyz(15.955954308821331, 4.1893571944839891e-16, 0.12264161315188961, list(Sgr), Law) #print plane2xyz(24.0-8.5, 0.0, 0.0, list(Sgr), Law) #print plane2xyz(15.955659255114893, -0.068783217539582636, 0.14044740696010716, list(Sgr), Law) #print coor.rot_3D(Sgr[0], Sgr[1], Sgr[2], "zxz", [-183.8*rad, 76.5*rad, 201.6*rad]) print
def make_coord_table(stripes, params): """ Makes a table of the Sgr dections, in standard coordinates Stripe #, x, y, z, l, b, lam, beta, new_lam, new_beta, R""" Sgr_lbr = [5.6, -14.2, 24.0] Sgr_xyz = [14.655645800014774, 2.2704309216189817, -5.8873772610912614] Stream_North = [-0.199, 0.935, 0.293, -0.988] Stream_South = [0.032, 0.987, 0.158, -1.073] coords = [] for i, stripe in enumerate(stripes): mu, r, theta, phi = eval(params[i][4]), eval(params[i][5]), \ eval(params[i][6]), eval(params[i][7]) x, y, z = coor.stream2xyz(0.0, 0.0, 0.0, mu, r, theta * deg, phi * deg, stripe) l, b, r = coor.xyz2lbr(x, y, z) Xs, Ys, Zs, lam, beta, rs = sl.law_xyz2sgr_sun(x, y, z) if lam > 180.0: lam = lam - 360.0 # Just going to use Sgr North plane for now xp, yp, zp = coor.xyz2plane(x, y, z, new_x=Sgr_xyz, plane=Stream_North, origin=-8.5) long, lat, rp = coor.xyz2longlat(xp, yp, zp) print r, rs, rp coords.append([stripe, x, y, z, l, b, lam, beta, long, lat, r]) # Now make table coord_table = tex.DataTable( sc.array(coords), 'lcccccccccc', "Sagittarius Stream Centers", "coordtable", [ "Stripe", r"$X_{GC}$", r"$Y_{GC}$", r"$Z_{GC}$", r"$l$", r"$b$", r"$\Lambda_{LM}$", r"$\Beta_{LM}$", r"$\Lambda_{new}$", r"$\Beta_{new}$", r"$R_{\sun} (kpc)$" ]) tex.deluxe_table(coord_table, roundoff=1) """Sgr_lbr = [5.6, -14.2, 24.0]
def sgr_density(stripes, params): # get lambda for stripes holder = [] for i in range(len(stripes)): mu, r, theta, phi, wedge = eval(params[i][4]), eval(params[i][5]), \ eval(params[i][6]), eval(params[i][7]), stripes[i] x, y, z = coor.stream2xyz(0.0, 0.0, 0.0, mu, r, theta, phi, wedge) Xs, Ys, Zs, lam, beta, r = sl.law_xyz2sgr_sun(x, y, z) #if lam > 180.0: lam = lam - 360.0 #lam = -lam print lam, beta, r, stripes[i] holder.append([lam, beta, r]) Xs, Ys, Zs, lam, beta, r = sl.law_xyz2sgr_sun(14.655646, 2.270431, -5.887377) print lam, beta, r # Get distances as a function of Lamda, using straight pipes to connect points. LAB = [ ] # lambda, A, B such that: R = A(lam) + B; C,D st beta = C(lam) + D for i in range(15 - 1): # all but end A = (holder[i + 1][2] - holder[i][2]) / ( holder[i + 1][0] - holder[i][0]) # R2-R1/L2-L1 B = holder[i][2] - A * holder[i][0] # R1 - A*L1 C = (holder[i + 1][1] - holder[i][1]) / ( holder[i + 1][0] - holder[i][0]) # B2-B1/L2-L1 D = holder[i][1] - C * holder[i][0] # B1 - A*L1 LAB.append([holder[i + 1][0], A, B, C, D]) # get lambda range for northern Sgr 15 N stripes, 0-14 -> 9-23 low_lam, high_lam = 200.0, 314.8 # from Sgr stripes: (200.025901082, 314.707561185) size = (high_lam - low_lam) / 15.0 print "# - LAMBDA BIN SIZE: {0}".format(size) out = [] for i in range(15): killed = 0 print "# - Lambda wedge {0}:".format(i) num = str(i) name = "./Lambda_outs/lamsim_out_" + num + ".txt" data = fi.read_data(name, echo=1) count, in_1, in_2, in_0 = 0, 0.0, 0.0, 0.0 sigma = params[i][8] for j in range(len(data[:, 0])): lam, beta, r = data[j, 0], data[j, 1], data[j, 2] count = count + 1 index = 0 while data[j, 0] > LAB[index][0]: index = index + 1 if (index == len(LAB) - 1): break # correct for missing far edge by counting all near edge and doubling A, B = LAB[index][1], LAB[index][2] if r > (A * lam + B) / sc.cos(beta): killed = killed + 1 continue #D = (0.295*lam - 42.601)/sc.cos(beta) #if r > D: killed=killed+1; continue # correct for missing side edge by counting inner and doubling #C, D = LAB[index][3], LAB[index][4] #if beta > (C*lam + D): continue # Correct for completeness Deff = 1.0 / SDSS_eff(r) in_0 = in_0 + 1.0 in_1 = in_1 + Deff in_2 = in_2 + Deff / TO_eff(r) out.append([(low_lam + (size * i) + (size * 0.5)), count, in_1, in_2, in_2 / size]) print "### Number of stars in stream: {0}".format(count) print "### KILLED: {0}".format(killed) print "### Remaining Stars: {0}".format(in_0 * 1.0) print "### Corrected for SDSS Eff.: {0}".format(in_1 * 2.0) print "### Corrected for SDSS/FTO Eff: {0}".format(in_2 * 2.0) #print out return sc.array(out)
def dist(l, b, lam, beta): x, y, z = coor.lbr2xyz(l, b, r) x0, y0, z0, lam0, beta0, r0 = sl.law_xyz2sgr_sun(x, y, z) one = (lam0 - lam) * (lam0 - lam) two = (beta0 - beta) * (beta0 - beta) return sc.sqrt(one + two)
def width_plot(stripes, params): data = fi.read_data("../sgrnorth_paper/sgrNorth_density_sim.txt", ",") #Ben = fi.read_data("../sgrnorth_paper/bensgr_lam_bins.dat") #Law = fi.read_data("../sgrnorth_paper/lawsgr_lam_bins.dat") Law = fi.read_data("../sgrnorth_paper/lawsgrTRX_lam_binsC.dat") sph = fi.read_data("../sgrnorth_paper/lawsgrSPH_lam_binsC.dat") obl = fi.read_data("../sgrnorth_paper/lawsgrOBL_lam_binsC.dat") pro = fi.read_data("../sgrnorth_paper/lawsgrPRO_lam_binsC.dat") LM10 = fi.read_data("../sgrnorth_paper/lawsgrTRX_widthsC.dat") #2 wp = fi.read_data("../sgrnorth_paper/lawsgrPRO_widthsC.dat") ws = fi.read_data("../sgrnorth_paper/lawsgrSPH_widthsC.dat") wo = fi.read_data("../sgrnorth_paper/lawsgrOBL_widthsC.dat") errors = sc.array([ 0.775105, 0.47734, 0.836774, 1.882841, 0.932078, 1.531246, 1.653404, 0.593513, 0.853309, 0.469178, 3.053077, 0.314356, 0.388961, 1.21, 2.330186, 0.142532, 0.989839, 0.541965 ]) sigma, slam = [], [] for i in range(len(stripes)): mu, r, theta, phi, wedge = eval(params[i][4]), eval(params[i][5]), \ eval(params[i][6]), eval(params[i][7]), stripes[i] #print mu, r, theta, phi x, y, z = coor.stream2xyz(0.0, 0.0, 0.0, mu, r, theta, phi, wedge) Xs, Ys, Zs, lam, beta, r = sl.law_xyz2sgr_sun(x, y, z) slam.append(lam) for param in params: sigma.append(2.35482 * eval(param[8])) fig = plt.figure(1) plt.subplots_adjust(hspace=0.001, wspace=0.001) # density along stream plot sp1 = plt.subplot(211) color = [ 'w', 'w', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'w', 'w', 'w', 'k', 'k', 'k' ] #plt.scatter(data[:,0], data[:,4]*1.0, facecolor=color, marker="s", # label="Expected Counts") plt.scatter(data[:, 0], data[:, 4], facecolor=color, marker="^", label="__nolabel__") plt.scatter(data[:, 0], data[:, 1] * (data[:, 4] / data[:, 2]), facecolor=color, marker="o", label="__nolabel__") #plt.errorbar([315.0, 315.0, 315.0, 312.0, 312.0, 312.0], [1000, 2000, 3000, 1000, 2000, 3000], # yerr=[39.2, 51.5, 80.0, 33.2, 43.6, 53.8], fmt="o", markersize=1, # mfc="red", ecolor="red", label="Typical Errors") #71.8 #plt.plot(Ben[:,0], Ben[:,1]*0.2, "k--") #0.1 a, b = 21, 23 plt.plot(obl[:a, 0], obl[:a, 1] * 7.0, "r:", label="Oblate") plt.plot(obl[b:, 0], obl[b:, 1] * 7.0, "r:", label=None) plt.plot(sph[:a, 0], sph[:a, 1] * 7.0, "k-.", label="Spherical", linewidth=1.5) plt.plot(sph[b:, 0], sph[b:, 1] * 7.0, "k-.", label=None, linewidth=1.5) plt.plot(pro[:a, 0], pro[:a, 1] * 7.0, "b--", label="Prolate") plt.plot(pro[b:, 0], pro[b:, 1] * 7.0, "b--", label=None) plt.plot(Law[:a, 0], Law[:a, 1] * 6.0, "k-", label="L&M10 Nbody") # 1.5 plt.plot(Law[b:, 0], Law[b:, 1] * 6.0, "k-", label=None) # 1.5 #sp1.annotate('Triaxial', xy=(178, 3200), xytext=(210, 3650), fontsize=8, # arrowprops=dict(facecolor='black', shrink=0.05, width=0.5, headwidth=3) ) #sp1.annotate('Prolate', xy=(192, 3000), xytext=(215, 3350), fontsize=8, # arrowprops=dict(facecolor='black', shrink=0.05, width=0.5, headwidth=3) ) #sp1.annotate('Spherical', xy=(199, 2750), xytext=(220, 3050), fontsize=8, # arrowprops=dict(facecolor='black', shrink=0.05, width=0.5, headwidth=3) ) #sp1.annotate('Oblate', xy=(205, 2500), xytext=(225, 2800), fontsize=8, # arrowprops=dict(facecolor='black', shrink=0.05, width=0.5, headwidth=3) ) #plt.scatter(Ben[:,0], Ben[:,1]*0.5, facecolor="blue", marker="x") #plt.scatter(Law[:,0], Law[:,1], facecolor="red", marker="+") spoof1 = plt.scatter(180.0, -10.0, facecolor='k', marker="^", label="Expected Counts") #spoof spoof2 = plt.scatter(180.0, -10.0, facecolor='k', marker="o", label="Raw Counts") #spoof plt.setp(sp1.get_xticklabels(), visible=False) plt.ylim(0.0, 6000.0) plt.ylabel("Stars per degree", fontsize=12) # legend leg1 = sp1.legend(loc='upper center', numpoints=2) for t in leg1.get_texts(): t.set_fontsize(10) # ---------------- FWHM v lambda plot -------------------- sp2 = plt.subplot(212, sharex=sp1) g_mean = np.sqrt(LM10[:, 3] * LM10[:, 4]) #geometric mean plt.errorbar(slam, sigma, yerr=2.35482 * errors, fmt="d", mfc="black", ecolor="black", label="MLE Fits") #plt.scatter(slam, sigma, facecolor="black", marker="o", label=None) plt.plot(LM10[:21, 0], 2.35482 * g_mean[:21], "k-", label=None) plt.plot(LM10[21:, 0], 2.35482 * g_mean[21:], "k-", label=None) # NEW STUFF aa, bb = 21, 21 plt.plot(wp[:aa, 0], 2.35482 * np.sqrt(wp[:aa, 3] * wp[:aa, 4]), "b--", label=None) plt.plot(wp[bb:, 0], 2.35482 * np.sqrt(wp[bb:, 3] * wp[bb:, 4]), "b--", label=None) plt.plot(ws[:aa, 0], 2.35482 * np.sqrt(ws[:aa, 3] * ws[:aa, 4]), "k-.", label=None) plt.plot(ws[bb:, 0], 2.35482 * np.sqrt(ws[bb:, 3] * ws[bb:, 4]), "k-.", label=None) plt.plot(wo[:aa, 0], 2.35482 * np.sqrt(wo[:aa, 3] * wo[:aa, 4]), "r:", label=None) plt.plot(wo[bb + 3:, 0], 2.35482 * np.sqrt(wo[bb + 3:, 3] * wo[bb + 3:, 4]), "r:", label=None) #plt.scatter(LM10[:,0], 2.35482*g_mean, facecolor='black', marker='+', label="L&M10 Nbody") # legend leg2 = sp2.legend(loc='lower right', numpoints=1) for t in leg2.get_texts(): t.set_fontsize(8) plt.xlabel(r"$\Lambda_{\odot}$") plt.ylabel(r"FWHM (kpc)") plt.ylim(0.0, 20.0) plt.xlim(320.0, 70.0) # 70, 320 #plt.xticks(sc.arange(80.0, 320.0, 20.0)) plt.show()
def sgr_density(stripes, params): # get lambda for stripes holder = [] for i in range(len(stripes)): mu, r, theta, phi, wedge = eval(params[i][4]), eval(params[i][5]), \ eval(params[i][6]), eval(params[i][7]), stripes[i] x,y,z = coor.stream2xyz(0.0, 0.0, 0.0, mu, r, theta, phi, wedge) Xs, Ys, Zs, lam, beta, r = sl.law_xyz2sgr_sun(x,y,z) #if lam > 180.0: lam = lam - 360.0 #lam = -lam print lam, beta, r, stripes[i] holder.append([lam, beta, r]) Xs, Ys, Zs, lam, beta, r = sl.law_xyz2sgr_sun(14.655646, 2.270431, -5.887377) print lam, beta, r # Get distances as a function of Lamda, using straight pipes to connect points. LAB = [] # lambda, A, B such that: R = A(lam) + B; C,D st beta = C(lam) + D for i in range(15-1): # all but end A = (holder[i+1][2]-holder[i][2])/(holder[i+1][0]-holder[i][0]) # R2-R1/L2-L1 B = holder[i][2] - A*holder[i][0] # R1 - A*L1 C = (holder[i+1][1]-holder[i][1])/(holder[i+1][0]-holder[i][0]) # B2-B1/L2-L1 D = holder[i][1] - C*holder[i][0] # B1 - A*L1 LAB.append([holder[i+1][0], A, B, C, D]) # get lambda range for northern Sgr 15 N stripes, 0-14 -> 9-23 low_lam, high_lam = 200.0, 314.8 # from Sgr stripes: (200.025901082, 314.707561185) size = (high_lam - low_lam) / 15.0 print "# - LAMBDA BIN SIZE: {0}".format(size) out = [] for i in range(15): killed = 0 print "# - Lambda wedge {0}:".format(i) num = str(i) name = "./Lambda_outs/lamsim_out_"+num+".txt" data = fi.read_data(name, echo=1) count, in_1, in_2, in_0 = 0, 0.0, 0.0, 0.0 sigma = params[i][8] for j in range(len(data[:,0])): lam, beta, r = data[j,0], data[j,1], data[j,2] count = count + 1 index = 0 while data[j,0] > LAB[index][0]: index = index + 1 if (index == len(LAB)-1): break # correct for missing far edge by counting all near edge and doubling A, B = LAB[index][1], LAB[index][2] if r > (A*lam + B)/sc.cos(beta): killed=killed+1; continue #D = (0.295*lam - 42.601)/sc.cos(beta) #if r > D: killed=killed+1; continue # correct for missing side edge by counting inner and doubling #C, D = LAB[index][3], LAB[index][4] #if beta > (C*lam + D): continue # Correct for completeness Deff = 1.0/SDSS_eff(r) in_0 = in_0 + 1.0 in_1 = in_1 + Deff in_2 = in_2 + Deff/TO_eff(r) out.append([(low_lam+(size*i)+(size*0.5)), count, in_1, in_2, in_2/size]) print "### Number of stars in stream: {0}".format(count) print "### KILLED: {0}".format(killed) print "### Remaining Stars: {0}".format(in_0*1.0) print "### Corrected for SDSS Eff.: {0}".format(in_1*2.0) print "### Corrected for SDSS/FTO Eff: {0}".format(in_2*2.0) #print out return sc.array(out)
verbose = 0 for i in range(len(lam_out)): d0, scale = 100.0, 1.0 l0, b0 = 0.0, 0.0 l_base, b_base = center_l, center_b lam, beta = lam_out[i], beta_out[i] x, changed = 0, 0 while x < 15: for dl in l_steps: l = l_base + dl * scale for db in b_steps: b = b_base + db * scale d = dist(l, b, lam, beta) if d < d0: l0, b0, d0 = l, b, d changed = 1 if verbose == 1: print "Current l,b,d: {0}, {1}, {2}".format(l0, b0, d0) x0, y0, z0 = coor.lbr2xyz(l0, b0, r) print sl.law_xyz2sgr_sun(x0, y0, z0)[3:] if d0 < pres: print "# - Exiting by threshold" break scale = scale / 2.0 l_base, b_base = l0, b0 x = x + 1 print "# - For lamda, beta = ({0},{1}), l,b,d = {2}, {3}, {4}".format( lam, beta, l0, b0, d0) x0, y0, z0 = coor.lbr2xyz(l0, b0, r) print "# - {0}".format(sl.law_xyz2sgr_sun(x0, y0, z0)[3:])
def width_plot(stripes, params): data = fi.read_data("../sgrnorth_paper/sgrNorth_density_sim.txt", ",") #Ben = fi.read_data("../sgrnorth_paper/bensgr_lam_bins.dat") #Law = fi.read_data("../sgrnorth_paper/lawsgr_lam_bins.dat") Law = fi.read_data("../sgrnorth_paper/lawsgrTRX_lam_binsC.dat") sph = fi.read_data("../sgrnorth_paper/lawsgrSPH_lam_binsC.dat") obl = fi.read_data("../sgrnorth_paper/lawsgrOBL_lam_binsC.dat") pro = fi.read_data("../sgrnorth_paper/lawsgrPRO_lam_binsC.dat") LM10 = fi.read_data("../sgrnorth_paper/lawsgrTRX_widthsC.dat") #2 wp = fi.read_data("../sgrnorth_paper/lawsgrPRO_widthsC.dat") ws = fi.read_data("../sgrnorth_paper/lawsgrSPH_widthsC.dat") wo = fi.read_data("../sgrnorth_paper/lawsgrOBL_widthsC.dat") errors = sc.array([0.775105, 0.47734, 0.836774, 1.882841, 0.932078, 1.531246, 1.653404, 0.593513, 0.853309, 0.469178, 3.053077, 0.314356, 0.388961, 1.21, 2.330186, 0.142532, 0.989839, 0.541965]) sigma, slam = [], [] for i in range(len(stripes)): mu, r, theta, phi, wedge = eval(params[i][4]), eval(params[i][5]), \ eval(params[i][6]), eval(params[i][7]), stripes[i] #print mu, r, theta, phi x,y,z = coor.stream2xyz(0.0, 0.0, 0.0, mu, r, theta, phi, wedge) Xs, Ys, Zs, lam, beta, r = sl.law_xyz2sgr_sun(x,y,z) slam.append(lam) for param in params: sigma.append(2.35482*eval(param[8])) fig = plt.figure(1) plt.subplots_adjust(hspace=0.001, wspace=0.001) # density along stream plot sp1 = plt.subplot(211) color = ['w', 'w', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'w', 'w', 'w', 'k', 'k', 'k'] #plt.scatter(data[:,0], data[:,4]*1.0, facecolor=color, marker="s", # label="Expected Counts") plt.scatter(data[:,0], data[:,4], facecolor=color, marker="^", label="__nolabel__") plt.scatter(data[:,0], data[:,1]*(data[:,4]/data[:,2]), facecolor=color, marker="o", label="__nolabel__") #plt.errorbar([315.0, 315.0, 315.0, 312.0, 312.0, 312.0], [1000, 2000, 3000, 1000, 2000, 3000], # yerr=[39.2, 51.5, 80.0, 33.2, 43.6, 53.8], fmt="o", markersize=1, # mfc="red", ecolor="red", label="Typical Errors") #71.8 #plt.plot(Ben[:,0], Ben[:,1]*0.2, "k--") #0.1 a, b = 21, 23 plt.plot(obl[:a,0], obl[:a,1]*7.0, "r:", label="Oblate") plt.plot(obl[b:,0], obl[b:,1]*7.0, "r:", label=None) plt.plot(sph[:a,0], sph[:a,1]*7.0, "k-.", label="Spherical", linewidth=1.5) plt.plot(sph[b:,0], sph[b:,1]*7.0, "k-.", label=None, linewidth=1.5) plt.plot(pro[:a,0], pro[:a,1]*7.0, "b--", label="Prolate") plt.plot(pro[b:,0], pro[b:,1]*7.0, "b--", label=None) plt.plot(Law[:a,0], Law[:a,1]*6.0, "k-", label="L&M10 Nbody") # 1.5 plt.plot(Law[b:,0], Law[b:,1]*6.0, "k-", label=None) # 1.5 #sp1.annotate('Triaxial', xy=(178, 3200), xytext=(210, 3650), fontsize=8, # arrowprops=dict(facecolor='black', shrink=0.05, width=0.5, headwidth=3) ) #sp1.annotate('Prolate', xy=(192, 3000), xytext=(215, 3350), fontsize=8, # arrowprops=dict(facecolor='black', shrink=0.05, width=0.5, headwidth=3) ) #sp1.annotate('Spherical', xy=(199, 2750), xytext=(220, 3050), fontsize=8, # arrowprops=dict(facecolor='black', shrink=0.05, width=0.5, headwidth=3) ) #sp1.annotate('Oblate', xy=(205, 2500), xytext=(225, 2800), fontsize=8, # arrowprops=dict(facecolor='black', shrink=0.05, width=0.5, headwidth=3) ) #plt.scatter(Ben[:,0], Ben[:,1]*0.5, facecolor="blue", marker="x") #plt.scatter(Law[:,0], Law[:,1], facecolor="red", marker="+") spoof1 = plt.scatter(180.0, -10.0, facecolor='k', marker="^", label="Expected Counts") #spoof spoof2 = plt.scatter(180.0, -10.0, facecolor='k', marker="o", label="Raw Counts") #spoof plt.setp(sp1.get_xticklabels(), visible=False) plt.ylim(0.0, 6000.0) plt.ylabel("Stars per degree", fontsize=12) # legend leg1 = sp1.legend(loc='upper center', numpoints=2) for t in leg1.get_texts(): t.set_fontsize(10) # ---------------- FWHM v lambda plot -------------------- sp2 = plt.subplot(212, sharex=sp1) g_mean = np.sqrt(LM10[:,3]*LM10[:,4]) #geometric mean plt.errorbar(slam, sigma, yerr=2.35482*errors, fmt="d", mfc="black", ecolor="black", label="MLE Fits") #plt.scatter(slam, sigma, facecolor="black", marker="o", label=None) plt.plot(LM10[:21,0], 2.35482*g_mean[:21], "k-", label=None) plt.plot(LM10[21:,0], 2.35482*g_mean[21:], "k-", label=None) # NEW STUFF aa, bb = 21, 21 plt.plot(wp[:aa,0], 2.35482*np.sqrt(wp[:aa,3]*wp[:aa,4]), "b--", label=None) plt.plot(wp[bb:,0], 2.35482*np.sqrt(wp[bb:,3]*wp[bb:,4]), "b--", label=None) plt.plot(ws[:aa,0], 2.35482*np.sqrt(ws[:aa,3]*ws[:aa,4]), "k-.", label=None) plt.plot(ws[bb:,0], 2.35482*np.sqrt(ws[bb:,3]*ws[bb:,4]), "k-.", label=None) plt.plot(wo[:aa,0], 2.35482*np.sqrt(wo[:aa,3]*wo[:aa,4]), "r:", label=None) plt.plot(wo[bb+3:,0], 2.35482*np.sqrt(wo[bb+3:,3]*wo[bb+3:,4]), "r:", label=None) #plt.scatter(LM10[:,0], 2.35482*g_mean, facecolor='black', marker='+', label="L&M10 Nbody") # legend leg2 = sp2.legend(loc='lower right', numpoints=1) for t in leg2.get_texts(): t.set_fontsize(8) plt.xlabel(r"$\Lambda_{\odot}$") plt.ylabel(r"FWHM (kpc)") plt.ylim(0.0, 20.0) plt.xlim(320.0, 70.0) # 70, 320 #plt.xticks(sc.arange(80.0, 320.0, 20.0)) plt.show()
def dist(l,b,lam, beta): x,y,z = coor.lbr2xyz(l,b,r) x0,y0,z0,lam0,beta0,r0 = sl.law_xyz2sgr_sun(x,y,z) one = (lam0 - lam)*(lam0 - lam) two = (beta0 - beta)*(beta0 - beta) return sc.sqrt(one + two)
def lb2sgr(l,b,r): x,y,z = lbr2xyz(l,b,r) return sl.law_xyz2sgr_sun(x,y,z)
x0,y0,z0,lam0,beta0,r0 = sl.law_xyz2sgr_sun(x,y,z) one = (lam0 - lam)*(lam0 - lam) two = (beta0 - beta)*(beta0 - beta) return sc.sqrt(one + two) verbose = 0 for i in range(len(lam_out)): d0, scale = 100.0, 1.0 l0, b0 = 0.0, 0.0 l_base, b_base = center_l, center_b lam, beta = lam_out[i], beta_out[i] x, changed = 0, 0 while x<15: for dl in l_steps: l = l_base + dl*scale for db in b_steps: b = b_base + db*scale d = dist(l,b,lam,beta) if d < d0: l0, b0, d0 = l, b, d; changed=1 if verbose==1: print "Current l,b,d: {0}, {1}, {2}".format(l0,b0,d0) x0,y0,z0 = coor.lbr2xyz(l0,b0,r) print sl.law_xyz2sgr_sun(x0,y0,z0)[3:] if d0 < pres: print "# - Exiting by threshold"; break scale = scale/2.0 l_base, b_base = l0, b0 x=x+1 print "# - For lamda, beta = ({0},{1}), l,b,d = {2}, {3}, {4}".format(lam,beta,l0,b0,d0) x0,y0,z0 = coor.lbr2xyz(l0,b0,r) print "# - {0}".format(sl.law_xyz2sgr_sun(x0,y0,z0)[3:])