Exemplo n.º 1
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')
Exemplo n.º 2
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')
Exemplo n.º 3
0
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
Exemplo n.º 4
0
def plot_stripe_3D(data):
    l, b, r = data[:, 0], data[:, 1], coor.getr(data[:, 2])
    x, y, z = coor.lbr2xyz(l, b, r)
    fig = plt.figure()
    ax = Axes3D(fig)
    ax.scatter([-8.5], [0.0], [0.0], c='red')
    ax.scatter(x, y, z, c='yellow')
    ax.set_xlabel('X')
    ax.set_ylabel('Y')
    ax.set_zlabel('Z')
    plt.show()
Exemplo n.º 5
0
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"
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
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
Exemplo n.º 8
0
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"
Exemplo n.º 9
0
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)
Exemplo n.º 10
0
plt.ylabel(r'density')
plt.show()
"""


# Plotting Code 
fig = plt.figure()
ax = Axes3D(fig)

#ax.plot([-5.0,5.0],[0.0, 0.0],[0.0, 0.0], c='yellow')
#data_b = fi.read_data("Backgen82.txt")
#xb, yb, zb = co.lbr2xyz(data_b[:,0], data_b[:,1], data_b[:,2])
#ax.scatter(xb,yb,zb, facecolor='k', edgecolor='k')

data_p = fi.read_data("full_test_82.txt")
xp, yp, zp = co.lbr2xyz(data_p[:,0], data_p[:,1], data_p[:,2])
ax.scatter(xp,yp,zp, c='r')

#data_s = fi.read_data("stream_test.txt")
#xs, ys, zs = co.lbr2xyz(data_s[:,0], data_s[:,1], data_s[:,2])
#u,v,w = twg.generate_stream(1000, -2.2, 1.9, 2.0)
#xs,ys,zs = [],[],[]
#for i in range(len(u)):
#    x_h,y_h,z_h = co.stream2xyz(u[i],v[i],w[i],360.0, 21.0, 0.0, 0.0, 82)
#    xs.append(x_h), ys.append(y_h), zs.append(z_h)
#ax.scatter(xs,ys,zs, facecolor='b', edgecolor='b')
#mu, nu, r1 = sc.array([360.0, 360.0]),sc.array([-1.25, -1.25]),sc.array([10.0, 30.0])
#x,y,z = co.GC2xyz(mu, nu, r1, 82)
#ax.plot(x,y,z, c='r')
#mu2, nu2, r2 = sc.array([360.0, 360.0]),sc.array([1.25, 1.25]),sc.array([10.0, 30.0])
#x2,y2,z2 = co.GC2xyz(mu2, nu2, r2, 82)
Exemplo n.º 11
0
import scipy as sc
import files as fi
import matplotlib
#matplotlib.use('PS')
import matplotlib.pyplot as plt
import astro_coordinates as coor
import sgr_law as sl
import make_latex_table as tex
import sgr_density_analysis as sda

rad = ma.pi / 180.0
deg = 180.0 / ma.pi
sun = [-8.5, 0.0, 0.0]
GC = [0.0, 0.0, 0.0]
Sgr_lbr = [5.6, -14.2, 24.0]
Sgr = coor.lbr2xyz(Sgr_lbr[0], Sgr_lbr[1], Sgr_lbr[2])

'''python scripts for producing components of the sgrNorth paper.
Matthew Newby, April 16, 2012'''

def load_params(filename):
    stripes, params = [], []
    readfile = open(filename, "r")
    for line in readfile:
        if line.strip() == "":  continue
        if line.strip()[0] =="#":  continue
        if line.strip()[0:3] == "---":
            stripes.append(int(line.strip().strip(" -Stripe")))
            #print "Loaded stripe {0}".format(stripes[-1])
            continue
        params.append(line.strip().split(","))
Exemplo n.º 12
0
# 7.57640162772, 7.67810980299, 11.5363484879, 25.6937588232, 8.75918164562,
# 37.6255221984, 54.5484852169, 13.1237001504, 12.2803690866, 11.9300143607,
# 12.2150368604, 13.3084651939, 14.9866923184, 15.7846605126, 27.9365850481, 
# 11.2583497941, 10.1111224829, 9.12819009006
to_x = sc.zeros((len(data[:,0]), 3) )  # RAISE THIS TO 4? WHEN ERRORS ARE USED
for i in range(len(data[:,0])):
    u, v, w, mu, r, theta, phi, sigma = 0.0, 0.0, 0.0, data[i,4], data[i,5], \
        data[i,6], data[i,7], data[i,8]
    to_x[i,0], to_x[i,1], to_x[i,2] = co.stream2xyz(u, v, w, mu, r, theta, phi, wedges[i])
    #to_x[i,3] = errors[i]

"""

to_x = sc.zeros((len(data[:,0]), 3) )
for i in range(len(data[:,0])):
    x,y,z = co.lbr2xyz(data[i,0], data[i,1], co.getr(data[i,2], 0.6))  #<--- 0.6 for Koposov 'i's
    to_x[i,0], to_x[i,1], to_x[i,2] = x,y,z

print to_x


params = pf.plane_OLS(to_x[:,0], to_x[:,1], to_x[:,2])
print "#- Distance array:", pf.plane_dist(to_x[:,0], to_x[:,1], to_x[:,2], params)

fitter.x = to_x
fitter.y = sc.zeros(len(data[:,0]) )
fitter.function=func.plane_fit  #func.R_squared_plane
fitter.update_params([3.0*ma.pi/2.0, ma.pi/2.0, 1.0]) #(params)
fitter.range = [(0, 0.0, 2.0*ma.pi, ma.pi/10.0), (1, 0.0, ma.pi, ma.pi/20.0), (2, -20.0, 20.0, 1.0)]
print fitter.params, fitter.RR
Exemplo n.º 13
0
def plot_wedge_density(data,
                       wedge=82,
                       q=0.458,
                       r0=19.5,
                       mu_min=310.0,
                       mu_max=419.0,
                       streams=None,
                       perturb=None,
                       name="out",
                       mag=0,
                       plot=1,
                       size=1.0):
    """Plots the average density of a wedge versus radius
    stream coords. should be a list of streams, with each sub-list being a
    standard 6-parameter set of stream parameters; perturb is weight of
    perturbation, if any;  mag is whether data is in g magnitudes or not.
    CURRENTLY ONLY WORKS (WELL) FOR STRIPE 82!!!"""
    #Get Average Density with r
    x, y, z = coor.lbr2xyz(data[:, 0], data[:, 1], data[:, 2])
    if mag == 1: r = coor.getr(data[:, 2])
    else: r = data[:, 2]
    max, min = np.ma.max(r), np.ma.min(r)
    bins = int((max - min + 1.0) / size)
    rho_raw = sc.zeros(bins, int)
    for i in range(len(r)):
        index = int((r[i] - min) / size)
        rho_raw[index] = rho_raw[index] + 1
    # get volume at each distance
    #mu_min, mu_max = 310.0, 419.0  #Defined in def inputs
    nu_min, nu_max = (-1.25 * ma.pi / 180.0), (1.25 * ma.pi / 180.0)
    mu_bit = mu_max - mu_min
    nu_bit = sc.sin(nu_max) - sc.sin(nu_min)
    V = sc.zeros(bins, float)
    for i in range(bins):
        r_bit = (min + (i + 1) * size)**3 - (min + i * size)**3
        V[i] = r_bit * (1. / 3.) * mu_bit * nu_bit
    # make the histogram of rho(r)
    rho_hist = sc.zeros((bins, 3), float)
    for i in range(bins):
        rho_hist[i, 0] = min + (i * size)
        rho_hist[i, 1] = rho_raw[i] / V[i]
        rho_hist[i, 2] = (ma.sqrt(rho_raw[i] + 1.0) + 1.0) / V[i]
    """Plot Herquist, stream, perturbation functions over histogram"""
    #get gal-centered herquist distribution for r points in wedge
    mu_avg = ((mu_max - mu_min) / 2.0) + mu_min
    nu_avg = 0.0
    sol_r = sc.arange(min, max, size)
    x, y, z = coor.GC2xyz(mu_avg, nu_avg, sol_r, wedge)
    Hern_rho = twg.hernquist_profile(x, y, z, q, r0)
    H_scale = sc.sum(rho_hist[:, 1]) / sc.sum(
        Hern_rho)  #multiply a factor of 2 to account for different # of bins
    for i in range(len(Hern_rho)):
        Hern_rho[i] = Hern_rho[i] * H_scale
    # DO STREAM!!!
    ################
    #get gal-centered perturbation distribution for r points in wedge
    if perturb != None:
        perturb_rho = twg.perturb_density(x, y, z, (0.0, 0.79, -19.9))
        p_scale = 1.0
        for i in range(len(perturb_rho)):
            perturb_rho[i] = perturb_rho[i] * p_scale
    #Plot it all
    if plot == 1:
        fig = plt.figure()
        plt.bar(rho_hist[:, 0], (rho_hist[:, 1] / Hern_rho) - 1.0, size)
        #plt.plot(sol_r, Hern_rho, c='r')
        if perturb != None:
            plt.plot(sol_r, perturb_rho, c='r')
        plt.xlabel(r'Sun-centered $r$ (kpc)')
        plt.ylabel(r'$\rho$ (stars/kpc)')
        #plt.savefig((name+".ps"), papertype='letter')
        plt.show()
        plt.close('all')
    return rho_hist
Exemplo n.º 14
0
def sgr_xz_plot(folder="./sep_lbr/",
                bin_size=1.0,
                outfile=None,
                infile=None,
                primary=1,
                color=1,
                scale=1):
    x_min, x_max, x_size = -50.0, 50.0, bin_size
    z_min, z_max, z_size = 0.0, 100.0, bin_size
    x_bins, z_bins = int((x_max - x_min) / x_size) + 1, int(
        (z_max - z_min) / z_size) + 1
    if infile == None:
        H = sc.zeros((z_bins, x_bins), float)
        files = glob.glob(folder + "/*.txt")
        for file in files:
            data = fi.read_data(file)
            wedge = int(file[-6:-4])
            for i in range(len(data[:, 0])):
                if primary == 1:
                    if test_primary(data[i, 0],
                                    data[i, 1],
                                    wedge,
                                    low=9,
                                    high=23) == 0:
                        continue
                x, y, z = coor.lbr2xyz(data[i, 0], data[i, 1], data[i, 2])
                if x < x_min or x > x_max: continue
                if z < z_min or z > z_max: continue  #FLAG
                xi, zi = int((x - x_min) / x_size), int(
                    (z - z_min) / z_size)  #FLAG
                H[zi, xi] = H[zi, xi] + 1.0
        if outfile != None: fi.write_data(H, outfile)
    else: H = fi.read_data(infile)
    if scale == 1: H = sc.sqrt(H)
    #Make the plot
    plt.figure(1)
    sp = plt.subplot(111)
    if color == 1: cmap = spectral_wb
    else: cmap = binary
    plt.imshow(H, interpolation='nearest', cmap=cmap)  #vmin=0.0, vmax=15.0)
    bar = plt.colorbar(orientation='vertical')
    if scale == 1:
        bar_ticks = sc.arange(0.0, 17.0, 4.0)
        bar_labels = []
        for i in range(len(bar_ticks)):
            bar_labels.append(str(int(bar_ticks[i]**2)))
        bar.set_ticks(bar_ticks)
        bar.set_ticklabels(bar_labels, update_ticks=True)
    Earth = [-8.5, 0.0, 0.0]
    plt.scatter((Earth[0] - x_min) / x_size, (Earth[2] - z_min) / z_size,
                c='yellow',
                s=5)
    # Clean up
    y_lim = plt.ylim()
    plt.ylim(y_lim[1], y_lim[0])
    #plt.xlim(-25.0, 270.0)
    #plt.ylim(-25.0, 270.0)
    #plt.setp(sp.get_xticklabels(), visible=False)
    #plt.setp(sp.get_yticklabels(), visible=False)
    #plt.setp(sp.get_xticklines(),  visible=False)
    #plt.setp(sp.get_yticklines(),  visible=False)
    # Show plot
    plt.show()
    plt.close('all')
Exemplo n.º 15
0
from matplotlib.colors import ListedColormap
#from mpl_toolkits.mplot3d import Axes3D
import time
import astro_coordinates as coor
import os.path
import sys
import glob
#import test_wedge_generator as twg
'''Input: l,b,g_0
l limits: 20.4835409501, 205.337883034
b limits: -85.9538084201, -30.0000008077
g limits: 16, 23
Matthew Newby, August 30, 2011'''

Sgr_lbr = [5.6, -14.2, 24.0]
Sgr = coor.lbr2xyz(Sgr_lbr[0], Sgr_lbr[1], Sgr_lbr[2])


class stripe:
    """ Do not include extension in file name!"""
    def __init__(self, filename=""):
        self.filename = filename
        self.data = []
        self.size = 0
        self.file_size = 0
        while os.path.isfile(filename) == True:
            filename = filename + "_new"
        filename = filename + ".txt"
        file = open(filename, "w")
        file.write("#  l, b, r")
        file.close()
Exemplo n.º 16
0
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)
Exemplo n.º 17
0
    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:])
Exemplo n.º 18
0
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)
Exemplo n.º 19
0
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:])
Exemplo n.º 20
0
plt.xlabel(r'Sun-centered r (kpc)')
plt.ylabel(r'density')
plt.show()
"""

# Plotting Code
fig = plt.figure()
ax = Axes3D(fig)

#ax.plot([-5.0,5.0],[0.0, 0.0],[0.0, 0.0], c='yellow')
#data_b = fi.read_data("Backgen82.txt")
#xb, yb, zb = co.lbr2xyz(data_b[:,0], data_b[:,1], data_b[:,2])
#ax.scatter(xb,yb,zb, facecolor='k', edgecolor='k')

data_p = fi.read_data("full_test_82.txt")
xp, yp, zp = co.lbr2xyz(data_p[:, 0], data_p[:, 1], data_p[:, 2])
ax.scatter(xp, yp, zp, c='r')

#data_s = fi.read_data("stream_test.txt")
#xs, ys, zs = co.lbr2xyz(data_s[:,0], data_s[:,1], data_s[:,2])
#u,v,w = twg.generate_stream(1000, -2.2, 1.9, 2.0)
#xs,ys,zs = [],[],[]
#for i in range(len(u)):
#    x_h,y_h,z_h = co.stream2xyz(u[i],v[i],w[i],360.0, 21.0, 0.0, 0.0, 82)
#    xs.append(x_h), ys.append(y_h), zs.append(z_h)
#ax.scatter(xs,ys,zs, facecolor='b', edgecolor='b')
#mu, nu, r1 = sc.array([360.0, 360.0]),sc.array([-1.25, -1.25]),sc.array([10.0, 30.0])
#x,y,z = co.GC2xyz(mu, nu, r1, 82)
#ax.plot(x,y,z, c='r')
#mu2, nu2, r2 = sc.array([360.0, 360.0]),sc.array([1.25, 1.25]),sc.array([10.0, 30.0])
#x2,y2,z2 = co.GC2xyz(mu2, nu2, r2, 82)