Esempio n. 1
0
def test_coords():
    # test Li Jing's coord transforms
    #ra,dec,l,b,j0,k0,w10,w20,lambda,beta
    arcsec = 1.0 / 3600.0
    data = np.loadtxt("/home/newbym/Desktop/Mgiant_wise_sgr.csv",
                      delimiter=",",
                      skiprows=1)
    ra, dec = data[:, 0], data[:, 1]
    l, b = data[:, 2], data[:, 3]
    lam, bet = data[:, 8], data[:, 9]
    badl, badb, badlam, badbet, badlam2, badbet2 = [], [], [], [], [], []
    for i in range(data.shape[0]):
        new_l, new_b = ac.EqTolb(ra[i], dec[i])
        if np.abs(new_l - l[i]) > arcsec: badl.append(new_l - l[i])
        if np.abs(new_b - b[i]) > arcsec: badb.append(new_b - b[i])
        new_lam, new_bet = ac.lb2sgr(l[i], b[i], 30.)[3:5]
        if np.abs(new_lam - lam[i]) > arcsec: badlam.append(lam[i])
        if np.abs(new_bet - bet[i]) > arcsec: badbet.append(bet[i])
        new_lam2, new_bet2 = ac.lb2sgr(new_l, new_b, 30.)[3:5]
        if np.abs(new_lam2 - lam[i]) > arcsec: badlam2.append(lam[i])
        if np.abs(new_bet2 - bet[i]) > arcsec: badbet2.append(bet[i])
    print data.shape[0]
    print np.mean(badl), np.mean(badb)
    print np.mean(badlam), np.mean(badbet), np.std(badbet)
    print np.mean(badlam2), np.mean(badbet2), np.std(badbet2)
    print "Done"
Esempio n. 2
0
def sgr_rv_skyplot():
    data = np.loadtxt("/home/newbym2/Dropbox/Research/sgrLetter/sgr_spec_all.csv", delimiter=",")
    #dered_g,dered_r,l,b,ELODIERVFINAL,ELODIERVFINALERR,plate,p_ra,p_dec
    g0, r0 = data[:,0], data[:,1]
    l, b = data[:,2], data[:,3]
    rv, rv_err = data[:,4], data[:,5]
    plates = data[:,6]
    p_ra, p_dec = data[:,7], data[:,8]
    d = ac.getr(g0)
    # Transform to vgsr from Yanny+ 2009
    vgsr = ac.rv_to_vgsr(rv,l,b)
    X,Y,Z, lsgr, bsgr, r_sgr = ac.lb2sgr(l, b, d)
    pl,pb = ac.EqTolb(p_ra, p_dec)
    pd = 20.0*sc.ones(len(pl))
    pX,pY,pZ, plsgr, pbsgr, pr_sgr = ac.lb2sgr(pl, pb, pd)
    mean, stdev, nsig = -118.233333, 30.222222, 1.0
    #plates = plate_center_utils()
    locs = []
    for i in range(len(data[:,0])):
        if g0[i] < 20.0:  continue
        if g0[i] > 23.0:  continue
        #if lsgr[i] > 230.0:  continue
        locs.append([lsgr[i], bsgr[i], vgsr[i], plsgr[i], pbsgr[i] ])
    locs = np.array(locs)
    sgr = []
    for i in range(len(locs[:,0])):
        if locs[i,2] < (mean - stdev*nsig):  continue
        if locs[i,2] > (mean + stdev*nsig):  continue
        sgr.append([locs[i,0], locs[i,1]])
    sgr = np.array(sgr)
    plt.figure()
    plt.scatter(locs[:,0], locs[:,1], c="k", s=1)
    plt.scatter(sgr[:,0], sgr[:,1], c='r', s=10)
    plt.scatter(locs[:,3], locs[:,4], c='b', s=10)
    plt.plot([190.0, 250.0, 250.0, 190.0],[10.0, 10.0, -10.0, -10.0], "b-")
    plt.plot([190.0, 320.0], [0.0, 0.0], "b--")
    plt.text(195.0, 33.0, "$\mu=$-118.2, $\sigma=$30.2\n{0} stars in {1}$\sigma$".format(len(sgr), nsig), fontsize=16)
    plt.xlim(190.0, 320.0)
    #plt.ylim(-75.0, 40.0)
    plt.ylim(40.0, -75.0)
    plt.xlabel(r"$\Lambda$", fontsize=16)
    plt.ylabel(r"$B$", fontsize=16)
    plt.show()
    """
    hist, edges = np.histogram(sgr[:,1], bins=23, range=(-75.0, 40.0))
    plt.bar(edges[:-1], hist, width=5.0, color="grey")
    plt.xlabel("B", fontsize=16)
    plt.text(-50.0, 25.0, "Stars within "+str(nsig)+r"$\sigma$ of mean $v_{\rm gsr}$; $\Lambda<230$", fontsize=12)
    plt.show()"""
    plt.close()
Esempio n. 3
0
def sgr_rv_cut():
    data = np.loadtxt("/home/newbym2/Dropbox/Research/sgrLetter/sgr_spec_all.csv", delimiter=",")
    #dered_g,dered_r,l,b,ELODIERVFINAL,ELODIERVFINALERR,plate,p_ra,p_dec
    g0, r0 = data[:,0], data[:,1]
    l, b = data[:,2], data[:,3]
    rv, rv_err = data[:,4], data[:,5]
    plates = data[:,6]
    p_ra, p_dec = data[:,7], data[:,8]
    d = ac.getr(g0)
    # Transform to vgsr from Yanny+ 2009
    vgsr = ac.rv_to_vgsr(rv,l,b)
    X,Y,Z, lsgr, bsgr, r_sgr = ac.lb2sgr(l, b, d)
    mean, stdev, nsig = -118.233333, 30.222222, 2.0
    keep = []
    for i in range(len(data[:,0])):
        if abs(bsgr[i]) < 10.0:  
            if g0[i] < 20.0:  continue
            if g0[i] > 23.0:  continue
            if vgsr[i] < (mean - stdev*nsig):  continue
            if vgsr[i] > (mean + stdev*nsig):  continue
            keep.append([(g0[i]-r0[i]), g0[i]], p_ra[i], p_dec[i])
    keep = np.array(keep)
    plt.figure()
    plt.scatter(keep[:,0], keep[:,1], s=1)
    lims = plt.ylim()
    plt.ylim(lims[1], lims[0])
    plt.ylabel(r"$g_0$")
    plt.xlabel(r"$(g-r)_0$")
    plt.show()
    plt.close()
Esempio n. 4
0
def bhb_tools(infile="/home/newbym2/Desktop/sdssN-stars/sgr_bhbs_all.csv",
              out=[],
              gmin=15.0,
              gmax=22.5,
              suffix="All"):
    """ bhb stuff """
    data = np.loadtxt(infile, delimiter=",", skiprows=1)
    ff = 1
    if "c-c" in out:
        ug0 = data[:, 2] - data[:, 3]
        gr0 = data[:, 3] - data[:, 4]
        plt.figure(ff)
        ff += 1
        plt.scatter(gr0, ug0, c="k", s=2)
        plt.xlabel(r"$(g-r)_0$")
        plt.ylabel(r"$(u-g)_0$")
        plt.xlim(-0.5, 1.5)
        plt.ylim(3.0, 0.0)
    if "c-mag" in out:
        #rr = ac.getr(data[:,3], 0.7)  ## BHB M  #Not working right?
        gr0 = data[:, 3] - data[:, 4]
        cmag = pp.HistMaker(gr0, data[:, 3], 0.01, 0.1)
        cmag.yflip = 1
        cmag.scale = 'sqrt'
        cmag.varea = (0.0, 2000.0)
        cmag.plot()
    plt.show()
    if "sgrplot" in out:
        # use only primaries
        sgr = []
        for i in range(data.shape[0]):
            #if ac.SDSS_primary(data[i,0],data[i,1],wedge,fmt="lb",low=9,high=27)==0:  continue
            if data[i, 3] > gmax: continue
            if data[i, 3] < gmin: continue
            sgr.append([data[i, 0], data[i, 1]])
        sgr = np.array(sgr)
        lam, bet = (ac.lb2sgr(sgr[:, 0], sgr[:, 1], 30.0))[3:5]
        hist = pp.HistMaker(lam,
                            bet,
                            1.0,
                            1.0,
                            xarea=(20.0, 320.0),
                            yarea=(-70.0, 40.0))
        hist.xflip = 1
        hist.yflip = 1
        hist.varea = (0.0, 6.0)
        hist.savehist("sgr_bhbs.csv", fmt='%.1f')
        #hist.ticks= [[20.0, 40.0, 60.0, 80.0, 100.0, 120.0, 140.0],[-40.0, -20.0, 0.0, 20.0]]
        # mask the data
        if "mask" in out:
            mask = np.loadtxt("Rhist_sgr.csv", delimiter=",")
            for i in range(len(mask[:, 0])):
                for j in range(len(mask[0, :])):
                    if mask[i, j] == 0.0: hist.H[i, j] = 0.0
        hist.savehist("bhb" + suffix + "_hist.csv", fmt='%.1f')
        pp.PlotHist(hist,
                    imfile="BHB_" + suffix + ".png",
                    cbarO='horizontal',
                    cax=[0.1, 0.75, 0.8, 0.02])
Esempio n. 5
0
def FTO_skyplot(path="/home/mnewby/Desktop/", gmin=16.0, gmax=22.5,
                multistep=None):
    """Make a skyplot with updated MSTO stars from SDSS """
    #files = glob.glob(path+"stars*")
    #files.append(path+"South/stars-79-new.txt")
    #files.append(path+"South/stars-82-new.txt")
    #files.append(path+"South/stars-86-new.txt")
    #files = glob.glob(path+"FTO_All*")
    #files.append(path+"FTO_south_dirty.csv")
    #files = glob.glob(path+"*dirty*")
    #files = [path+"MSTO_North_plus20.csv", path+"MSTO_South_minus20.csv"]
    files = [path+"blue_all.csv"]
    out = []
    for f in files:
        #data = np.loadtxt(f, skiprows=1)
        data = np.loadtxt(f, delimiter=",", skiprows=1)
        print "Loaded:", f
        for i in range(data.shape[0]):
            #if data[i,2] < ac.getr(16.0):  continue
            #if data[i,2] > ac.getr(22.5):  continue
            gmag = data[i,3]  # for FTO data
            #gmag = data[i,2]  #for MSTO data
            if gmag < gmin:  continue
            if gmag > gmax:  continue
            #Distance is ambiguous for blue stars
            #lam, bet = (ac.lb2sgr(data[i,0], data[i,1], ac.getr(data[i,3]) ) )[3:5]
            lam, bet = (ac.lb2sgr(data[i,0], data[i,1], 10000.0) )[3:5]
            out.append([lam, bet, gmag])
        print "Transformed coordinates:", f
    out = np.array(out)
    if multistep != None:
        #runs = np.arange(10.0, 50.0, 5.0)  #for distance
        runs = np.arange(gmin, gmax, multistep)
        runs = [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
        for run in runs:
            print "Starting run", run
            gslice = []
            for i in range(out.shape[0]):
                if out[i,2] < run:  continue
                if out[i,2] >= (run+multistep):  continue
                gslice.append(out[i,:])
            gslice = np.array(gslice)
            hist = pp.HistMaker(gslice[:,0], gslice[:,1], 0.5, 0.5, yarea=(-70.0, 40.0), xarea=(20.0, 320.0) )
            hist.savehist(outfile="FTO_"+str(run)+"_hist.csv", fmt='%.1f')
            hist.yflip = 1
            hist.xflip = 1
            hist.ticks = (None, [-60, -40.0, -20.0, 0.0, 20.0, 40.0])
            hist.varea = (0.0, 12.0)
            pp.PlotHist(hist, imfile="FTO_"+str(run)+".png", cbarO='horizontal')
    else:
        hist = pp.HistMaker(out[:,0], out[:,1], 1.0, 1.0, yarea=(-70.0, 40.0), xarea=(20.0, 320.0) )
        hist.savehist(outfile="BLUE_all_hist.csv", fmt='%.1f')
        hist.yflip=1
        hist.xflip=1
        hist.labels=(r"$\Lambda$","B")
        hist.ticks = (None, [-40.0, -20.0, 0.0, 20.0, 40.0, 60.0, 80.0])
        hist.varea=(0.0, 30.0)
        pp.PlotHist(hist, imfile="BLUE_all.png", cbarO='horizontal')
Esempio n. 6
0
def lambet_profiles(path="/home/newbym2/Desktop/sdssN-stars/", glb="*bhbs_all*",
                    lj=0, bj=1, gj=2, lbins=2.5, bbins=0.5, suffix="_bhbs", coords="sgr"):
    """ remixed from plot_profiles in utilities1 """
    files = glob.glob(path+glb)
    print files
    data=[]
    g_cut_low, g_cut_high = 16.0, 22.5
    pb = pr.Progressbar(steps=len(files), prefix="Loading Stars:", suffix=None,
        symbol="#", active="=", brackets="[]", percent=True, size=40)
    for f in files:
        count=0
        stripedata = np.loadtxt(f, delimiter=",", skiprows=1)
        for i in range(stripedata.shape[0]):
            if stripedata[i,gj] < g_cut_low:  continue
            if stripedata[i,gj] > g_cut_high:  continue
            #if ac.SDSS_primary(temp[0],temp[1],wedge,fmt="lb",low=9,high=27)==0:  continue
            data.append([stripedata[i,lj], stripedata[i,bj], stripedata[i,gj] ] )
        pb.updatebar(float(files.index(f)+1)/float(len(files)) )
    data = np.array(data)
    if coords == "sgr":
        count, nStars, pb2 = 0, float(len(data[:,0])), pr.Progressbar(steps=100,
            prefix="Changing Coordinates:", suffix=None, symbol="#", active="=",
            brackets="[]", percent=True, size=40)
        for i in range(data.shape[0]):
            count += 1
            data[i,0], data[i,1] = ac.lb2sgr(data[i,0], data[i,1], 50.0 )[3:5]
            #data[i,2] = data[i,2]
            if count % 1000 == 0:  pb2.updatebar(float(count)/nStars)
    elif coords == "lbr":  pass
        #data[i,0], data[i,1] = ac.lb2GC(data[i,0], data[i,1], 15)
        #data[i,0], data[i,1] = ac.lbToEq(data[i,0], data[i,1])
    else:  print "!!! Coordinate system not recognized !!!";  sys.exit(2)
    pb2.endbar()
    # loop over Lambda slices and plot Beta histograms
    pb3 = pr.Progressbar(steps=len(files), prefix="Making Slices:", suffix=None,
        symbol="#", active="=", brackets="[]", percent=True, size=40)
    #Ls = (40.0, 130.0, lbins)
    #Ls = (200.0, 300.0, lbins)
    Ls = (201.25, 301.25, lbins)  #for wedges offset by half a wedge
    Lsteps = int((Ls[1]-Ls[0])/Ls[2])
    for i in range(Lsteps):
        Lname = str(Ls[0]+(Ls[2]*i) )[:6]+suffix
        new = []
        for j in range(len(data[:,0])):
            if data[j,0] < Ls[0]+(Ls[2]*i):  continue
            if data[j,0] > Ls[0]+(Ls[2]*(i+1)):  continue
            new.append([data[j,0], data[j,1], data[j,2]])
        if len(new) < 1:  continue
        new = np.array(new)
        #np.savetxt("stars-lambda-"+("00"+str(i))[-2:]+".txt", new, fmt='%.6f')
        pb3.updatebar(float(i)/float(Lsteps))
        Lhist, Ledges = np.histogram(new[:,1], int(100/bbins), (-60.0, 40.0))
        #output to file
        outstuff = sc.array(zip(Ledges+(bbins/2.0), Lhist))
        np.savetxt(Lname+".out", outstuff, fmt='%.2f')
    pb3.endbar()
    print "Ended Successfully"
Esempio n. 7
0
def mag_plots(gmin=16.0, gmax=22.5):
    path = "/home/mnewby/Desktop/"
    #path="/home/newbym/Desktop/FTO-stars/"
    #files = [path+"MSTO_North_plus20.csv", path+"MSTO_South_minus20.csv"]
    #files = [path+"MSTO_North.csv", path+"MSTO_South.csv"]
    files = [path + "blue_all.csv"]
    out = []
    for f in files:
        data = np.loadtxt(f, delimiter=",", skiprows=1)
        print "Loaded:", f
        pb = pr.Progressbar(steps=data.shape[0],
                            prefix="Loading Stars:",
                            suffix=None,
                            symbol="#",
                            active="=",
                            brackets="[]",
                            percent=True,
                            size=40)
        for i in range(data.shape[0]):
            #if data[i,2] < ac.getr(16.0):  continue
            #if data[i,2] > ac.getr(22.5):  continue
            gmag = data[i, 3]  # for BHB data
            #gmag = data[i,2]  #for MSTO data
            if gmag < gmin: continue
            if gmag > gmax: continue
            lam, bet = (ac.lb2sgr(data[i, 0], data[i, 1], 30.0))[3:5]
            if lam > 170.0:
                #if bet > 10.0:  continue
                #if bet < 2.5:  continue
                if bet > -2.5: continue
                if bet < -10.0: continue
            else:
                #if bet <  -2.5:  continue
                #if bet > 5.0:  continue
                if bet > -5.0: continue
                if bet < -12.5: continue
            out.append([lam, bet, gmag])
            if i % 10000 == 0: pb.updatebar(float(i) / float(data.shape[0]))
        pb.endbar()
        print "Transformed coordinates:", f
    out = np.array(out)
    hist = pp.HistMaker(out[:, 0],
                        out[:, 2],
                        0.5,
                        0.1,
                        yarea=(16.0, 22.5),
                        xarea=(0.0, 360.0))
    hist.savehist(outfile="blue_faint_faint_hist.csv", fmt='%.1f')
    hist.yflip = 0
    hist.xflip = 1
    hist.labels = (r"$\Lambda$", r"$g_0$")
    hist.ticks = (sc.arange(20.0, 321.0, 20.0), sc.arange(16.0, 22.6, 0.5))
    #hist.ticklabels = (None, ["16.0", "16.5", "17.0", "17.5", "18.0", "18.5", "19.0", "19.5", "20.0",
    #                            "20.5", "21.0", "21.5", "22.0", "22.5"])
    hist.varea = (0.0, 30.0)
    pp.PlotHist(hist, imfile="blue_faint_faint.png", cbarO='horizontal')
    pp.PlotHist(hist, imfile="blue_faint_faint.ps", cbarO='horizontal')
Esempio n. 8
0
def sgr_plot(folder="./sep_lbr"):
    files = glob.glob(folder + "/*.txt")
    plt.figure(1)
    for file in files:
        data = fi.read_data(file)
        Xs, Ys, Zs, lam, beta, r = coor.lb2sgr(data[:, 0], data[:, 1], data[:,
                                                                            2])
        plt.scatter(lam, beta, s=1, c="black")
    plt.show()
    plt.close('all')
Esempio n. 9
0
def make_single_stream_plot(filename):
    data = np.loadtxt(filename)
    for i in range(len(data[:,0])):
        #data[i,0], data[i,1] = ac.lbToEq(data[i,0], data[i,1])
        #if ac.SDSS_primary(temp[0],temp[1],wedge,fmt="lb",low=9,high=27)==0:  continue
        data[i,0], data[i,1] = (ac.lb2sgr(data[i,0], data[i,1], 10.0))[3:5]
        lam, bet = new_shift_sgr(data[i,0], data[i,1])
        data2.append([lam, bet, data[i,2]])
    # Not done yet!!!
    return -1
Esempio n. 10
0
def process_spec():
    pp = np.loadtxt("/home/newbym2/Dropbox/Research/sgrLetter/plate_stars.csv", delimiter=",")
    pl,pb = ac.EqTolb(pp[:,1], pp[:,2])
    pd = 20.0
    pX,pY,pZ, plsgr, pbsgr, pr_sgr = ac.lb2sgr(pl, pb, pd)
    norm = pp[:,3] + pp[:,4]
    out = []
    for i in range(len(pp[:,0])):
        out.append([plsgr[i], pbsgr[i], pp[i,4]/norm[i], norm[i]])
    np.savetxt("/home/newbym2/Dropbox/Research/sgrLetter/plate_data.csv", np.array(out), delimiter=",")
Esempio n. 11
0
def make_sim_stream_plot(filein="stream_50shift.txt", RGB=0, imfile=None):
    """ Makes the plot for the simulated streams
        /home/newbym2/Dropbox/Research/sgrnorth_paper/sgr_separated_stars_MRT.txt"""
    folder = "/home/newbym2/Dropbox/Research/sgrLetter/"
    filename=folder + filein
    #file2="/home/newbym2/Dropbox/Research/sgrnorth_paper/sgr_separated_stars_MRT.txt"
    #file2="streamgen_sgr_sim.txt"
    #file2="streamgen_sgrfidprim.txt"
    file2 = folder+"streamgen_sfp2.txt"
    data = np.loadtxt(filename)
    data2 = []
    datasgr = np.loadtxt(file2)
    for i in range(len(data[:,0])):
        #data[i,0], data[i,1] = ac.lbToEq(data[i,0], data[i,1])
        #if ac.SDSS_primary(temp[0],temp[1],wedge,fmt="lb",low=9,high=27)==0:  continue
        data[i,0], data[i,1], data[i,2] = (ac.lb2sgr(data[i,0], data[i,1], data[i,2]))[3:]
        lam, bet = new_shift_sgr(data[i,0], data[i,1])  #move 2nd stream to new position
        data2.append([lam, bet, ac.getg(data[i,2], M=4.2)])
    data2 = sc.array(data2)
    for i in range(len(datasgr[:,0])):
        datasgr[i,0], datasgr[i,1] = (ac.lb2sgr(datasgr[i,0], datasgr[i,1], 10.0))[3:5]
        datasgr[i,2] = ac.getg(data[i,2], M=4.2)
    """
    data2 = np.loadtxt(file2)
    for i in range(len(data2[:,0])):
        #data2[i,0], data2[i,1] = ac.lbToEq(data2[i,0], data2[i,1])
        data2[i,0], data2[i,1] = (ac.lb2sgr(data2[i,0], data2[i,1], 10.0))[3:5]
    """
    if RGB==1:  
        data3 = np.concatenate((data2,datasgr), axis=0)
        #data3 = np.concatenate((data2,data), axis=0)
        RGB_plot(data3, imfile=imfile, mask_data="Bhist_sgr.csv", muddle=0)
    else:
        sky = pp.HistMaker(np.concatenate([data[:,0],data2[:,0]]), np.concatenate([data[:,1],data2[:,1]]),
            xsize=0.5, ysize=0.5, xarea=(120.0, 250.0), yarea=(-10.0, 50.0))
        sky.varea = (0.0,200.0)
        sky.H = sky.H + np.random.normal(60.0, 15.0, sky.H.shape)
        #for i in range(sky.H.shape[0]):
        #    if i < 14:   sky.H[i,:] = sky.H[i,:]*0.0; continue
        #    sky.H[i,:] = sky.H[i,:] + 45.0 - (0.5/1.0)*i
        pp.PlotHist(sky, "streamgen_bifExtra_radec.png")
        sky.savehist("streamgen_bifExtra.csv")
    print "Ended Successfully"
Esempio n. 12
0
def sky_map(infile="/home/newbym2/Desktop/sdssN-stars/sdssN_sky.csv"):
    """Map a variable in Lambda, Beta  """
    data = np.loadtxt(infile, delimiter=",", skiprows=1)
    l, b = data[:,0], data[:,1]
    g_ext, r_ext = data[:,4], data[:,5]
    g_sky, r_sky = data[:,6], data[:,7]
    print np.ma.min(g_ext), np.ma.max(g_ext)
    lam, bet = ac.lb2sgr(l, b, 30.0)[3:5]
    plt.figure()
    sc = plt.scatter(lam, bet, c=r_ext, cmap=pp.spectral_wb, edgecolors='none', 
                    s=3, alpha=0.3, vmin=0, vmax=0.4)
    plt.colorbar(sc)
    plt.xlim(230.0, 255.0); plt.ylim(15.0, -10.0)
    plt.show()
Esempio n. 13
0
def make_total_plot(path="/home/newbym2/Desktop/starfiles", RGB=0, imfile=None, 
                    rcut=None, vrange=None, outfile=None):
    """ Makes a 2D histogram """
    files = glob.glob(path+"/stars*")
    print files
    data=[]
    pb = pr.Progressbar(steps=len(files), prefix="Loading Stars:", suffix=None,
        symbol="#", active="=", brackets="[]", percent=True, size=40)
    for f in files:
        wedge = int(f.split("-")[1].split(".")[0])
        count=0
        stripedata = open(f, "r")
        for line in stripedata:
            count = count + 1
            if count==1:  continue
            if line.strip()=="":  continue
            temp = line.split()
            for i in range(len(temp)):  temp[i] = float(temp[i])
            if rcut != None:
                if temp[2] < rcut[0]:  continue
                if temp[2] > rcut[1]:  continue
            if ac.SDSS_primary(temp[0],temp[1],wedge,fmt="lb",low=9,high=27)==0:  continue
            data.append(temp)
        stripedata.close()
        pb.updatebar(float(files.index(f)+1)/float(len(files)) )
    data = np.array(data)
    count, nStars, pb2 = 0, float(len(data[:,0])), pr.Progressbar(steps=100,
        prefix="Changing Coordinates:", suffix=None, symbol="#", active="=",
        brackets="[]", percent=True, size=40)
    for i in range(len(data[:,0])):
        count = count + 1
        #data[i,0], data[i,1] = ac.lb2GC(data[i,0], data[i,1], 15)
        #data[i,0], data[i,1] = ac.lbToEq(data[i,0], data[i,1])
        data[i,0], data[i,1] = (ac.lb2sgr(data[i,0], data[i,1], 10.0))[3:5]
        data[i,2] = ac.getg(data[i,2], 4.2)
        if count % 100 == 0:  pb2.updatebar(float(count)/nStars)
    pb2.endbar()
    if RGB==1:  RGB_plot(data, imfile=imfile)
    else:
        allsky = pp.HistMaker(data[:,0], data[:,1], xsize=0.5, ysize=0.5,
            #xarea=(200.0, 300.0), yarea=(-40.0, 30.0))
            xarea=(230.0, 255.0), yarea=(-10.0, 15.0))
        #allsky.scale = 'sqrt'
        allsky.cmap="bw"
        allsky.yflip = 1
        if vrange != None:  allsky.varea = (vrange[0], vrange[1])
        if outfile==None:  pp.PlotHist(allsky, "sgrall_GC.png")
        else:  pp.PlotHist(allsky, outfile)
        #allsky.savehist("SDSSnorthGC.csv")
    print "Ended Successfully"
Esempio n. 14
0
def test_coords():
    # test Li Jing's coord transforms
    #ra,dec,l,b,j0,k0,w10,w20,lambda,beta
    arcsec = 1.0 / 3600.0
    data = np.loadtxt("/home/newbym/Desktop/Mgiant_wise_sgr.csv", delimiter=",", skiprows=1)
    ra, dec = data[:,0], data[:,1]
    l, b = data[:,2], data[:,3]
    lam, bet = data[:,8], data[:,9]
    badl, badb, badlam, badbet, badlam2, badbet2 = [], [], [], [], [], []
    for i in range(data.shape[0]):
        new_l, new_b = ac.EqTolb(ra[i], dec[i])
        if np.abs(new_l - l[i]) > arcsec:  badl.append(new_l - l[i])
        if np.abs(new_b - b[i]) > arcsec:  badb.append(new_b - b[i])
        new_lam, new_bet = ac.lb2sgr(l[i],b[i], 30.)[3:5]
        if np.abs(new_lam - lam[i]) > arcsec:  badlam.append(lam[i])
        if np.abs(new_bet - bet[i]) > arcsec:  badbet.append(bet[i])
        new_lam2, new_bet2 = ac.lb2sgr(new_l,new_b, 30.)[3:5]
        if np.abs(new_lam2 - lam[i]) > arcsec:  badlam2.append(lam[i])
        if np.abs(new_bet2 - bet[i]) > arcsec:  badbet2.append(bet[i])
    print data.shape[0]
    print np.mean(badl), np.mean(badb)
    print np.mean(badlam), np.mean(badbet), np.std(badbet)
    print np.mean(badlam2), np.mean(badbet2), np.std(badbet2)
    print "Done"
Esempio n. 15
0
def lam_wedges():
    sys.path.insert(0, '../milkyway-tools')
    import sdss_visualizers as sdss
    path = "/home/newbym2/Desktop/lam_starfiles/"
    files = glob.glob(path+"/stars*")
    for f in files:
        # get lambdas from naming scheme
        wedge = float(f[-6:-4])
        name = "lam-"+str(200.0 + (wedge*2.5) )[:6]
        stars = np.loadtxt(f)
        print "Loaded ", f
        for i in range(stars.shape[0]):
            stars[i,0], stars[i,1] = (ac.lb2sgr(stars[i,0], stars[i,1], 30.0))[3:5]
        sdss.plot_stripe_mur(stars, wedge, outname=name, mag=1, scale=1, color=1,
                    mu_lim=None, r_lim=(0.0, 50.0), vm=10.0, nu_flatten=0, bar=1, raw_coords=1)
        print "Finished file {0} of {1}:".format(files.index(f)+1, len(files) )
    print "### - Done"
Esempio n. 16
0
def mag_plots(gmin=16.0, gmax=22.5):
    path = "/home/mnewby/Desktop/"
    #path="/home/newbym/Desktop/FTO-stars/"
    #files = [path+"MSTO_North_plus20.csv", path+"MSTO_South_minus20.csv"]
    #files = [path+"MSTO_North.csv", path+"MSTO_South.csv"]
    files = [path+"blue_all.csv"]
    out = []
    for f in files:
        data = np.loadtxt(f, delimiter=",", skiprows=1)
        print "Loaded:", f
        pb = pr.Progressbar(steps=data.shape[0], prefix="Loading Stars:", suffix=None,
        symbol="#", active="=", brackets="[]", percent=True, size=40)
        for i in range(data.shape[0]):
            #if data[i,2] < ac.getr(16.0):  continue
            #if data[i,2] > ac.getr(22.5):  continue
            gmag = data[i,3]  # for BHB data
            #gmag = data[i,2]  #for MSTO data
            if gmag < gmin:  continue
            if gmag > gmax:  continue
            lam, bet = (ac.lb2sgr(data[i,0], data[i,1], 30.0))[3:5]
            if lam > 170.0:
                #if bet > 10.0:  continue
                #if bet < 2.5:  continue
                if bet > -2.5:  continue
                if bet < -10.0:  continue
            else:
                #if bet <  -2.5:  continue
                #if bet > 5.0:  continue
                if bet >  -5.0:  continue
                if bet < -12.5:  continue
            out.append([lam, bet, gmag])
            if i % 10000 == 0:  pb.updatebar(float(i)/float(data.shape[0]) )
        pb.endbar()
        print "Transformed coordinates:", f
    out = np.array(out)
    hist = pp.HistMaker(out[:,0], out[:,2], 0.5, 0.1, yarea=(16.0, 22.5), xarea=(0.0, 360.0) )
    hist.savehist(outfile="blue_faint_faint_hist.csv", fmt='%.1f')
    hist.yflip=0
    hist.xflip=1
    hist.labels=(r"$\Lambda$",r"$g_0$")
    hist.ticks = (sc.arange(20.0, 321.0, 20.0), sc.arange(16.0, 22.6, 0.5) )
    #hist.ticklabels = (None, ["16.0", "16.5", "17.0", "17.5", "18.0", "18.5", "19.0", "19.5", "20.0",
    #                            "20.5", "21.0", "21.5", "22.0", "22.5"])
    hist.varea=(0.0, 30.0)
    pp.PlotHist(hist, imfile="blue_faint_faint.png", cbarO='horizontal')
    pp.PlotHist(hist, imfile="blue_faint_faint.ps", cbarO='horizontal')
Esempio n. 17
0
def bhb_tools(infile="/home/newbym2/Desktop/sdssN-stars/sgr_bhbs_all.csv",
                out=[], gmin=15.0, gmax=22.5, suffix="All"):
    """ bhb stuff """
    data = np.loadtxt(infile, delimiter=",", skiprows=1)
    ff = 1
    if "c-c" in out:
        ug0 = data[:,2] - data[:,3]
        gr0 = data[:,3] - data[:,4]
        plt.figure(ff);  ff+=1
        plt.scatter(gr0, ug0, c="k", s=2)
        plt.xlabel(r"$(g-r)_0$");  plt.ylabel(r"$(u-g)_0$")
        plt.xlim(-0.5, 1.5);  plt.ylim(3.0, 0.0)
    if "c-mag" in out:
        #rr = ac.getr(data[:,3], 0.7)  ## BHB M  #Not working right?
        gr0 = data[:,3] - data[:,4]
        cmag = pp.HistMaker(gr0,data[:,3], 0.01, 0.1)
        cmag.yflip=1
        cmag.scale='sqrt'
        cmag.varea=(0.0, 2000.0)
        cmag.plot()
    plt.show()
    if "sgrplot" in out:
        # use only primaries
        sgr = []
        for i in range(data.shape[0]):
            #if ac.SDSS_primary(data[i,0],data[i,1],wedge,fmt="lb",low=9,high=27)==0:  continue
            if data[i,3] > gmax:  continue
            if data[i,3] < gmin:  continue
            sgr.append([data[i,0], data[i,1]])
        sgr = np.array(sgr)
        lam, bet = (ac.lb2sgr(sgr[:,0], sgr[:,1], 30.0))[3:5]
        hist = pp.HistMaker(lam, bet, 1.0, 1.0, xarea=(20.0, 320.0), yarea=(-70.0, 40.0))
        hist.xflip=1
        hist.yflip=1
        hist.varea=(0.0, 6.0)
        hist.savehist("sgr_bhbs.csv", fmt='%.1f')
        #hist.ticks= [[20.0, 40.0, 60.0, 80.0, 100.0, 120.0, 140.0],[-40.0, -20.0, 0.0, 20.0]]
        # mask the data
        if "mask" in out:
            mask = np.loadtxt("Rhist_sgr.csv", delimiter=",")
            for i in range(len(mask[:,0])):
                for j in range(len(mask[0,:])):
                    if mask[i,j] == 0.0:  hist.H[i,j] = 0.0
        hist.savehist("bhb"+suffix+"_hist.csv", fmt='%.1f')
        pp.PlotHist(hist, imfile="BHB_"+suffix+".png", cbarO='horizontal', cax=[0.1, 0.75, 0.8, 0.02])
Esempio n. 18
0
def sgr_rv_fits():
    data = np.loadtxt("/home/newbym2/Dropbox/Research/sgrLetter/sgr_spec.csv", delimiter=",")
    #dered_g,dered_r,l,b,ELODIERVFINAL,ELODIERVFINALERR
    g0, r0 = data[:,0], data[:,1]
    l, b = data[:,2], data[:,3]
    rv, rv_err = data[:,4], data[:,5]
    d = ac.getr(g0)
    # Transform to vgsr from Yanny+ 2009
    vgsr = ac.rv_to_vgsr(rv,l,b)
    X,Y,Z, lsgr, bsgr, r_sgr = ac.lb2sgr(l, b, d)
    for w in [0.5, 1.0, 2.5, 5.0, 7.5, 10.0, 15.0, 20.0, 25.0, 30.0, 50.0]:
        keep = []
        for i in range(len(data[:,0])):
            if abs(bsgr[i]) < w:  
                if g0[i] < 20.0:  continue
                if g0[i] > 23.0:  continue
                keep.append(vgsr[i])
        hist, edges = np.histogram(np.array(keep), bins=60, range=(-300.0, 300.0))
        y, x = hist, edges[:-1] 
        e = func.poisson_errors(y)
        fitter = fit.ToFit(x,y,e)
        fitter.function=func.double_gaussian_one_fixed
        fitter.update_params([3.0, -120.0, 30.0, 2.0, 0.0, 120.0])
        fitter.step = [1.0, 10.0, 1.0, 1.0, 0.0, 0.0]
        fitter.param_names = ["amp", "mu", "sigma", "amp", "mu", "sigma"]
        path1 = fit.gradient_descent(fitter, its=10000, line_search=0)
        path2 = fit.MCMC(fitter)
        new_params=fitter.params
        xx = sc.arange(-300.0, 300.0, 1.0)
        yy = func.double_gaussian_one_fixed(xx, new_params)
        y1 = func.gaussian_function(xx, new_params[:3])
        y2 = func.gaussian_function(xx, new_params[3:])
        fig = plt.figure()
        plt.bar(edges[:-1], hist, width=10.0, color="white")
        plt.plot(xx,yy, "k-")
        plt.plot(xx,y1, "k--")
        plt.plot(xx,y2, "k--")
        plt.title("cut width = "+str(w))
        plt.xlabel(r"$v_{\rm gsr}$", fontsize=16)
        plt.ylabel(r"Counts")
        #plt.ylim(0.0, 60.0)
        #plt.show()
        plt.savefig("/home/newbym2/Dropbox/Research/sgrLetter/sgr_spec/r_cut_relative"+str(w)+".png")
        plt.close()    
Esempio n. 19
0
def split_by_plate():
    # dered_g,dered_r,l,b,ELODIERVFINAL,ELODIERVFINALERR,plate,p_ra,p_dec
    data = np.loadtxt("/home/newbym2/Dropbox/Research/sgrLetter/sgr_spec_all.csv", delimiter=",")
    mean, stdev, nsig = -118.233333, 30.222222, 1.0
    plates, pos = [], []
    for i in range(len(data[:,0])):
        if plates.count(data[i,6]) > 0:  continue
        plates.append(data[i,6])
        pos.append([data[i,7], data[i,8]])
    out = []
    for i, plate in enumerate(plates):
        # get stars for plate
        stars = []
        for j in range(len(data[:,0])):
            if data[j,6] == plate:  stars.append(data[j,:])
        if stars == []:  continue
        # apply cuts
        keep = []
        for star in stars:
            if star[0] < 20.0:  continue
            if star[0] > 20.5:  continue  #using stricter cut
            X,Y,Z, lsgr, bsgr, r_sgr = ac.lb2sgr(star[2], star[3], ac.getr(star[0]))
            if lsgr < 190.0:  continue
            if lsgr > 250.0:  continue
            if abs(bsgr) > 10.0:  continue
            vgsr = ac.rv_to_vgsr(star[4],star[2],star[3])
            keep.append([lsgr, bsgr, vgsr])
        if keep == []:  continue
        # vgsr selection
        yes, no = 0, 0
        for k in keep:
            if k[2] < (mean - stdev*nsig):  no += 1;  continue
            if k[2] > (mean + stdev*nsig):  no += 1;  continue
            yes += 1
        print "Plate {0}:  In {1} of Sgr versus out:  {2}, {3}".format(
            plate, nsig, yes, no)
        # compile plate info positions
        out.append([plate, pos[i][0], pos[i][1], yes, no])
    savename = "/home/newbym2/Dropbox/Research/sgrLetter/plate_stars.csv"
    np.savetxt(savename, sc.array(out), delimiter=",")
Esempio n. 20
0
def crotus_cut(path="/home/newbym2/Desktop/starfiles", cdata=None):
    if cdata == None:
        files = glob.glob(path+"/stars*")
        data=[]
        r_cut_low, r_cut_high = ac.getr(16.0), ac.getr(23.5) #30.0, 45.0
        pb = pr.Progressbar(steps=len(files), prefix="Loading Stars:", suffix=None,
            symbol="#", active="=", brackets="[]", percent=True, size=40)
        for f in files:
            wedge = int(f.split("-")[1].split(".")[0])
            sdata = np.loadtxt(f, skiprows=1)
            for i in range(sdata.shape[0]):
                if (sdata[i,2] < r_cut_low) or (sdata[i,2] > r_cut_high):  continue
                if ac.SDSS_primary(sdata[i,0],sdata[i,1],wedge,fmt="lb",low=9,high=27)==0:  continue
                lam, bet = (ac.lb2sgr(sdata[i,0], sdata[i,1], 10.0))[3:5]
                if (lam <230.0) or (lam > 255.0):  continue
                data.append([sdata[i,0], sdata[i,1], sdata[i,2], lam, bet])
            pb.updatebar(float(files.index(f)+1)/float(len(files)) )
        pb.endbar()
        data = np.array(data)
        np.savetxt("crotus_data.txt", data, fmt='%.6f')
    else:  
        data = []
        rdata = np.loadtxt(cdata)
        rlim0 = 28.5  #ac.getr(22.5)
        rlim1 = 45.0
        for i in range(rdata.shape[0]):
            if rdata[i,2] < rlim0:  continue
            if rdata[i,2] > rlim1:  continue
            data.append(rdata[i,:])
        data = np.array(data)
    #Now do analysis
    sky = pp.HistMaker(data[:,3], data[:,4], xsize=0.25, ysize=0.25, 
        xarea=(230.0, 255.0), yarea=(-10.0, 15.0))
    sky.varea = (0.0, 60.0)
    sky.cmap="color"
    #sky.scale = 'sqrt'
    sky.yflip = 1
    pp.PlotHist(sky, "crotus_cut.png")
    #sky.savehist("streamgen_bifExtra.csv")
    print "### - Done"
Esempio n. 21
0
def sky_map(infile="/home/newbym2/Desktop/sdssN-stars/sdssN_sky.csv"):
    """Map a variable in Lambda, Beta  """
    data = np.loadtxt(infile, delimiter=",", skiprows=1)
    l, b = data[:, 0], data[:, 1]
    g_ext, r_ext = data[:, 4], data[:, 5]
    g_sky, r_sky = data[:, 6], data[:, 7]
    print np.ma.min(g_ext), np.ma.max(g_ext)
    lam, bet = ac.lb2sgr(l, b, 30.0)[3:5]
    plt.figure()
    sc = plt.scatter(lam,
                     bet,
                     c=r_ext,
                     cmap=pp.spectral_wb,
                     edgecolors='none',
                     s=3,
                     alpha=0.3,
                     vmin=0,
                     vmax=0.4)
    plt.colorbar(sc)
    plt.xlim(230.0, 255.0)
    plt.ylim(15.0, -10.0)
    plt.show()
Esempio n. 22
0
def sky_map(infile="/home/newbym2/Desktop/sdssN-stars/sgr_sky_data.csv", dumb=1):
    """Map a variable in Lambda, Beta  """
    if dumb == 1:
        data = np.loadtxt(infile, delimiter=",", skiprows=1)
        l, b = data[:,0], data[:,1]
        g_ext, r_ext = data[:,4], data[:,5]
        g_sky, r_sky = data[:,6], data[:,7]
        print np.ma.min(g_ext), np.ma.max(g_ext)
        lam, bet = ac.lb2sgr(l, b, 30.0)[3:5]
        plt.figure()
        sc = plt.scatter(lam, bet, c=g_ext, cmap=pp.spectral_wb, edgecolors='none',
                    s=3, alpha=0.3, vmin=0, vmax=0.4)
        plt.colorbar(sc)
        plt.xlim(320, 20.0); plt.ylim(40.0, -70.0)
    else:
        path="/home/newbym2/Desktop/FTO-stars/"
        files = glob.glob(path+"FTO_All*")
        files.append(path+"FTO_south_dirty.csv")
        x_range, y_range = (20, 320), (-70, 40)
        x_step, y_step = 0.5, 0.5
        x_bins, y_bins = (x_range[1]-x_range[0])/x_step, (y_range[1]-y_range[0])/y_step
        try:
            grid = np.loadtxt("reddening_out.txt")
        except IOError:
            grid = np.zeros((y_bins+1, x_bins+1), float)
            for f in files:
                data = np.loadtxt(f, delimiter=",", skiprows=1)
                pb = pr.Progressbar(steps=data.shape[0], prefix="Loading {0}".format(f.split("/")[-1]),
                    suffix=None,  symbol="#", active="=", brackets="[]", percent=True, size=40)
                for i in range(data.shape[0]):
                    lam, bet = (ac.lb2sgr(data[i,0], data[i,1], 30.0))[3:5]
                    gridx = (lam - x_range[0])/x_step
                    gridy = (bet - y_range[0])/y_step
                    if (gridx < 0) or (gridy < 0):  continue
                    if (gridx > x_bins+1) or (gridy > y_bins +1):  continue
                    if grid[gridy, gridx] < data[i,13]:  grid[gridy, gridx] = data[i,13]
                    if i % 1000 == 0:  pb.updatebar(float(i)/float(data.shape[0]) )
                pb.endbar()
            np.savetxt("reddening_out.txt", grid, fmt="%.2f")
        """ plot stuff """
        grid = grid[:,::-1]
        grid = grid[::-1,:]
        fig = plt.figure(dpi=120)
        ax1 = fig.add_subplot(111)
        im = ax1.imshow(grid, cmap=pp.spectral_wb, norm=None, aspect=None, interpolation='nearest',
               alpha=None, origin='lower', extent=None, vmin=0.0, vmax=2.0)
        cbar = plt.colorbar(mappable=im, aspect=30, orientation="horizontal")
        xpos = np.arange(0.0, 601.0, 20.0)
        xlab = []
        for i in range(len(xpos)):
            if i % 3 == 0:
                xx = (xpos[i]*x_step) + x_range[0]
                xlab.append(str(xx).split(".")[0] )
            else:  xlab.append("")
        plt.xticks(xpos, xlab[::-1])
        ypos = np.arange(0.0, 221.0, 20.0)
        ylab = []
        for i in range(len(ypos)):
            if i % 2 == 0:
                yy = (ypos[i]*y_step) + y_range[0]
                ylab.append(str(yy).split(".")[0] )
            else:  ylab.append("")
        plt.yticks(ypos, ylab[::-1])
    plt.show()
Esempio n. 23
0
def FTO_skyplot(path="/home/mnewby/Desktop/",
                gmin=16.0,
                gmax=22.5,
                multistep=None):
    """Make a skyplot with updated MSTO stars from SDSS """
    #files = glob.glob(path+"stars*")
    #files.append(path+"South/stars-79-new.txt")
    #files.append(path+"South/stars-82-new.txt")
    #files.append(path+"South/stars-86-new.txt")
    #files = glob.glob(path+"FTO_All*")
    #files.append(path+"FTO_south_dirty.csv")
    #files = glob.glob(path+"*dirty*")
    #files = [path+"MSTO_North_plus20.csv", path+"MSTO_South_minus20.csv"]
    files = [path + "blue_all.csv"]
    out = []
    for f in files:
        #data = np.loadtxt(f, skiprows=1)
        data = np.loadtxt(f, delimiter=",", skiprows=1)
        print "Loaded:", f
        for i in range(data.shape[0]):
            #if data[i,2] < ac.getr(16.0):  continue
            #if data[i,2] > ac.getr(22.5):  continue
            gmag = data[i, 3]  # for FTO data
            #gmag = data[i,2]  #for MSTO data
            if gmag < gmin: continue
            if gmag > gmax: continue
            #Distance is ambiguous for blue stars
            #lam, bet = (ac.lb2sgr(data[i,0], data[i,1], ac.getr(data[i,3]) ) )[3:5]
            lam, bet = (ac.lb2sgr(data[i, 0], data[i, 1], 10000.0))[3:5]
            out.append([lam, bet, gmag])
        print "Transformed coordinates:", f
    out = np.array(out)
    if multistep != None:
        #runs = np.arange(10.0, 50.0, 5.0)  #for distance
        runs = np.arange(gmin, gmax, multistep)
        runs = [
            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
        for run in runs:
            print "Starting run", run
            gslice = []
            for i in range(out.shape[0]):
                if out[i, 2] < run: continue
                if out[i, 2] >= (run + multistep): continue
                gslice.append(out[i, :])
            gslice = np.array(gslice)
            hist = pp.HistMaker(gslice[:, 0],
                                gslice[:, 1],
                                0.5,
                                0.5,
                                yarea=(-70.0, 40.0),
                                xarea=(20.0, 320.0))
            hist.savehist(outfile="FTO_" + str(run) + "_hist.csv", fmt='%.1f')
            hist.yflip = 1
            hist.xflip = 1
            hist.ticks = (None, [-60, -40.0, -20.0, 0.0, 20.0, 40.0])
            hist.varea = (0.0, 12.0)
            pp.PlotHist(hist,
                        imfile="FTO_" + str(run) + ".png",
                        cbarO='horizontal')
    else:
        hist = pp.HistMaker(out[:, 0],
                            out[:, 1],
                            1.0,
                            1.0,
                            yarea=(-70.0, 40.0),
                            xarea=(20.0, 320.0))
        hist.savehist(outfile="BLUE_all_hist.csv", fmt='%.1f')
        hist.yflip = 1
        hist.xflip = 1
        hist.labels = (r"$\Lambda$", "B")
        hist.ticks = (None, [-40.0, -20.0, 0.0, 20.0, 40.0, 60.0, 80.0])
        hist.varea = (0.0, 30.0)
        pp.PlotHist(hist, imfile="BLUE_all.png", cbarO='horizontal')
Esempio n. 24
0
def lambet_profiles(path="/home/newbym2/Desktop/sdssN-stars/",
                    glb="*bhbs_all*",
                    lj=0,
                    bj=1,
                    gj=2,
                    lbins=2.5,
                    bbins=0.5,
                    suffix="_bhbs",
                    coords="sgr"):
    """ remixed from plot_profiles in utilities1 """
    files = glob.glob(path + glb)
    print files
    data = []
    g_cut_low, g_cut_high = 16.0, 22.5
    pb = pr.Progressbar(steps=len(files),
                        prefix="Loading Stars:",
                        suffix=None,
                        symbol="#",
                        active="=",
                        brackets="[]",
                        percent=True,
                        size=40)
    for f in files:
        count = 0
        stripedata = np.loadtxt(f, delimiter=",", skiprows=1)
        for i in range(stripedata.shape[0]):
            if stripedata[i, gj] < g_cut_low: continue
            if stripedata[i, gj] > g_cut_high: continue
            #if ac.SDSS_primary(temp[0],temp[1],wedge,fmt="lb",low=9,high=27)==0:  continue
            data.append(
                [stripedata[i, lj], stripedata[i, bj], stripedata[i, gj]])
        pb.updatebar(float(files.index(f) + 1) / float(len(files)))
    data = np.array(data)
    if coords == "sgr":
        count, nStars, pb2 = 0, float(len(data[:, 0])), pr.Progressbar(
            steps=100,
            prefix="Changing Coordinates:",
            suffix=None,
            symbol="#",
            active="=",
            brackets="[]",
            percent=True,
            size=40)
        for i in range(data.shape[0]):
            count += 1
            data[i, 0], data[i, 1] = ac.lb2sgr(data[i, 0], data[i, 1],
                                               50.0)[3:5]
            #data[i,2] = data[i,2]
            if count % 1000 == 0: pb2.updatebar(float(count) / nStars)
    elif coords == "lbr":
        pass
        #data[i,0], data[i,1] = ac.lb2GC(data[i,0], data[i,1], 15)
        #data[i,0], data[i,1] = ac.lbToEq(data[i,0], data[i,1])
    else:
        print "!!! Coordinate system not recognized !!!"
        sys.exit(2)
    pb2.endbar()
    # loop over Lambda slices and plot Beta histograms
    pb3 = pr.Progressbar(steps=len(files),
                         prefix="Making Slices:",
                         suffix=None,
                         symbol="#",
                         active="=",
                         brackets="[]",
                         percent=True,
                         size=40)
    #Ls = (40.0, 130.0, lbins)
    #Ls = (200.0, 300.0, lbins)
    Ls = (201.25, 301.25, lbins)  #for wedges offset by half a wedge
    Lsteps = int((Ls[1] - Ls[0]) / Ls[2])
    for i in range(Lsteps):
        Lname = str(Ls[0] + (Ls[2] * i))[:6] + suffix
        new = []
        for j in range(len(data[:, 0])):
            if data[j, 0] < Ls[0] + (Ls[2] * i): continue
            if data[j, 0] > Ls[0] + (Ls[2] * (i + 1)): continue
            new.append([data[j, 0], data[j, 1], data[j, 2]])
        if len(new) < 1: continue
        new = np.array(new)
        #np.savetxt("stars-lambda-"+("00"+str(i))[-2:]+".txt", new, fmt='%.6f')
        pb3.updatebar(float(i) / float(Lsteps))
        Lhist, Ledges = np.histogram(new[:, 1], int(100 / bbins),
                                     (-60.0, 40.0))
        #output to file
        outstuff = sc.array(zip(Ledges + (bbins / 2.0), Lhist))
        np.savetxt(Lname + ".out", outstuff, fmt='%.2f')
    pb3.endbar()
    print "Ended Successfully"
Esempio n. 25
0
def sky_map(infile="/home/newbym2/Desktop/sdssN-stars/sgr_sky_data.csv",
            dumb=1):
    """Map a variable in Lambda, Beta  """
    if dumb == 1:
        data = np.loadtxt(infile, delimiter=",", skiprows=1)
        l, b = data[:, 0], data[:, 1]
        g_ext, r_ext = data[:, 4], data[:, 5]
        g_sky, r_sky = data[:, 6], data[:, 7]
        print np.ma.min(g_ext), np.ma.max(g_ext)
        lam, bet = ac.lb2sgr(l, b, 30.0)[3:5]
        plt.figure()
        sc = plt.scatter(lam,
                         bet,
                         c=g_ext,
                         cmap=pp.spectral_wb,
                         edgecolors='none',
                         s=3,
                         alpha=0.3,
                         vmin=0,
                         vmax=0.4)
        plt.colorbar(sc)
        plt.xlim(320, 20.0)
        plt.ylim(40.0, -70.0)
    else:
        path = "/home/newbym2/Desktop/FTO-stars/"
        files = glob.glob(path + "FTO_All*")
        files.append(path + "FTO_south_dirty.csv")
        x_range, y_range = (20, 320), (-70, 40)
        x_step, y_step = 0.5, 0.5
        x_bins, y_bins = (x_range[1] - x_range[0]) / x_step, (
            y_range[1] - y_range[0]) / y_step
        try:
            grid = np.loadtxt("reddening_out.txt")
        except IOError:
            grid = np.zeros((y_bins + 1, x_bins + 1), float)
            for f in files:
                data = np.loadtxt(f, delimiter=",", skiprows=1)
                pb = pr.Progressbar(steps=data.shape[0],
                                    prefix="Loading {0}".format(
                                        f.split("/")[-1]),
                                    suffix=None,
                                    symbol="#",
                                    active="=",
                                    brackets="[]",
                                    percent=True,
                                    size=40)
                for i in range(data.shape[0]):
                    lam, bet = (ac.lb2sgr(data[i, 0], data[i, 1], 30.0))[3:5]
                    gridx = (lam - x_range[0]) / x_step
                    gridy = (bet - y_range[0]) / y_step
                    if (gridx < 0) or (gridy < 0): continue
                    if (gridx > x_bins + 1) or (gridy > y_bins + 1): continue
                    if grid[gridy, gridx] < data[i, 13]:
                        grid[gridy, gridx] = data[i, 13]
                    if i % 1000 == 0:
                        pb.updatebar(float(i) / float(data.shape[0]))
                pb.endbar()
            np.savetxt("reddening_out.txt", grid, fmt="%.2f")
        """ plot stuff """
        grid = grid[:, ::-1]
        grid = grid[::-1, :]
        fig = plt.figure(dpi=120)
        ax1 = fig.add_subplot(111)
        im = ax1.imshow(grid,
                        cmap=pp.spectral_wb,
                        norm=None,
                        aspect=None,
                        interpolation='nearest',
                        alpha=None,
                        origin='lower',
                        extent=None,
                        vmin=0.0,
                        vmax=2.0)
        cbar = plt.colorbar(mappable=im, aspect=30, orientation="horizontal")
        xpos = np.arange(0.0, 601.0, 20.0)
        xlab = []
        for i in range(len(xpos)):
            if i % 3 == 0:
                xx = (xpos[i] * x_step) + x_range[0]
                xlab.append(str(xx).split(".")[0])
            else:
                xlab.append("")
        plt.xticks(xpos, xlab[::-1])
        ypos = np.arange(0.0, 221.0, 20.0)
        ylab = []
        for i in range(len(ypos)):
            if i % 2 == 0:
                yy = (ypos[i] * y_step) + y_range[0]
                ylab.append(str(yy).split(".")[0])
            else:
                ylab.append("")
        plt.yticks(ypos, ylab[::-1])
    plt.show()
Esempio n. 26
0
def plot_profiles(path="/home/newbym2/Desktop/starfiles", savewedge=False, suffix=""):
    files = glob.glob(path+"/stars*")
    print files
    suffix = "_rcut_IV"
    data=[]
    r_cut_low, r_cut_high = 40.0, ac.getr(22.5) #ac.getr(16.0), ac.getr(22.5) #20.0 OR 30.0, 45.0
    pb = pr.Progressbar(steps=len(files), prefix="Loading Stars:", suffix=None,
        symbol="#", active="=", brackets="[]", percent=True, size=40)
    for f in files:
        wedge = int(f.split("-")[1].split(".")[0])
        count=0
        stripedata = open(f, "r")
        for line in stripedata:
            count = count + 1
            if count==1:  continue
            if line.strip()=="":  continue
            temp = line.split()
            for i in range(len(temp)):  temp[i] = float(temp[i])
            if (temp[2] < r_cut_low) or (temp[2] > r_cut_high):  continue
            if ac.SDSS_primary(temp[0],temp[1],wedge,fmt="lb",low=9,high=27)==0:  continue
            data.append(temp)
        stripedata.close()
        pb.updatebar(float(files.index(f)+1)/float(len(files)) )
    datar = np.array(data)
    data = np.zeros(datar.shape, float)
    count, nStars, pb2 = 0, float(len(data[:,0])), pr.Progressbar(steps=100,
        prefix="Changing Coordinates:", suffix=None, symbol="#", active="=",
        brackets="[]", percent=True, size=40)
    for i in range(len(data[:,0])):
        count = count + 1
        #data[i,0], data[i,1] = ac.lb2GC(data[i,0], data[i,1], 15)
        #data[i,0], data[i,1] = ac.lbToEq(data[i,0], data[i,1])
        data[i,0], data[i,1] = (ac.lb2sgr(datar[i,0], datar[i,1], 30.0))[3:5]
        data[i,2] = ac.getg(datar[i,2], 4.2)
        if count % 100 == 0:  pb2.updatebar(float(count)/nStars)
    pb2.endbar()
    # loop over Lambda slices and plot Beta histograms
    pb3 = pr.Progressbar(steps=len(files), prefix="Making Slices:", suffix=None,
        symbol="#", active="=", brackets="[]", percent=True, size=40)
    Ls = (200.0, 300.0, 2.5)
    Lsteps = int((Ls[1]-Ls[0])/Ls[2])
    for i in range(Lsteps):
        Lname = str(Ls[0]+(Ls[2]*i) )[:6]+suffix
        new = []
        for j in range(len(data[:,0])):
            if data[j,0] < Ls[0]+(Ls[2]*i):  continue
            if data[j,0] > Ls[0]+(Ls[2]*(i+1)):  continue
            if savewedge:  
                new.append([datar[j,0], datar[j,1], data[j,2]])
                continue
            new.append(data[j,1])
        new = np.array(new)
        if savewedge:
            np.savetxt("stars-lambda-"+("00"+str(i))[-2:]+".txt", new, fmt='%.6f')
        else:
            Lhist, Ledges = np.histogram(new, 140, (-30.0, 40.0))
            #output to file
            outstuff = sc.array(zip(Ledges+0.25, Lhist))
            np.savetxt(Lname+".out", outstuff)
            #plot
            plt.figure(1)
            plt.bar(Ledges[:-1], Lhist, 0.5)
            plt.title(Lname)
            plt.xlabel("B")
            plt.savefig(Lname+".png")
            plt.close('all')
        pb3.updatebar(float(i)/float(Lsteps))
    print "Ended Successfully"