Exemplo n.º 1
0
def plot_double_mur(data,
                    wedge=82,
                    mu_min=310.0,
                    mu_max=419.0,
                    name="out",
                    mag=0,
                    rsize=2.0,
                    musize=2.0):
    """ !!! TAKE INTO ACOUNT mu WRAPAROUND AT 360.0 !!!"""
    ra, dec = coor.lbToEq(data[:, 0], data[:, 1])
    mu, nu = coor.EqToGC(ra, dec, wedge)
    r_min, r_max = int(sc.ma.min(data[:, 2])), int(sc.ma.max(data[:, 2])) + 1
    r_hist = np.histogram(data[:, 2], int((r_max - r_min) / rsize),
                          (r_min, r_max))
    mu_hist = np.histogram(mu, int((mu_max - mu_min) / musize),
                           (mu_min, mu_max))
    # plot r hist
    fig = plt.figure(1)
    plt.subplot(211)
    plt.bar(r_hist[1][:-1], r_hist[0], rsize)
    plt.xlabel("r, kpc")
    # plot mu hist
    plt.subplot(212)
    plt.bar(mu_hist[1][:-1], mu_hist[0], musize)
    plt.xlabel("mu")
    plt.show()
    plt.close('all')
Exemplo n.º 2
0
def shift_sgr(filein="streamgen_bif50Good.txt", fileout="stream_50shift.txt"):
    prime = [ -5.25124491e-03, 1.57254414e+00, -1.00216868e+02]
    second = [ -7.76551199e-03, 2.31737724e+00, -1.41690141e+02]
    #file1="/home/newbym2/Dropbox/Research/sgrLetter/"+filein
    file1="/home/newbym2/Dropbox/Research/sgrLetter/"+filein
    data = np.loadtxt(file1)
    for i in range(len(data[:,0])):
        data[i,0], data[i,1] = ac.lbToEq(data[i,0], data[i,1])
        deldel = data[i,1] - (data[i,0]*data[i,0]*prime[0] + data[i,0]*prime[1] + prime[2])
        data[i,1] = deldel + (data[i,0]*data[i,0]*second[0] + data[i,0]*second[1] + second[2])
        data[i,0], data[i,1] = ac.EqTolb(data[i,0], data[i,1])
    np.savetxt(fileout, data, delimiter=" ")
Exemplo n.º 3
0
def get_stripe(wedge, filein):
    stripe_data = []
    skymap = sc.zeros((180, 360), float)
    for line in fileinput.input(filein):
        # Get Data
        if line.strip()[0] == '': continue
        if line.strip()[0] == '#': continue
        holder = line.split(',')
        l, b, g = eval(holder[0].strip()), eval(holder[1].strip()), eval(
            holder[2].strip())
        ra, dec = coor.lbToEq(l, b)
        mu, nu = coor.EqToGC(ra, dec, wedge)
        if abs(nu) < 1.25:
            stripe_data.append([l, b, g])
            # now build the histogram
            l_i = int(ra)
            b_i = int(dec) + 90
            skymap[-b_i][l_i] = skymap[-b_i][l_i] + 1.0
        if fileinput.filelineno() % 100000 == 0:
            print "Line {0} complete".format(fileinput.filelineno())
    return sc.array(stripe_data), skymap
Exemplo n.º 4
0
def plot_stripe_mug(data, wedge, name="out", mag=0):
    """ SPREAD OUT MORE!!! """
    #l, b = data[:,0], data[:,1]
    if mag == 1: g = data[:, 2]
    else: g = coor.getg(data[:, 2])
    ra, dec = coor.lbToEq(data[:, 0], data[:, 1])
    mu, nu = coor.EqToGC(ra, dec, wedge)
    x, y = g * sc.cos(mu * rad), g * sc.sin(mu * rad)
    x_bins = int((np.ma.max(x) - np.ma.min(x)) / 0.5) + 1
    y_bins = int((np.ma.max(y) - np.ma.min(y)) / 0.5) + 1
    H, x, y = np.histogram2d(x, y, [x_bins, y_bins])
    extent = [np.ma.min(y), np.ma.max(y), np.ma.max(x), np.ma.min(x)]
    plt.figure(1)
    sp = plt.subplot(111)
    #plt.polar([0.0, np.ma.min(mu)*rad, np.ma.max(mu)*rad, 0.0], [0.0, 60.0, 60.0, 0.0])
    plt.imshow(H, extent=extent, interpolation='nearest')
    plt.colorbar(orientation='horizontal')
    #plt.plot(x1,y1,'r-')
    plt.setp(sp.get_xticklabels(), visible=False)
    plt.setp(sp.get_yticklabels(), visible=False)
    plt.savefig((name + ".ps"), papertype='letter')
    plt.close('all')
Exemplo n.º 5
0
def field_of_streams(xa = (0.0,360.0), ya=(-90.0, 90.0), normed=1, file=None, hname=""):
    #xa = (110.0,230.0), ya=(-5.0, 60.0), normed=1):
    path = "/usr/home/f/081/tug08879/Desktop/"
    #file = "MSTO_North.csv"
    hname = "_sgrtweaked"
    if file != None:
        data = np.loadtxt(path+file, delimiter=",", skiprows=1)
        print "Loaded data"
        # change coordinates
        for i in range(data.shape[0]):
            ra, dec = ac.lbToEq(data[i,0], data[i,1])
            data[i,0], data[i,1] = ra, dec
        print "Changed Coordinates"
        #Wr, Br, Gr, Rr, Kr = 20.0+0.25, 20.66+0.25, 21.33+0.25, 22.0+0.25, 23.0+0.25  #Belokurov 2006 + g-r=0.25
        Wr, Br, Gr, Rr, Kr = 19.0, 21.0, 21.75, 22.5, 23.0
        # bins for each color
        W, B, G, R, K = [], [], [], [], []
        for i in range(len(data[:,0])):
            if   data[i,2] < Wr:  W.append(data[i,:])
            elif data[i,2] < Br:  B.append(data[i,:])
            elif data[i,2] < Gr:  G.append(data[i,:])
            elif data[i,2] < Rr:  R.append(data[i,:])
            else:  pass
        if R == []:  R = [[0.0,0.0,0.0]]  #failsafe
        if G == []:  G = [[0.0,0.0,0.0]]  #failsafe
        if B == []:  B = [[0.0,0.0,0.0]]  #failsafe
        B = np.array(B)
        Bhist = pp.HistMaker(B[:,0], B[:,1], xsize=0.25, ysize=0.25, xarea=xa, yarea=ya)
        Bhist.varea = (0.0,200.0)
        Bhist.savehist("Bhist.csv")
        G = np.array(G)
        Ghist = pp.HistMaker(G[:,0], G[:,1], xsize=0.25, ysize=0.25, xarea=xa, yarea=ya)
        Ghist.varea = (0.0,200.0)
        Ghist.savehist("Ghist.csv")
        R = np.array(R)
        Rhist = pp.HistMaker(R[:,0], R[:,1], xsize=0.25, ysize=0.25, xarea=xa, yarea=ya)
        Rhist.varea = (0.0,200.0)
        Rhist.savehist("Rhist.csv")
    else:
        Bhist = pp.HistFromFile("Bhist"+hname+".csv")
        Ghist = pp.HistFromFile("Ghist"+hname+".csv")
        Rhist = pp.HistFromFile("Rhist"+hname+".csv")
    #print np.ma.max(Bhist.H), np.ma.max(Ghist.H), np.ma.max(Rhist.H)
    # Now correct for bin size changes due to declination
    for j in range(Bhist.H.shape[0]):
        decl = (j - 360)*0.25
        mod = 1.0 / np.cos(decl*ma.pi/180.0)
        Bhist.H[j,:] = Bhist.H[j,:]*mod
        Ghist.H[j,:] = Ghist.H[j,:]*mod
        Rhist.H[j,:] = Rhist.H[j,:]*mod
    if normed == 1:
        Bhist.H = Bhist.H / 25.0 #np.ma.max(Bhist.H)  #Normalize individually
        Ghist.H = Ghist.H / 12.0 #np.ma.max(Ghist.H)
        Rhist.H = Rhist.H / 12.0 #np.ma.max(Rhist.H)
    else:
        #norm = max(np.ma.max(Bhist.H), np.ma.max(Ghist.H), np.ma.max(Rhist.H))
        norm = 100.0
        Bhist.H = norm_hist(Bhist.H, norm)
        Ghist.H = norm_hist(Ghist.H, norm)
        Rhist.H = norm_hist(Rhist.H, norm)
    RGB = np.dstack( (Rhist.H, Ghist.H, Bhist.H) )
    fig = plt.figure(dpi=300, figsize=(5.0,4.0) )
    sp = plt.subplot(111)
    plt.imshow(RGB, origin='lower')
    plt.setp(sp.get_xticklabels(), visible=False)
    plt.setp(sp.get_yticklabels(), visible=False)
    plt.xlim(1075.0, 425.0)
    plt.ylim(340.0, 640.0)
    plt.savefig("FoS_smallbins.png", dpi=300)
Exemplo n.º 6
0
def single_stripe_mur(data,
                      wedge,
                      mag=0,
                      scale=0,
                      color=1,
                      position=111,
                      mu_lim=None,
                      r_lim=None,
                      vm=None,
                      nu_flatten=0,
                      bar=1,
                      ring=1,
                      raw_coords=0):
    """ change 'scale' to a string tag:  None, sqrt, flatten, log? """
    #l, b = data[:,0], data[:,1]
    x_size, y_size = 0.5, 0.5
    if mag == 1: r = coor.getr(data[:, 2])
    else: r = data[:, 2]
    print len(r)
    if r_lim == None: r_lim = (np.ma.min(r), np.ma.max(r))
    if raw_coords == 0:
        ra, dec = coor.lbToEq(data[:, 0], data[:, 1])
        mu, nu = coor.EqToGC(ra, dec, wedge)
    else:
        mu, nu = data[:, 0], data[:, 1]
    if mu_lim == None: mu_lim = [np.ma.min(mu), np.ma.max(mu)]
    #Checks if limits straddle mu=0.0
    if (mu_lim[0] < 1.0) and (mu_lim[1] > 359.0):
        mu_lim[0], mu_lim[1] = 0.0, 360.0
        for i in mu:
            if (i > 180.0) and (i < mu_lim[1]): mu_lim[1] = i
            if (i < 180.0) and (i > mu_lim[0]): mu_lim[0] = i
        mu_lim[0] = mu_lim[0] - 360.0
    x, y = r * sc.cos(mu * rad), r * sc.sin(mu * rad)
    x_bins = int((np.ma.max(x) - np.ma.min(x)) / x_size) + 1
    y_bins = int((np.ma.max(y) - np.ma.min(y)) / y_size) + 1
    H, x, y = np.histogram2d(
        y, x, [y_bins, x_bins])  #, range=[[-155.0, 110.0],[-190.0, 0.0]])
    extent = [np.ma.min(y), np.ma.max(y), np.ma.max(x), np.ma.min(x)]
    if nu_flatten == 1:
        print "!!! DOUBLE-CHECK NU FLATTENING! {0}".format(H.shape)
        for i in range(H.shape[0]):
            for j in range(H.shape[1]):
                dist = ma.sqrt(((i - (H.shape[0] / 2.0)) * y_size)**2 +
                               (j * x_size)**2)
                H[i, j] = H[i, j] / (dist * 2.5)
        H = sc.sqrt(H)  #sc.log10(H)
        vm = 1.5
    elif scale == 1:
        H = sc.sqrt(H)
        if vm == None: vm = 16.0
    else:
        if vm == None: vm = 300.0
    """ Begin Figure """
    #fig = plt.figure(frameon=False)
    sp = plt.subplot(position)
    if color == 1: cmap = spectral_wb
    else: cmap = 'gist_yarg'
    plt.imshow(H,
               extent=extent,
               interpolation='nearest',
               vmin=0.0,
               vmax=vm,
               cmap=cmap)
    if bar == 1:
        bar = plt.colorbar(orientation='vertical')
        if scale == 1:
            bar_ticks = sc.arange(0.0, vm + 1.0, 2.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)
    """ Draw axes - mu """
    mu_axis = gen_mu_axis(mu_lim, r_lim[1], ring)
    plt.plot(mu_axis[0], mu_axis[1], 'k-')  # Draws main axis
    for i in range(len(mu_axis[2])):
        x0 = [
            1.0 * r_lim[1] * sc.cos(mu_axis[2][i] * rad),
            1.1 * r_lim[1] * sc.cos(mu_axis[2][i] * rad)
        ]
        y0 = [
            1.0 * r_lim[1] * sc.sin(mu_axis[2][i] * rad),
            1.1 * r_lim[1] * sc.sin(mu_axis[2][i] * rad)
        ]
        plt.plot(x0, y0, 'k-')  # Draws mu ticks
        if mu_axis[3][i] <= 180.0: rot = -90.0 + mu_axis[3][i]
        else: rot = -360.0 + mu_axis[3][i] - 90.0
        if wedge < 40:
            offset = 1.12  #This accounts for different whitespace on each side of 180
        else:
            offset = 1.14
        x00, y00 = offset * r_lim[1] * sc.cos(
            mu_axis[2][i] * rad), offset * r_lim[1] * sc.sin(
                mu_axis[2][i] * rad)
        #Format tick labels - this part adds whitespace to center labels on ticks
        pre, mulbl = "$", str(mu_axis[3][i])
        if len(mulbl) < 3:
            for k in range(3 - len(mulbl)):
                pre = " " + pre
        if i == (len(mu_axis[2])) - 1:
            plt.text(x00,
                     y00,
                     "$\mu=" + str(mu_axis[3][i]) + "^{\circ}$",
                     rotation=rot,
                     fontsize=12,
                     horizontalalignment='center')  #float(mu_axis[3][i]) )
        else:
            plt.text(x00,
                     y00,
                     pre + str(mu_axis[3][i]) + "^{\circ}$",
                     rotation=rot,
                     fontsize=12,
                     horizontalalignment='center')  #float(mu_axis[3][i]) )
    """ Draw axes - r """
    r_axis = gen_r_axis(mu_lim, r_lim)
    plt.plot(r_axis[0], r_axis[1], 'k-')
    mu1 = sc.arange(mu_lim[0] - 6.0, mu_lim[1] + 7.0, 1.0)
    for tick in r_axis[2]:
        x1, y1 = tick * sc.cos(mu1 * rad), tick * sc.sin(mu1 * rad)
        if mu1[-1] < 90.0 or mu1[-1] > 360.0:
            x2, y2 = tick * sc.cos((mu1[-1]) * rad), tick * sc.sin(
                (mu1[-1]) * rad)
            hl = 'right'
        else:
            x2, y2 = tick * sc.cos((mu1[1]) * rad), tick * sc.sin(
                (mu1[1]) * rad)
            hl = 'left'
        plt.plot(x1[:7], y1[:7], "k-")
        plt.plot(x1[-7:], y1[-7:], "k-")
        if tick == r_axis[2][-1]:
            plt.text(x2,
                     y2,
                     "$r=" + str(int(tick)) + "$",
                     rotation=0.0,
                     fontsize=12,
                     horizontalalignment=hl,
                     verticalalignment='bottom')
        else:
            plt.text(x2,
                     y2,
                     "$" + str(int(tick)) + "$",
                     rotation=0.0,
                     fontsize=12,
                     horizontalalignment=hl,
                     verticalalignment='bottom')
    # Draw axes - g (TO BE DONE)
    """ Clean up output """
    y_lim = plt.ylim()
    plt.ylim(y_lim[1], y_lim[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)
    #ax = fig.add_axes([0, 0, 1, 1])  #These two lines supress the axes... supposedly
    #ax.axis('off')
    return sp
Exemplo n.º 7
0
def field_of_streams(
        xa=(0.0, 360.0), ya=(-90.0, 90.0), normed=1, file=None, hname=""):
    #xa = (110.0,230.0), ya=(-5.0, 60.0), normed=1):
    path = "/usr/home/f/081/tug08879/Desktop/"
    #file = "MSTO_North.csv"
    hname = "_sgrtweaked"
    if file != None:
        data = np.loadtxt(path + file, delimiter=",", skiprows=1)
        print "Loaded data"
        # change coordinates
        for i in range(data.shape[0]):
            ra, dec = ac.lbToEq(data[i, 0], data[i, 1])
            data[i, 0], data[i, 1] = ra, dec
        print "Changed Coordinates"
        #Wr, Br, Gr, Rr, Kr = 20.0+0.25, 20.66+0.25, 21.33+0.25, 22.0+0.25, 23.0+0.25  #Belokurov 2006 + g-r=0.25
        Wr, Br, Gr, Rr, Kr = 19.0, 21.0, 21.75, 22.5, 23.0
        # bins for each color
        W, B, G, R, K = [], [], [], [], []
        for i in range(len(data[:, 0])):
            if data[i, 2] < Wr: W.append(data[i, :])
            elif data[i, 2] < Br: B.append(data[i, :])
            elif data[i, 2] < Gr: G.append(data[i, :])
            elif data[i, 2] < Rr: R.append(data[i, :])
            else: pass
        if R == []: R = [[0.0, 0.0, 0.0]]  #failsafe
        if G == []: G = [[0.0, 0.0, 0.0]]  #failsafe
        if B == []: B = [[0.0, 0.0, 0.0]]  #failsafe
        B = np.array(B)
        Bhist = pp.HistMaker(B[:, 0],
                             B[:, 1],
                             xsize=0.25,
                             ysize=0.25,
                             xarea=xa,
                             yarea=ya)
        Bhist.varea = (0.0, 200.0)
        Bhist.savehist("Bhist.csv")
        G = np.array(G)
        Ghist = pp.HistMaker(G[:, 0],
                             G[:, 1],
                             xsize=0.25,
                             ysize=0.25,
                             xarea=xa,
                             yarea=ya)
        Ghist.varea = (0.0, 200.0)
        Ghist.savehist("Ghist.csv")
        R = np.array(R)
        Rhist = pp.HistMaker(R[:, 0],
                             R[:, 1],
                             xsize=0.25,
                             ysize=0.25,
                             xarea=xa,
                             yarea=ya)
        Rhist.varea = (0.0, 200.0)
        Rhist.savehist("Rhist.csv")
    else:
        Bhist = pp.HistFromFile("Bhist" + hname + ".csv")
        Ghist = pp.HistFromFile("Ghist" + hname + ".csv")
        Rhist = pp.HistFromFile("Rhist" + hname + ".csv")
    #print np.ma.max(Bhist.H), np.ma.max(Ghist.H), np.ma.max(Rhist.H)
    # Now correct for bin size changes due to declination
    for j in range(Bhist.H.shape[0]):
        decl = (j - 360) * 0.25
        mod = 1.0 / np.cos(decl * ma.pi / 180.0)
        Bhist.H[j, :] = Bhist.H[j, :] * mod
        Ghist.H[j, :] = Ghist.H[j, :] * mod
        Rhist.H[j, :] = Rhist.H[j, :] * mod
    if normed == 1:
        Bhist.H = Bhist.H / 25.0  #np.ma.max(Bhist.H)  #Normalize individually
        Ghist.H = Ghist.H / 12.0  #np.ma.max(Ghist.H)
        Rhist.H = Rhist.H / 12.0  #np.ma.max(Rhist.H)
    else:
        #norm = max(np.ma.max(Bhist.H), np.ma.max(Ghist.H), np.ma.max(Rhist.H))
        norm = 100.0
        Bhist.H = norm_hist(Bhist.H, norm)
        Ghist.H = norm_hist(Ghist.H, norm)
        Rhist.H = norm_hist(Rhist.H, norm)
    RGB = np.dstack((Rhist.H, Ghist.H, Bhist.H))
    fig = plt.figure(dpi=300, figsize=(5.0, 4.0))
    sp = plt.subplot(111)
    plt.imshow(RGB, origin='lower')
    plt.setp(sp.get_xticklabels(), visible=False)
    plt.setp(sp.get_yticklabels(), visible=False)
    plt.xlim(1075.0, 425.0)
    plt.ylim(340.0, 640.0)
    plt.savefig("FoS_smallbins.png", dpi=300)