def results_to_table(stripes, params): """ Build latex tables from a file of results """ # Background params bg_data = [] for i, stripe in enumerate(stripes): #print i, stripe, params[i] bg_data.append([stripe, params[i][1], params[i][2] ]) bg_table = tex.DataTable(sc.array(bg_data), 'lcc', "Spheroid Parameters", "spheroidtable", ["Stripe","$q$","$r_0$"]) tex.deluxe_table(bg_table, roundoff=3) # Sgr params sgr_data = [] for i, stripe in enumerate(stripes): if stripe==9 or stripe==22 or stripe==82: theta, phi = (ma.pi-eval(params[i][6]) ), (eval(params[i][7]) + ma.pi) #not sure if needed anymore else: theta, phi = eval(params[i][6]), eval(params[i][7]) theta, phi = coor.angle_bounds3(theta*deg, phi*deg, phi_max=180.0) theta, phi = theta*rad, phi*rad sgr_data.append([stripe, params[i][3], params[i][4], params[i][5], str(theta), str(phi), params[i][8] ]) sgr_table = tex.DataTable(sc.array(sgr_data), 'lcccccc', "Sagittarius Stream Parameters", "sgrtable", ["Stripe","$\epsilon$","$\mu$ ({}^{\circ})", "R (kpc)", "\theta (rad)", "\phi (rad)", "\sigma"]) tex.deluxe_table(sgr_table, roundoff=3)
def integrate_stripes(stripes, fit): mu_min = [170.0, 165.0, 150.0, 135.0, 135.0, 135.0, 135.0, 135.0, 135.0, 135.0, 135.0, 133.0, 133.0, 131.0, 133.0, 311.0, 310.0, 310.0] mu_max = [235.0, 227.0, 229.0, 235.0, 235.0, 235.0, 240.0, 240.0, 235.0, 240.0, 230.0, 249.0, 210.0, 225.0, 230.0, 416.0, 419.0, 420.0] N_stars = [19386, 18734, 11096, 17044, 18736, 15409, 12519, 12248, 8853, 7328, 5479, 4450, 3486, 2425, 971, 9511, 16119, 16603] deg = 180.0/ma.pi for i in range(len(stripes)): if stripes[i] != 82: continue params = twg.ParamSet() params.wedge = stripes[i] params.background = [0.0, 1.0, float(fit[i][1]), float(fit[i][2]), 1.0] # flip the weird angles, and convert to degrees if stripes[i]==9 or stripes[i]==22 or stripes[i]==82: theta, phi = (ma.pi-eval(fit[i][6]) ), (eval(fit[i][7]) + ma.pi) else: theta, phi = eval(fit[i][6]), eval(fit[i][7]) theta, phi = coor.angle_bounds3(theta*deg, phi*deg, phi_max=180.0) params.streams = [ [float(fit[i][3]), float(fit[i][4]), float(fit[i][5]), 94.682, 116.0, float(fit[i][8])] ] #normal to 82 #params.streams = [ [float(fit[i][3]), float(fit[i][4]), float(fit[i][5]), # theta, phi, float(fit[i][8])] ] # Set g limits if (stripes[i]==9) or (stripes[i]==10): g_max = 23.5 elif (stripes[i]==11) or (stripes[i]==12): g_max = 23.0 else: g_max = 22.5 params.stripe = [(mu_min[i], mu_max[i], 10),(-1.25, 1.25, 10),(16.0,g_max,10)] params.update_refs() params.print_params() name = "sim_stripe_"+str(stripes[i])+"_NormNoCon.txt" print "STARTING: "+name stream_gen(params, 0, N_stars[i], fileout=name, convolve=0)
def make_table_werrors(stripes, params): file2 = "../sgrnorth_paper/results_errors_final.txt" errors = fi.read_data(file2) for i, stripe in enumerate(stripes): if stripe == 9 or stripe == 22 or stripe == 82: theta, phi = (ma.pi - eval(params[i][6])), ( eval(params[i][7]) + ma.pi) #not sure if needed anymore else: theta, phi = float(params[i][6]), float(params[i][7]) theta, phi = coor.angle_bounds3(theta * deg, phi * deg, phi_max=180.0) theta, phi = theta * rad, phi * rad fit = [ stripe, float(params[i][3]), float(params[i][4]), float(params[i][5]), theta, phi, float(params[i][8]) ] # put it together out = str(stripe) + " & " for j in range(2, 8): out = out + str(round(fit[j - 1], 2)) + r" \pm " + str( round(errors[i, j], 2)) + r" & " out = out + r" \\" print out, "\n" back = [ stripe, ]
def results_to_table(stripes, params): """ Build latex tables from a file of results """ # Background params bg_data = [] for i, stripe in enumerate(stripes): #print i, stripe, params[i] bg_data.append([stripe, params[i][1], params[i][2]]) bg_table = tex.DataTable(sc.array(bg_data), 'lcc', "Spheroid Parameters", "spheroidtable", ["Stripe", "$q$", "$r_0$"]) tex.deluxe_table(bg_table, roundoff=3) # Sgr params sgr_data = [] for i, stripe in enumerate(stripes): if stripe == 9 or stripe == 22 or stripe == 82: theta, phi = (ma.pi - eval(params[i][6])), ( eval(params[i][7]) + ma.pi) #not sure if needed anymore else: theta, phi = eval(params[i][6]), eval(params[i][7]) theta, phi = coor.angle_bounds3(theta * deg, phi * deg, phi_max=180.0) theta, phi = theta * rad, phi * rad sgr_data.append([ stripe, params[i][3], params[i][4], params[i][5], str(theta), str(phi), params[i][8] ]) sgr_table = tex.DataTable( sc.array(sgr_data), 'lcccccc', "Sagittarius Stream Parameters", "sgrtable", [ "Stripe", "$\epsilon$", "$\mu$ ({}^{\circ})", "R (kpc)", "\theta (rad)", "\phi (rad)", "\sigma" ]) tex.deluxe_table(sgr_table, roundoff=3)
def integrate_stripes(stripes, fit): mu_min = [ 170.0, 165.0, 150.0, 135.0, 135.0, 135.0, 135.0, 135.0, 135.0, 135.0, 135.0, 133.0, 133.0, 131.0, 133.0, 311.0, 310.0, 310.0 ] mu_max = [ 235.0, 227.0, 229.0, 235.0, 235.0, 235.0, 240.0, 240.0, 235.0, 240.0, 230.0, 249.0, 210.0, 225.0, 230.0, 416.0, 419.0, 420.0 ] N_stars = [ 19386, 18734, 11096, 17044, 18736, 15409, 12519, 12248, 8853, 7328, 5479, 4450, 3486, 2425, 971, 9511, 16119, 16603 ] deg = 180.0 / ma.pi for i in range(len(stripes)): if stripes[i] != 82: continue params = twg.ParamSet() params.wedge = stripes[i] params.background = [0.0, 1.0, float(fit[i][1]), float(fit[i][2]), 1.0] # flip the weird angles, and convert to degrees if stripes[i] == 9 or stripes[i] == 22 or stripes[i] == 82: theta, phi = (ma.pi - eval(fit[i][6])), (eval(fit[i][7]) + ma.pi) else: theta, phi = eval(fit[i][6]), eval(fit[i][7]) theta, phi = coor.angle_bounds3(theta * deg, phi * deg, phi_max=180.0) params.streams = [[ float(fit[i][3]), float(fit[i][4]), float(fit[i][5]), 94.682, 116.0, float(fit[i][8]) ]] #normal to 82 #params.streams = [ [float(fit[i][3]), float(fit[i][4]), float(fit[i][5]), # theta, phi, float(fit[i][8])] ] # Set g limits if (stripes[i] == 9) or (stripes[i] == 10): g_max = 23.5 elif (stripes[i] == 11) or (stripes[i] == 12): g_max = 23.0 else: g_max = 22.5 params.stripe = [(mu_min[i], mu_max[i], 10), (-1.25, 1.25, 10), (16.0, g_max, 10)] params.update_refs() params.print_params() name = "sim_stripe_" + str(stripes[i]) + "_NormNoCon.txt" print "STARTING: " + name stream_gen(params, 0, N_stars[i], fileout=name, convolve=0)
def make_table_werrors(stripes, params): file2="../sgrnorth_paper/results_errors_final.txt" errors=fi.read_data(file2) for i, stripe in enumerate(stripes): if stripe==9 or stripe==22 or stripe==82: theta, phi = (ma.pi-eval(params[i][6]) ), (eval(params[i][7]) + ma.pi) #not sure if needed anymore else: theta, phi = float(params[i][6]), float(params[i][7]) theta, phi = coor.angle_bounds3(theta*deg, phi*deg, phi_max=180.0) theta, phi = theta*rad, phi*rad fit = [stripe, float(params[i][3]), float(params[i][4]), float(params[i][5]), theta, phi, float(params[i][8]) ] # put it together out = str(stripe)+" & " for j in range(2,8): out = out + str(round(fit[j-1],2))+r" \pm "+str(round(errors[i,j],2))+r" & " out = out + r" \\" print out, "\n" back = [stripe, ]
import astro_coordinates as co import math as ma deg = 180.0/ma.pi # milkyway thetas and phis mw_t = [-1.50, -1.53, -1.31, -1.70, -1.91, -1.91, -2.33, -1.92, -1.97, -2.40, -2.36, -2.62, 0.60, -2.20] mw_p = [-0.06, -0.05, -0.01, 0.15, -0.22, -0.14, -0.27, -0.22, -0.32, -0.10, -0.19, -0.30, -1.20, -2.10] # BlueGene thetas and phis bg_t = [1.1, 1.2, 1.3, 1.5, 1.8, 1.9, 2.3, 2.0, 2.1, 2.4, 2.3, 2.6, 2.4, 2.7] bg_ts = [0.5, 1.3, 0.5, 0.2, 0.8, 0.7, 0.7, 0.8, 0.7, 1.6, 0.3, 0.9, 1.0, 1.6] bg_p = [3.0, -2.9, 3.1, -3.0, 2.9, 3.0, 2.9, 2.9, 3.0, 3.0, 3.0, 3.0, 1.9, 1.4] bg_ps = [2.0, 0.5, 0.3, 1.0, 0.3, 0.6, 0.5, 0.3, 1.0, 2.0, 0.7, 2.0, 2.5, 1.6] for i in range(len(mw_t)): print bg_t[i], bg_ts[i], bg_p[i], bg_ps[i], mw_t[i], mw_p[i] x, y = co.angle_bounds3(mw_t[i]*deg, mw_p[i]*deg, phi_max=180.0) theta, phi = x/deg, y/deg dt, dp = abs(theta-bg_t[i])/bg_ts[i], abs(phi-bg_p[i])/bg_ps[i] print theta, dt, phi, dp, "\n"
def sgr_xyz_plots(stripes, params): """ Plots stream positions & directions in galactic XYZ""" positions = sc.zeros((len(stripes),3)) vectors = sc.zeros((len(stripes),3)) for i, stripe in enumerate(stripes): positions[i,0], positions[i,1], positions[i,2] = coor.GC2xyz( eval(params[i][4]), 0.0, eval(params[i][5]), stripe) if stripe==9 or stripe==22 or stripe==82: theta, phi = (ma.pi-eval(params[i][6]) ), (eval(params[i][7]) + ma.pi) else: theta, phi = eval(params[i][6]), eval(params[i][7]) theta, phi = coor.angle_bounds3(theta*deg, phi*deg, phi_max=180.0) theta, phi = theta*rad, phi*rad print stripe, theta, phi vectors[i,0] = ma.sin(theta)*ma.cos(phi) vectors[i,1] = ma.sin(theta)*ma.sin(phi) vectors[i,2] = ma.cos(theta) off = 1.0 """ Plot xy """ plt.figure(1) #ax = plt.subplot(111) plt.scatter(GC[0], GC[1], s=40, edgecolor="k", marker="o", facecolor="black") plt.text(GC[0]+off, GC[1]+off, "GC", fontsize=10) plt.scatter(sun[0], sun[1], s=20, edgecolor="k", marker=(8,2,0), facecolor="white") plt.text(sun[0]+off, sun[1]+off, "Sun", fontsize=10) plt.scatter(Sgr[0], Sgr[1], s=20, edgecolor="k", marker="o", facecolor="black") plt.text(Sgr[0]+off, Sgr[1]+off, "Sgr Core", fontsize=10) t = sc.arange(0.0, 2.0*ma.pi, 0.01) plt.plot(30.0*sc.cos(t), 30.0*sc.sin(t), "k:") offset_x = [0.0, 0.0, 0.0, -1.0, -2.0, -1.0, -1.0, 0.0, 0.0, 0.0, -1.0, -2.0, -3.2, -3.0, 0.5, 0.0, 0.0, -1.0] offset_y = [0.0, 0.0, -1.0, -1.9, 0.2, 0.5, 0.5, -1.0, -2.0, -3.0, -3.0, -2.9, -2.5, 0.5, 0.5, -2.0, -2.0, -2.25] for i in range(len(stripes)): #plt.annotate(str(stripes[i]), xy=(positions[i,0], positions[i,1]), # xytext=( (positions[i,0]+(vectors[i,0]*100.0)), (positions[i,1]+(vectors[i,1]*100.0)) ), # arrowprops=dict(facecolor='black', arrowstyle="->") ) if stripes[i] < 75: color='white' else: color='black' plt.arrow(positions[i,0], positions[i,1], vectors[i,0]*10.0, vectors[i,1]*10.0, width=0.20, head_width=1.5, facecolor=color) if stripes[i] < 20 or stripes[i] > 19: plt.text(positions[i,0]+offset_x[i], positions[i,1]+offset_y[i], r"$"+str(stripes[i])+r"$", fontsize=10) plt.xlabel(r"$X_{GC}$ (kpc)") plt.ylabel(r"$Y_{GC}$ (kpc)") plt.axis('equal') plt.ylim(-30, 30) plt.xlim(-30, 30) locs, labels = plt.xticks() for i in range(len(labels)): labels[i] = r"$"+str(locs[i])+r"$" plt.xticks(locs, labels, fontsize=12) locs, labels = plt.yticks() for i in range(len(labels)): labels[i] = r"$"+str(locs[i])+r"$" plt.yticks(locs, labels, fontsize=12) """ Plot xz """ plt.figure(2) #ax = plt.subplot(111) plt.scatter(GC[0], GC[2], s=40, edgecolor="k", marker="o", facecolor="black") plt.text(GC[0]+off, GC[2]+off, r"GC", fontsize=10) plt.scatter(sun[0], sun[2], s=20, edgecolor="k", marker=(8,2,0), facecolor="white") plt.text(sun[0]+off, sun[2]+off, "Sun", fontsize=10) plt.scatter(Sgr[0], Sgr[2], s=20, edgecolor="k", marker="o", facecolor="black") plt.text(Sgr[0]+off, Sgr[2]+off, "Sgr Core", fontsize=10) plt.plot([-30.0, 30.0], [0.0, 0.0], "k:") offset_x = [0.2, 0.0, 0.0, -0.2, 0.0, 0.0, 0.0, -0.5, 1.0, 1.0, 0.5, 0.75, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0] offset_z = [0.0, 0.0, 0.0, -2.5, 0.0, 0.0, -2.0, 0.5, -1.0, -1.0, 0.25, -1.0, -0.5, 0.0, -0.5, 0.0, 0.5, 0.5] for i in range(len(stripes)): #plt.annotate(str(stripes[i]), xytext=(positions[i,0], positions[i,2]), # xy=( (positions[i,0]+(vectors[i,0]*10.0)), (positions[i,2]+(vectors[i,2]*10.0)) ), # arrowprops=dict(facecolor='black', arrowstyle="->") ) if stripes[i] < 75: color='white' else: color='black' plt.arrow(positions[i,0], positions[i,2], vectors[i,0]*10.0, vectors[i,2]*10.0, width=0.25, head_width=2.0, facecolor=color) if stripes[i] < 20 or stripes[i] > 19: plt.text(positions[i,0]+offset_x[i], positions[i,2]+offset_z[i], r"$"+str(stripes[i])+r"$", fontsize=10) plt.xlabel(r"$X_{GC}$ (kpc)") plt.ylabel(r"$Z_{GC}$ (kpc)") plt.axis('equal') plt.xlim(-45, 45) plt.ylim(-40, 50) locs, labels = plt.xticks() for i in range(len(labels)): labels[i] = r"$"+str(locs[i])+r"$" plt.xticks(locs, labels, fontsize=12) locs, labels = sc.arange(-40.0, 50.0, 20.0), [] for i in range(len(locs)): labels.append(r"$"+str(locs[i])+r"$") plt.yticks(locs, labels, fontsize=12) # done plt.show()
def sgr_xyz_plots(stripes, params): """ Plots stream positions & directions in galactic XYZ""" positions = sc.zeros((len(stripes), 3)) vectors = sc.zeros((len(stripes), 3)) for i, stripe in enumerate(stripes): positions[i, 0], positions[i, 1], positions[i, 2] = coor.GC2xyz( eval(params[i][4]), 0.0, eval(params[i][5]), stripe) if stripe == 9 or stripe == 22 or stripe == 82: theta, phi = (ma.pi - eval(params[i][6])), (eval(params[i][7]) + ma.pi) else: theta, phi = eval(params[i][6]), eval(params[i][7]) theta, phi = coor.angle_bounds3(theta * deg, phi * deg, phi_max=180.0) theta, phi = theta * rad, phi * rad print stripe, theta, phi vectors[i, 0] = ma.sin(theta) * ma.cos(phi) vectors[i, 1] = ma.sin(theta) * ma.sin(phi) vectors[i, 2] = ma.cos(theta) off = 1.0 """ Plot xy """ plt.figure(1) #ax = plt.subplot(111) plt.scatter(GC[0], GC[1], s=40, edgecolor="k", marker="o", facecolor="black") plt.text(GC[0] + off, GC[1] + off, "GC", fontsize=10) plt.scatter(sun[0], sun[1], s=20, edgecolor="k", marker=(8, 2, 0), facecolor="white") plt.text(sun[0] + off, sun[1] + off, "Sun", fontsize=10) plt.scatter(Sgr[0], Sgr[1], s=20, edgecolor="k", marker="o", facecolor="black") plt.text(Sgr[0] + off, Sgr[1] + off, "Sgr Core", fontsize=10) t = sc.arange(0.0, 2.0 * ma.pi, 0.01) plt.plot(30.0 * sc.cos(t), 30.0 * sc.sin(t), "k:") offset_x = [ 0.0, 0.0, 0.0, -1.0, -2.0, -1.0, -1.0, 0.0, 0.0, 0.0, -1.0, -2.0, -3.2, -3.0, 0.5, 0.0, 0.0, -1.0 ] offset_y = [ 0.0, 0.0, -1.0, -1.9, 0.2, 0.5, 0.5, -1.0, -2.0, -3.0, -3.0, -2.9, -2.5, 0.5, 0.5, -2.0, -2.0, -2.25 ] for i in range(len(stripes)): #plt.annotate(str(stripes[i]), xy=(positions[i,0], positions[i,1]), # xytext=( (positions[i,0]+(vectors[i,0]*100.0)), (positions[i,1]+(vectors[i,1]*100.0)) ), # arrowprops=dict(facecolor='black', arrowstyle="->") ) if stripes[i] < 75: color = 'white' else: color = 'black' plt.arrow(positions[i, 0], positions[i, 1], vectors[i, 0] * 10.0, vectors[i, 1] * 10.0, width=0.20, head_width=1.5, facecolor=color) if stripes[i] < 20 or stripes[i] > 19: plt.text(positions[i, 0] + offset_x[i], positions[i, 1] + offset_y[i], r"$" + str(stripes[i]) + r"$", fontsize=10) plt.xlabel(r"$X_{GC}$ (kpc)") plt.ylabel(r"$Y_{GC}$ (kpc)") plt.axis('equal') plt.ylim(-30, 30) plt.xlim(-30, 30) locs, labels = plt.xticks() for i in range(len(labels)): labels[i] = r"$" + str(locs[i]) + r"$" plt.xticks(locs, labels, fontsize=12) locs, labels = plt.yticks() for i in range(len(labels)): labels[i] = r"$" + str(locs[i]) + r"$" plt.yticks(locs, labels, fontsize=12) """ Plot xz """ plt.figure(2) #ax = plt.subplot(111) plt.scatter(GC[0], GC[2], s=40, edgecolor="k", marker="o", facecolor="black") plt.text(GC[0] + off, GC[2] + off, r"GC", fontsize=10) plt.scatter(sun[0], sun[2], s=20, edgecolor="k", marker=(8, 2, 0), facecolor="white") plt.text(sun[0] + off, sun[2] + off, "Sun", fontsize=10) plt.scatter(Sgr[0], Sgr[2], s=20, edgecolor="k", marker="o", facecolor="black") plt.text(Sgr[0] + off, Sgr[2] + off, "Sgr Core", fontsize=10) plt.plot([-30.0, 30.0], [0.0, 0.0], "k:") offset_x = [ 0.2, 0.0, 0.0, -0.2, 0.0, 0.0, 0.0, -0.5, 1.0, 1.0, 0.5, 0.75, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0 ] offset_z = [ 0.0, 0.0, 0.0, -2.5, 0.0, 0.0, -2.0, 0.5, -1.0, -1.0, 0.25, -1.0, -0.5, 0.0, -0.5, 0.0, 0.5, 0.5 ] for i in range(len(stripes)): #plt.annotate(str(stripes[i]), xytext=(positions[i,0], positions[i,2]), # xy=( (positions[i,0]+(vectors[i,0]*10.0)), (positions[i,2]+(vectors[i,2]*10.0)) ), # arrowprops=dict(facecolor='black', arrowstyle="->") ) if stripes[i] < 75: color = 'white' else: color = 'black' plt.arrow(positions[i, 0], positions[i, 2], vectors[i, 0] * 10.0, vectors[i, 2] * 10.0, width=0.25, head_width=2.0, facecolor=color) if stripes[i] < 20 or stripes[i] > 19: plt.text(positions[i, 0] + offset_x[i], positions[i, 2] + offset_z[i], r"$" + str(stripes[i]) + r"$", fontsize=10) plt.xlabel(r"$X_{GC}$ (kpc)") plt.ylabel(r"$Z_{GC}$ (kpc)") plt.axis('equal') plt.xlim(-45, 45) plt.ylim(-40, 50) locs, labels = plt.xticks() for i in range(len(labels)): labels[i] = r"$" + str(locs[i]) + r"$" plt.xticks(locs, labels, fontsize=12) locs, labels = sc.arange(-40.0, 50.0, 20.0), [] for i in range(len(locs)): labels.append(r"$" + str(locs[i]) + r"$") plt.yticks(locs, labels, fontsize=12) # done plt.show()