Exemple #1
0
def make_redmapper_reg():
    """
    Function to make region files from redmapper cs82 cluster ctalog
    Input
     -
    Output
     -
    #FIXME - finish documentation
    """
    mem_data, mem_names = rc.read_catalog("cs82_redmapper_members")
    red_data, red_names = rc.read_catalog("cs82_redmapper")

    print mem_names
    print red_names
    print len(red_data["RA"])
    ids = np.unique(mem_data["MEM_MATCH_ID"])

    str_reg = ""

    print names

    for i in range(len(ids)):
        print i, str(ids[i]) + ":"
        str_reg = "fk5\n"

        f_reg = open(str(ids[i]) + ".reg", "w")

        msk_mem = (mem_data["MEM_MATCH_ID"] == ids[i])
        for j in range(len(mem_data["RA"][msk_mem])):
            str_reg += "circle( %f, %f, %.1f\")\n" % \
                    (mem_data["RA"][msk_mem][j], mem_data["DEC"][msk_mem][j], 5)

        #print str_reg
        f_reg.write(str_reg)
        f_reg.close()
Exemple #2
0
def download_sdss_coadd():
    """
    Download coadimages of redmapper clusters
    Input
     -
    Output
     -
    #FIXME - finish documentation
    """
    mem_data, mem_names = rc.read_catalog("cs82_redmapper_members")
    red_data, red_names = rc.read_catalog("cs82_redmapper")

    for i in range(len(red_data["RA"])):
        ra_red = red_data["RA"][i]
        dec_red = red_data["DEC"][i]
        print i, ra_red, dec_red
        time.sleep(2)
        names = si.get_sdss_tiles_within(ra_red, dec_red, "g", win = 1, \
                                         stripe82 = True)
        print names
        time.sleep(1)
        names = si.get_sdss_tiles_within(ra_red, dec_red, "r", win = 1, \
                                         stripe82 = True)
        print names
        time.sleep(1)
        names = si.get_sdss_tiles_within(ra_red, dec_red, "i", win = 1, \
                                         stripe82 = True)
        print names
Exemple #3
0
def main_redmapper():
    """
    Main function
    Input
     -
    Output
     -
    #FIXME - finish documentation
    """
    mem_data, mem_names = rc.read_catalog("cs82_redmapper_members")
    red_data, red_names = rc.read_catalog("cs82_redmapper")

    print mem_names
    print red_names

    print len(red_data["RA"])
    ids = np.unique(mem_data["MEM_MATCH_ID"])

    for i in range(1, 10):
        id_tmp = red_data["MEM_MATCH_ID"][i]
        msk = (mem_data["MEM_MATCH_ID"] == id_tmp)
        plt.plot(mem_data["RA"][msk], mem_data["DEC"][msk], ".")

        msk = (red_data["MEM_MATCH_ID"] == id_tmp)
        plt.plot(red_data["RA"][msk], red_data["DEC"][msk], 'o', alpha=0.5)
        plt.show()
    """
def main_catalog_analysis():
    """
    Main function
    Input
     -
    Output
     -
    #FIXME - finish documentation
    """
    print "Hello world! from main_catalog_analysis()"
    red_data, red_names = rcat.read_catalog("cs82_redmapper")
    func.s82_ra(red_data["RA"])

    gmbs82_data, gmbs82_names = rcat.read_catalog("gmb_s82")
    func.s82_ra(gmbs82_data["RA"])

    ecg_data, ecg_names = rcat.read_catalog("ecgmm_old")
    func.s82_ra(ecg_data["RA"])

    red_data, red_names = rcat.read_catalog("cs82_redmapper")
    func.s82_ra(red_data["RA"])

    sog_data, sog_names = rcat.read_catalog("sogras_cris")
    func.s82_ra(sog_data["RA"])

    print "gmb_stripe82_clusters_toplevel_v1.fits, %i objects:" % \
           len(gmbs82_data["RA"])
    print gmbs82_names


    print "\n Coadd_ecgmm_belended_2com.fit, %i objects:" % \
          len(ecg_data["RA"])
    print ecg_names



    print "\ncs82_redmapper_v3.21_catalog.fit, %i objects:" % \
           len(red_data["RA"])
    print red_names
    """
    plt.plot(red_data["RA"], red_data["DEC"], ".")
    plt.plot(gmbs82_data["RA"], gmbs82_data["DEC"], ".")
    plt.plot(sog_data["RA"], sog_data["DEC"], "o", alpha = 0.5)
    plt.show()
    plt.plot(ecg_data["RA"], ecg_data["DEC"], ".")
    plt.show()
    """
    msk = (ecg_data["GM_SCALED_NGALS"] > 20)
    print len(ecg_data["GM_SCALED_NGALS"][msk])
    """
Exemple #5
0
def red_cluster_size():
    """
    Computes the size of redmapper clusters.
    Input
     -
    Output
     -
    #FIXME - finish documentation
    """
    mem_data, mem_names = rc.read_catalog("cs82_redmapper_members")
    red_data, red_names = rc.read_catalog("cs82_redmapper")

    ids = np.unique(mem_data["MEM_MATCH_ID"])

    dist = []

    for i in range(len(ids)):
        #    print i, str(ids[i]) + ":"
        msk_mem = (mem_data["MEM_MATCH_ID"] == ids[i])


        max_res = pm.max_diff(red_data["RA"][i], red_data["DEC"][i], \
                      mem_data["RA"][msk_mem], mem_data["DEC"][msk_mem])

        dist.append(max_res)

        if max_res[0] > 7:
            print i, str(ids[i]) + ":"
            print red_data["RA"][i], red_data["DEC"][i]
            print max_res
        """
        names = si.get_sdss_tiles_within(red_data["RA"][i], \
            red_data["DEC"][i], "g", win = 6, stripe82 = True)
        time.sleep(1)
        names = si.get_sdss_tiles_within(red_data["RA"][i], \
            red_data["DEC"][i], "r", win = 6, stripe82 = True)
        time.sleep(1)
        names = si.get_sdss_tiles_within(red_data["RA"][i], \
            red_data["DEC"][i], "i", win = 6, stripe82 = True)
        time.sleep(1)
        """

    print max(dist)
    """
def main_cs82_footprint_cut():
    """
    Main function
    Input
     -
    Output
     -
    """

    gmb_data, gmb_names, gmb_hdu = \
                                rcs.read_catalog("ecgmm_old", return_hdu = True)
    gmb_data.sort(order="NGALS")
    fuc.s82_ra(gmb_data["RA"])
    print "gmb_names", gmb_names, "\n"

    msk = np.zeros(len(gmb_data["RA"]), dtype=bool)
    cs82_lim = coo.cs82_limits()[0]
    for i in range(len(cs82_lim)):
        fuc.s82_ra(cs82_lim[i][0])
        msk = msk | ( gmb_data["RA"] > cs82_lim[i][0][0] ) & \
                    ( gmb_data["RA"] < cs82_lim[i][0][1] ) & \
                    ( gmb_data["DEC"] > cs82_lim[i][1][0]) & \
                    ( gmb_data["DEC"] < cs82_lim[i][1][1])

    gmb_cs82_dic = {}
    for i in gmb_names:
        gmb_cs82_dic[i] = gmb_data[i][msk]

    gmb_cs82_columns = []
    for i in range(len(gmb_hdu[1].columns.formats)):
        gmb_cs82_columns.append( pyfits.Column(name = gmb_names[i], \
                                 format = gmb_hdu[1].columns.formats[i], \
                                 array = gmb_cs82_dic[gmb_names[i]]) )
    tbhdu_s82 = pyfits.new_table(gmb_cs82_columns)
    tbhdu_s82.writeto("test.fits")

    for i in range(len(cs82_lim)):
        plt.plot([cs82_lim[i][0][0], cs82_lim[i][0][1], cs82_lim[i][0][1], \
                  cs82_lim[i][0][0], cs82_lim[i][0][0]], \
                 [cs82_lim[i][1][0], cs82_lim[i][1][0], cs82_lim[i][1][1], \
                  cs82_lim[i][1][1], cs82_lim[i][1][0]], \
                 'b-')
    plt.plot(gmb_data["RA"][msk], gmb_data["DEC"][msk], ".")
    plt.show()

    print len(gmb_data["RA"][msk])
Exemple #7
0
def find_cs82_image():
    """
    Function to find in which cs82 image the redmapper clusters are and create
    the command to make a cut_out using imcp.py from sltools
    Input
     -
    Output
     -
    #FIXME - finish documentation
    """
    print "find_cs82_im"
    red_data, red_names = rc.read_catalog("cs82_redmapper")

    limits, imgs = cor.cs82_limits()
    cs82_path = os.environ["CS82_IMAGE_DIR"]

    for i in range(len(limits)):
        #print imgs[i]
        """
        if limits[i][0][1] > 300 and limits[i][0][0] < 300:
            print imgs[i]
            print limits[i]
        """

        str_out = ""
        for j in range(len(red_data["RA"])):

            if red_data["RA"][j] < limits[i][0][1] and \
               red_data["RA"][j] > limits[i][0][0] and \
               red_data["DEC"][j] < limits[i][1][1] and \
               red_data["DEC"][j] > limits[i][1][0]:
                hdu = pyfits.open(imgs[i])
                hdr = hdu[0].header
                pix_xy = sltools_wcs_conv.radec2xy(hdr, red_data["RA"][j], \
                                                   red_data["DEC"][j])

                str_out = "imcp.py " + imgs[i] + " "
                str_out += str(pix_xy[0]) + " " + str(pix_xy[1]) + " "
                str_out += "-s 600,600 -J -o "
                str_out += str(red_data["MEM_MATCH_ID"][j]) + "_"
                str_out += imgs[i][len(cs82_path) + 1:len(cs82_path) + 10]
                if pix_xy[0] > 0 and  pix_xy[0] < 21000 and \
                   pix_xy[1] > 0 and  pix_xy[1] < 21000:
                    print str_out
Exemple #8
0
def red_sdss_ds9(cat_position):
    """
    Function to open ds9 with colored image and reg files with cluster members
    for the cs82_redmapper clusters.
    It uses comand line, use the package ds9_control.py instead of this!
    Input
     -
    Output
     -
    #FIXME - finish documentation
    """
    red_data, red_names = rc.read_catalog("cs82_redmapper")
    red_id = red_data["MEM_MATCH_ID"][cat_position]
    names = si.get_sdss_tiles_within(red_data["RA"][cat_position], \
                   red_data["DEC"][cat_position], "g", win = 1, stripe82 = True)
    print names
    sdss_dir = os.environ["SDSS_IMAGE_DIR"]
    imi = []
    img = []
    imr = []
    for i in range(len(names)):
        image_def = names[i][:len(sdss_dir)+12] + "i" + \
                    names[i][len(sdss_dir)+13:]
        imi.append(image_def)
        image_def = names[i][:len(sdss_dir)+12] + "r" + \
                    names[i][len(sdss_dir)+13:]
        imr.append(image_def)
        image_def = names[i][:len(sdss_dir)+12] + "g" + \
                    names[i][len(sdss_dir)+13:]
        img.append(image_def)

    str_cmd = "ds9 -rgb " + imi[0] + " -scale zscale -green " + imr[0] + \
              " -scale zscale -blue " + img[0] + " -scale zscale -region " + \
              str(red_id) + ".reg"

    print imi
    print imr
    print img
    print str_cmd
    os.system(str_cmd)
Exemple #9
0
def find_sdss_image():
    """
    Function to make create the sdss image for the redmapper clusters
    Input
     -
    Output
     -
    #FIXME - finish documentation
    """
    red_data, red_names = rc.read_catalog("cs82_redmapper")

    str_swarp = ""
    str_imcp = ""
    #    i_tmp = 897

    for i in range(31, len(red_data["RA"])):
        time.sleep(1)
        print i
        names = si.get_sdss_tiles_within(red_data["RA"][i], \
                              red_data["DEC"][i], "i", win = 5, stripe82 = True)

        sdss_out_im = str(red_data["MEM_MATCH_ID"][i]) + "_sdss_i.fits "

        str_swarp = "swarp -IMAGEOUT_NAME " + sdss_out_im
        for j in range(len(names)):
            str_swarp += names[j] + " "

        os.system(str_swarp)
        hdu = pyfits.open(sdss_out_im)
        hdr = hdu[0].header
        pix_xy = sltools_wcs_conv.radec2xy(hdr, red_data["DEC"][i], \
                                            red_data["RA"][i])

        str_imcp = "imcp.py " + sdss_out_im + " "
        str_imcp += str(pix_xy[0]) + " " + str(pix_xy[1])
        str_imcp += " -s 600,600 -J -o " + sdss_out_im[:-6]
        os.system(str_imcp)
def main_redmapper_members():
    """
    Main function
    Input
     -
    Output
     -
    #FIXME - finish documentation
    """
    redm_data, redm_names = rc.read_catalog("cs82_redmapper_members")
    s82_ra(redm_data["RA"])

    sogr_data, sogr_names = rc.read_catalog("sogras_cris")
    s82_ra(sogr_data["RA"])

    red_data, red_names = rc.read_catalog("cs82_redmapper")

    ecgmm_data, ecgmm_names = rc.read_catalog("bcg_r200_old")
    s82_ra(ecgmm_data["RA"])

    #    print redm_names
    #    print red_names
    ids = np.unique(redm_data["MEM_MATCH_ID"])

    selec_reg = []
    for i in range(len(sogr_data["RA"])):
        selec_reg.append( fc.select_region(redm_data["RA"], redm_data["DEC"], \
                                     sogr_data["RA"][i], sogr_data["DEC"][i], \
                                     3) )


#        print i, len(selec_reg[i])
    """
    for i in range(len(selec_reg)):
        if len(selec_reg[i]) != 0:
            file_reg = open(sogr_data["ID"][i] + ".reg", "w")
            for j in range(len(selec_reg[i])):
                print i, j
            file_reg.close()
    """
    """
    msk_id =  (redm_data["MEM_MATCH_ID"] == ids[7])
    plt.scatter(redm_data["RA"][msk_id], redm_data["DEC"][msk_id], \
                s = np.exp(redm_data["MODEL_MAG"][msk_id] - \
                redm_data["MODEL_MAG"][msk_id].min()), alpha = 0.7)
    plt.plot(red_data["RA"][7], red_data["DEC"][7], "r", markersize = 10, \
             marker = "H", alpha = 0.5)
    plt.show()
    """

    for i_ids in np.unique(redm_data["MEM_MATCH_ID"]):
        msk = (redm_data["MEM_MATCH_ID"] == i_ids)
        plt.plot(redm_data["RA"][msk], redm_data["DEC"][msk], ".")

    plt.plot(ecgmm_data["RA"], ecgmm_data["DEC"], 'mv', markersize = 7, \
             label = "ecgmm clusters")

    plt.plot(sogr_data["RA"], sogr_data["DEC"], "b^", \
            markersize = 7, label = "SOGRAS")

    for i in range(len(sogr_data["RA"])):
        circ = fc.make_circunference(2.0/60.0, sogr_data["RA"][i], \
                                     sogr_data["DEC"][i])
        if sogr_data["ID"][i][:1] == "S":
            plt.plot(circ[0], circ[1], 'b-')
        else:
            plt.plot(circ[0], circ[1], 'r-')
    plt.legend()
    plt.xlim(-51, 61)
    plt.ylim(-1.25, 1.25)
    plt.show()

    print sogr_data["ID"]
Exemple #11
0
def main_ds9_control():
    """
    Main function
    Input
     -
    Output
     -
    #FIXME - finish documentation
    """

    red_data = rcs.read_catalog("cs82_redmapper")

    sdss_vec = []
    reg_vec = []
    cs82_vec = []

    for i in range(len(red_data[0]["MEM_MATCH_ID"])):
        #print red_data[0]["MEM_MATCH_ID"][i]

        obj_id = red_data[0]["MEM_MATCH_ID"][i]

        imi = "/data2/redmapper_stuff/sdss_cuts/"
        imi += str(obj_id)
        imi += "_sdss_i0.fits"

        img = "/data2/redmapper_stuff/sdss_cuts/"
        img += str(obj_id)
        img += "_sdss_g0.fits"

        imr = "/data2/redmapper_stuff/sdss_cuts/"
        imr += str(obj_id)
        imr += "_sdss_r0.fits"

        cs82_im = glob.glob("/data2/redmapper_stuff/cs82_cuts/" + \
                          str(obj_id) + "_*.fits")
        reg_file = glob.glob("/data2/redmapper_stuff/members_reg/" + \
                          str(obj_id) + ".reg")

        sdss_vec.append([imi, imr, img])
        cs82_vec.append(cs82_im)
        reg_vec.append(reg_file)
        #print reg_vec[i], cs82_vec[i]

    d1 = ds9.ds9()

    imcs82 = "/data2/redmapper_stuff/cs82_cuts/16_S82m13p_y0.fits"

    reg = "/data2/redmapper_stuff/members_reg/16.reg"

    var = ""

    count = -1

    user_reg = []

    while var != "x" and count < len(sdss_vec) - 1:
        if var == "":
            user_reg = []
            count += 1
            print "Loading image %i of %i" % (count + 1, len(sdss_vec))
            print "Image ID = %i" % red_data[0]["MEM_MATCH_ID"][count]
            d1.set("frame delete all")
            load_rgb(sdss_vec[count][0], sdss_vec[count][1], \
                     sdss_vec[count][2], d1)

            for j in range(len(cs82_vec[count])):
                d1.set("frame new")
                d1.set("zoom 1.0")
                d1.set("file " + cs82_vec[count][j])
                d1.set("zoom 1.0")
            d1.set("frame next")
#            ds9_match(d1)
        elif var == "reg":
            print reg_vec[count][0]
            d1.set("regions " + reg_vec[count][0])
        elif var == "regr":
            d1.set("regions delete all")
        elif var == "regs":
            reg = d1.get("regions -system wcs").split("\n")
            user_reg = get_reg_arc(reg)
            save_reg_arc(user_reg, red_data[0]["MEM_MATCH_ID"][count])
        elif var == "color":
            d1.set("cmap value 1 0.5")
        elif var == "m":
            d1.set("match frame wcs")
        elif var[:4] == "goto":
            print int(var[5:])
            count = int(var[5:]) - 2
        else:
            print "Command", var, "does not exists"
            print var[:3]

        var = raw_input("Command: ")