Example #1
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')
Example #2
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"
Example #3
0
def make_diff_hist():
    """ Subtracts the simulated streams from the real data """
    folder = "/home/newbym2/Dropbox/Research/sgrLetter/"
    data = np.loadtxt("SDSSnorth.csv", delimiter=",")
    sims = ["streamgen_bifGood.csv", "streamgen_bif50Good.csv", "streamgen_bifExtra.csv", "streamgen_bifShift.csv"]
    outs = ["streamgen_ccdiff.png", "streamgen_cc50good.png", "streamgen_ccExtra.png", "streamgen_ccShift.png"]
    #sim = np.loadtxt("simtotbif50m30_radec.csv", delimiter=",")
    #sim = np.loadtxt("simtotbifm2_radec.csv", delimiter=",")
    #sim = np.loadtxt("streamgen_bifExtra.csv", delimiter=",")
    #sim = np.loadtxt("streamgen_bifGood.csv", delimiter=",")
    #sim = np.loadtxt("streamgen_bif50Good.csv", delimiter=",")
    for z in range(len(sims)):
        sim = np.loadtxt(folder+sims[z], delimiter=",")
        for i in range(sim.shape[0]):
            for j in range(sim.shape[1]):
                if data[i,j] < 1.0:  sim[i,j] = 0.0
        sky = pp.HistMaker([1,2], [1,2], xsize=0.5, ysize=0.5,
            xarea=(120.0, 250.0), yarea=(-10.0, 50.0))
        #new = sim #data - sim
        new = data - sim
        sky.H = new
        sky.cmap = 'color'
        sky.varea = (0.0,200.0)
        pp.PlotHist(sky, "sim_"+outs[z])
        #pp.PlotHist(sky, "data.png"); break
    #pp.PlotHist(sky, "streamgen_bif50Good_bwdiff.png")
    print "All done"
Example #4
0
def plot_from_file(
        infile="/home/newbym2/Newby-tools/paper-tools/FTO_All_hist.csv",
        outfile="FTO_All.png"):
    """ creates a image plot from a file """
    #indata = np.loadtxt(infile, delimiter=",")
    #hist = pp.HistMaker([0.0, 1.0], [0.0, 1.0], 0.5, 0.5, yarea=(-70.0, 40.0), xarea=(20.0, 320.0))
    #hist = pp.HistMaker([0.0, 1.0], [0.0, 1.0], 1.0, 1.0, yarea=(-70.0, 40.0), xarea=(20.0, 320.0))
    hist = pp.HistFromFile(infile,
                           0.5,
                           0.5,
                           yarea=(-70.0, 40.0),
                           xarea=(20.0, 320.0))
    #hist.H = indata
    hist.yflip = 1
    hist.xflip = 1
    hist.cmap = "bw"
    hist.labels = (r"$\Lambda$", r"${\rm B}$")
    hist.ticks = (range(20, 321, 20), [-60, -40, -20, 0, 20, 40])
    #hist.varea=(0.0, 200.0)  # FTOs, color
    hist.varea = (0.0, 120.0)  # FTOs, bw
    #hist.varea=(0.0, 45.0)  # BHBs
    pp.PlotHist(hist,
                imfile=outfile,
                cbarO='horizontal',
                cax=[0.1, 0.75, 0.8, 0.02])
Example #5
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])
Example #6
0
def Mgiant_hist():
    data = np.loadtxt("/home/newbym/Desktop/Mgiant_wise_sgr.csv",
                      delimiter=",",
                      skiprows=1)
    print data.shape
    #data[:,9] = -1.0*data[:,9]
    hist = pp.HistMaker(data[:, 8], data[:, 9], 1.0, 1.0,
                        yarea=(-90.0, 90.0))  #, xarea=(20.0, 320.0) )
    #lam, bet = ac.lb2sgr(data[:,2], data[:,3], 100.0 )[3:5]   # use the proxy distance that is same as MSTOs
    #hist = pp.HistMaker(lam, bet, 1.0, 1.0, yarea=(-90, 90))
    hist.savehist(outfile="Mgiant_test3.csv", fmt='%.1f')
    hist.yflip = 1
    hist.xflip = 1
    hist.labels = (r"$\Lambda$", r"$B$")
    #hist.ticks = (None, [-40.0, -20.0, 0.0, 20.0, 40.0, 60.0, 80.0])
    hist.varea = (0.0, 200.0)
    pp.PlotHist(hist, imfile="Mgiant_sgr.png", cbarO='horizontal')
Example #7
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"
Example #8
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"
Example #9
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')