Exemplo n.º 1
0
def get_moments(params, filter, out_dir):
    """Computes moments of stars, and moments for of tt_starfields at
    different Focus
    """
    print "Computing Moments"
    print filter, params.seg_id
    stars1 = np.loadtxt(out_dir + filter + '_matched_stars.txt').T
    moments = [[], []]
    hsm_params = galsim.hsm.HSMParams(max_mom2_iter=1000000000)
    fin_stars = []
    for i in range(len(stars1)):
        print "Getting moments of star %i of %i  " % (i, len(stars1))
        x_s = stars1[i][1]
        y_s = stars1[i][2]
        r = stars1[i][3]
        x_t = stars1[i][4]
        y_t = stars1[i][5]
        star_file = params.data_files[filter]
        im_s = fn.get_subImage(x_s,
                               y_s,
                               int(r) * 8,
                               star_file,
                               out_dir,
                               None,
                               save_img=False)
        star_result = galsim.hsm.FindAdaptiveMom(im_s,
                                                 hsmparams=hsm_params,
                                                 strict=False)
        if star_result.error_message != "":
            print "Moments measurement failed for star{0}".format(i)
            continue
        tt_result = {}
        check = False
        for j, focus in enumerate(params.focus):
            print "Computing moments for focus ", focus
            tt_file = params.tt_file_path + filter + '/' + params.tt_file_name[
                focus]
            im_t = fn.get_subImage(x_t,
                                   y_t,
                                   int(r) * 8,
                                   tt_file,
                                   out_dir,
                                   None,
                                   save_img=False)
            result = galsim.hsm.FindAdaptiveMom(im_t,
                                                hsmparams=hsm_params,
                                                strict=False)
            if result.error_message != "":
                check = True
                print "Moments measurement failed for tt star{0} at focus{1}".format(
                    i, focus)
                break
            tt_result[focus] = result
        if check == False:
            fin_stars.append(i)
            moments[0].append(star_result)
            moments[1].append(tt_result)
    return moments, fin_stars
Exemplo n.º 2
0
 def stars_for_focus(self, out_dir):
     """Makes postage stamps of stars. Ordered in decreasing highest SNR"""
     for filt in self.params.filters:
         cat_name = out_dir + '/' + filt + "_clean.cat"
         print "Making postage stamps of stars in filter ", cat_name
         catalog = Table.read(cat_name, format="ascii.basic")
         # get indices of stars with highest SNR
         best_stars = fn.select_good_stars_table(catalog)
         select_stars = self.check_stars(best_stars, filt, out_dir)
         matched_stars = self.match_to_tt(catalog, out_dir, filt,
                                          select_stars)
         print 'Number of stars selected', len(select_stars)
         num = 0
         for i in range(len(matched_stars)):
             x0 = matched_stars[i][1]
             y0 = matched_stars[i][2]
             stamp_size = matched_stars[i][3] * 8
             image = self.params.data_files[filt]
             dir_star = out_dir + '/stars/'
             out_name = filt + '_' + str(int(matched_stars[i][0]))
             # Save image of selected stars
             sub = fn.get_subImage(int(x0),
                                   int(y0),
                                   int(stamp_size),
                                   image,
                                   dir_star,
                                   out_name,
                                   save_img=True)
             num += 1
Exemplo n.º 3
0
def get_moments(params, good_stars,
                filter, out_dir):
    """Computes moments of good_stars, and moments for of tt_starfeilds at
    differnt Focus
    """
    print "Computing Moments"
    print filter, params.seg_id
    stars1 = np.loadtxt(out_dir + filter+'_matched_stars.txt').T
    moments = [[],[]]
    hsm_params =galsim.hsm.HSMParams(max_mom2_iter = 1000000000)
    fin_stars=[]
    for num,i in enumerate(good_stars):
        print "Getting moments of star ", int(stars1[i][0])
        x_s = stars1[i][1]
        y_s = stars1[i][2]
        r = stars1[i][3]
        x_t = stars1[i][4]
        y_t = stars1[i][5]
        star_file = params.data_files[filter]
        im_s = fn.get_subImage(x_s, y_s, int(r)*8, star_file,
                            out_dir, None, save_img=False)
        star_result = galsim.hsm.FindAdaptiveMom(im_s, hsmparams=hsm_params, strict=False)
        if star_result.error_message != "":
            print "Moments measurement failed for star{0}".format(i)
            continue
        tt_result = {}
        check = False
        for j, focus in enumerate(params.focus):
            print "Computing moments for focus ", focus
            tt_file = params.tt_file_path + filter+'/'+ params.tt_file_name[focus]
            im_t = fn.get_subImage(x_t, y_t, int(r)*8, tt_file,
                                out_dir, None, save_img=False)   
            result = galsim.hsm.FindAdaptiveMom(im_t, hsmparams=hsm_params, strict=False)
            if result.error_message != "" :
                check  = True
                print "Moments measurement failed for tt star{0} at focus{1}".format(i,focus)
                break      
            tt_result[focus] = result
        if check == False:
            fin_stars.append(i)
            moments[0].append(star_result)
            moments[1].append(tt_result)
    return moments, fin_stars
Exemplo n.º 4
0
 def stars_for_focus(self, out_dir):
     """Make postage stamps of stars with the highest SNR"""
     for filt in self.params.filters:
         cat_name = out_dir + '/' + filt + "_clean.cat"
         print "Making postage stamps of stars on filter ", cat_name
         catalog = Table.read(cat_name, format="ascii.basic")
         # get indices of stars with highest SNR
         best_stars = fn.select_good_stars_table(catalog)#,nstars=25)
         select_stars = self.check_stars(best_stars,filt, out_dir)
         matched_stars = self.match_to_tt(catalog, out_dir, filt, select_stars)
         print 'Number of stars selected', len(select_stars)
         num =0
         for i in range(len(matched_stars)):
             x0 =  matched_stars[i][1]
             y0 =  matched_stars[i][2]
             stamp_size =  matched_stars[i][3]*8
             image = self.params.data_files[filt]
             dir_star = out_dir+'/stars/'
             out_name = filt+'_' + str(int(matched_stars[i][0]))
             sub = fn.get_subImage(int(x0), int(y0), int(stamp_size), image,
                                   dir_star, out_name, save_img=True)
             num+=1