def isolate_real_gals(fullcat,starcat):
    try:
        star_matcher=htm.Matcher(16,ra=starcat['ALPHAWIN_J2000'],dec=starcat['DELTAWIN_J2000'])
    except:
        star_matcher=htm.Matcher(16,ra=starcat['ra'],dec=starcat['dec'])
    full_ind, star_ind, dist=star_matcher.match(ra=fullcat['ALPHAWIN_J2000'],dec=fullcat['DELTAWIN_J2000'],maxmatch=1,radius=2.5E-4)
    this_range=np.arange(len(fullcat)) 
    gals=np.setdiff1d(this_range,full_ind)
    gals_only = fullcat[gals]
    gals_only = gals_only[(gals_only['FWHM_IMAGE']>3) & (gals_only['FLUX_RADIUS']>2.7)] # clean out the junk
    
    return gals_only
Example #2
0
def self_match_cat(cat, superid='SuperID', verbose=False):
    id = catslist[cat['name']]['ID']
    sr = cat['sr'] / 3600

    if verbose:
        print('Self-matching', cat['name'], 'using', id, 'field with sr',
              sr * 3600, 'into new field', superid)

    if not superid in cat['table'].dtype.fields:
        cat['table'].add_column(
            Column(dtype=cat['table'].dtype.fields.get(id)[0],
                   name=superid,
                   length=len(cat['table'][id])))

    ra = cat['table'][cat.get('ra', 'RAJ2000')]
    dec = cat['table'][cat.get('dec', 'DEJ2000')]
    hm = htm.Matcher(10, ra, dec)

    mask = np.zeros(len(cat['table']), dtype=np.bool)
    for i in range(len(cat['table'])):
        if mask[i]:
            continue

        m = hm.match(ra[i], dec[i], sr, maxmatch=0)
        if len(m[1]):
            cat['table'][superid][m[1]] = cat['table'][id][min(m[1])]
            mask[m[1]] = True

    if verbose:
        print(len(np.unique(cat['table'][superid])), '/', len(cat['table']),
              'records unique')
Example #3
0
   def make_annular_cat(self, hdu_ext=2, filter_g=True, clobber=True):
      """
      make a catalog of positions and shapes
      ready for annular.c and lensing in general
      
      Filter_g : whether to clean failed fits or not
      
      """
      
      # actually load the master coadd catalog
      try:
         coadd_cat = Table.read(self.coadd_catalog,hdu=hdu_ext)
      except:
         print("wrong coadd extension, try again?")
         pdb.set_trace()

      # do matching
      fitvd_matcher=htm.Matcher(16,ra=self.master_fitvd['ra'],dec=self.master_fitvd['dec'])
      sex_ind,fitvd_ind,dist=fitvd_matcher.match(ra=coadd_cat['ALPHAWIN_J2000'],dec=coadd_cat['DELTAWIN_J2000'],maxmatch=1,radius=5.5E-4)
      for_annular=Table()
      for_annular.add_columns([coadd_cat['ALPHAWIN_J2000'][sex_ind],coadd_cat[sex_ind]['DELTAWIN_J2000'],coadd_cat[sex_ind]['X_IMAGE'],
                               coadd_cat[sex_ind]['Y_IMAGE']])
      for_annular.add_columns([self.master_fitvd[fitvd_ind]['exp_g'][:,0],self.master_fitvd[fitvd_ind]['exp_g'][:,1]],names=['g1','g2'])
      self.annular_cat = for_annular
        
      # write to file
      if filter_g==True:
         for_annular_clean=for_annular[for_annular['g1']>-10.]
         for_annular_clean.write('fitvd-out.csv',format='ascii.csv',overwrite=clobber)
      else:
         for_annular.write('fitvd-out.csv',format='ascii.csv',overwrite=clobber)
Example #4
0
    def _make_table(self):
        """
        - Match master metacal catalog to source extractor catalog
        - Trim catalog on g_cov, T/T_psf, etc. 
        - Correct g1/g2_noshear for the Rinv quantity (see Huff & Mandelbaum 2017)
        - Make an output table containing (corrected) ellipticities
        - Convert table to a "fiat" format ascii file 
        """

        # This step both applies selection cuts and returns shear-calibrated
        # tangential ellipticity moments
        self._compute_metacal_quantities()

        # Now match trimmed & shear-calibrated catalog against sextractor
        gals = Table.read(self.sexcat, format='fits', hdu=2)
        master_matcher = htm.Matcher(16,
                                     ra=self.mcCat['ra'],
                                     dec=self.mcCat['dec'])
        gals_ind, master_ind, dist = master_matcher.match(
            ra=gals['ALPHAWIN_J2000'],
            dec=gals['DELTAWIN_J2000'],
            radius=5E-4,
            maxmatch=1)
        match_master = self.mcCat[master_ind]
        gals = gals[gals_ind]

        # Write to file
        newtab = Table()
        newtab.add_columns(
            [match_master['id'], match_master['ra'], match_master['dec']],
            names=['id', 'ra', 'dec'])
        newtab.add_columns([gals['X_IMAGE'], gals['Y_IMAGE']])
        newtab.add_columns([match_master['g1_boot'], match_master['g2_boot']],
                           names=['g1_boot', 'g2_boot'])

        newtab.add_columns([match_master['g1_MC'], match_master['g2_MC']],
                           names=['g1_MC', 'g2_MC'])
        newtab.add_columns([match_master['g1_Rinv'], match_master['g2_Rinv']],
                           names=['g1_Rinv', 'g2_Rinv'])
        try:
            newtab.add_columns(
                [match_master['T_gmix'], match_master['flux_gmix']],
                names=['T_noshear', 'flux'])
        except:
            newtab.add_columns(
                [match_master['T_noshear'], match_master['flux']],
                names=['T_noshear', 'flux'])

        newtab.write(
            self.outcat, format='csv',
            overwrite=True)  # file gets replaced in the run_sdsscsv2fiat step
        self._run_sdsscsv2fiat()

        return newtab
Example #5
0
    def _make_table(self):
        """
        - Match master metacal catalog to source extractor catalog
        - Correct g1/g2_noshear for the Rinv quantity (see Huff & Mandelbaum 2017)
        - Make an output table containing (corrected) ellipticities
        - Convert table to a "fiat" format ascii file 
        """

        gals = Table.read(self.sexcat, format='fits',
                          hdu=2)  #contains only analysis objects.
        master_clean = self._compute_metacal_quantities()
        master_matcher = htm.Matcher(16,
                                     ra=master_clean['ra'],
                                     dec=master_clean['dec'])

        gals_ind, master_ind, dist = master_matcher.match(
            ra=gals['ALPHAWIN_J2000'],
            dec=gals['DELTAWIN_J2000'],
            radius=5E-4,
            maxmatch=1)
        match_master = master_clean[master_ind]
        gals = gals[gals_ind]

        newtab = Table()
        newtab.add_columns(
            [match_master['id'], match_master['ra'], match_master['dec']],
            names=['id', 'ra', 'dec'])
        newtab.add_columns([gals['X_IMAGE'], gals['Y_IMAGE']])
        newtab.add_columns([match_master['g1_gmix'], match_master['g2_gmix']],
                           names=['g1_gmix', 'g2_gmix'])

        newtab.add_columns([match_master['g1_MC'], match_master['g2_MC']],
                           names=['g1_MC', 'g2_MC'])
        newtab.add_columns([match_master['g1_Rinv'], match_master['g2_Rinv']],
                           names=['g1_Rinv', 'g2_Rinv'])
        try:
            newtab.add_columns(
                [match_master['T_gmix'], match_master['flux_gmix']],
                names=['T', 'flux'])
        except:
            newtab.add_columns([match_master['T'], match_master['flux']],
                               names=['T', 'flux'])

        newtab.write(
            self.outcat, format='csv',
            overwrite=True)  # file gets replaced in the run_sdsscsv2fiat step
        self._run_sdsscsv2fiat()

        return newtab
def get_stars(truthcats,all_cats):

    """
    isolate stars from GalSim truth catalogs ("truthcats"), and match to SEXtractor
    catalogs ("all_cats"), returning indicies corresponding to stars in all_cats 

    """
    # read in truth catalogs and isolate stars from it (they all have z<=0 by construction!)
    stars=truthcats[truthcats['redshift']==0]
    # Match to observed objects (airy flight cats) in RA/Dec
    star_match=htm.Matcher(16,ra=stars['ra'],dec=stars['dec'])
    all_ind,stars_ind, dist=star_match.match(ra=all_cats['ALPHAWIN_J2000'],dec=all_cats['DELTAWIN_J2000'],maxmatch=1,radius=1.5E-4)
    master_star_cat=hstack([all_cats[all_ind],stars[stars_ind]])
    
    return master_star_cat
def get_galaxies(truthcats,all_cats):

    """
    isolate galaxies from GalSim truth catalogs ("truthcats"), and match to SEXtractor
    catalogs ("all_cats"), returning indicies corresponding to galaxies in all_cats 

    """
    # read in truth catalogs and isolate stars from it (they all have z<=0 by construction!)
    truthgals=truthcats[truthcats['redshift']>0]
    
    # print("a total of %d gals were injected into simulations"%len(gals))
    all_cats=all_cats[(all_cats['FWHM_IMAGE']>3)&(all_cats['FLUX_RADIUS']>2.7)]
    
    # Match to observed objects (airy flight cats) in RA/Dec
    gal_match=htm.Matcher(16,ra=truthgals['ra'],dec=truthgals['dec'])
    all_ind,truth_ind, dist=gal_match.match(ra=all_cats['ALPHAWIN_J2000'],dec=all_cats['DELTAWIN_J2000'],maxmatch=1,radius=2.5E-4)
    
    print("Found %d real galaxies in catalog %s" %(len(all_ind),all_cats))

    master_gal_cat=hstack([all_cats[all_ind],truthgals[truth_ind]])
    
    return master_gal_cat
fulln='/Users/jemcclea/Research/SuperBIT/superbit-ngmix/scripts/output-jitter/one_hour_obs/mock_coadd_cat_full.ldac'
full=Table.read(fulln,format='fits',hdu=2)

truthdir = '/Users/jemcclea/Research/SuperBIT/superbit-metacal/GalSim/cluster3-newpsf/round6'
truthcatn = 'truth_gaussJitter.002.dat'
#truthdir = '/Users/jemcclea/Research/SuperBIT/superbit-ngmix/scripts/output-jitter/one_hour_obs'
#truthcat = 'truth_superbit300004.dat'
truthfile=os.path.join(truthdir,truthcatn)

#truthfile = '/Users/jemcclea/Research/SuperBIT/superbit-ngmix/scripts/output-deep/truth_flight_jitter_only_oversampled_1x300.0006.dat'

truthcat = Table.read(truthfile,format='ascii')
stars=truthcat[truthcat['redshift']==0] 

star_matcher = htm.Matcher(16,ra=stars['ra'],dec=stars['dec'])
matches,starmatches,dist = star_matcher.match(ra=full['ALPHAWIN_J2000'],
                                                    dec=full['DELTAWIN_J2000'],radius=2E-4,maxmatch=1)

stars = full[matches]



# Save result to file, return filename
outname = fulln.replace('.ldac','.star')
full[matches].write(outname,format='fits',overwrite=True)


# Make cute plots, if desired:

from matplotlib import colors
Example #9
0
mcb.fit_metacal(psf_model, gal_model, max_pars, Tguess, prior=prior, ntry=ntry,metacal_pars=metacal_pars)
mcr = mcb.get_metacal_result() # this is a dict

########################################################################
##
##  Do size comparisons
##
########################################################################


truth300_1=Table.read('/Users/jemcclea/Research/GalSim/examples/output-debug/truth_shear_300_1.dat',format='ascii')
gals=truth300_1[ (truth300_1['redshift']>0)]
mcal=Table.read('/Users/jemcclea/Research/SuperBIT/metacal/metacal-debug3-shear.csv',format='csv')
full_full = Table.read('/Users/jemcclea/Research/SuperBIT/superbit-ngmix/scripts/debug3/mock_empirical_debug_coadd_cat_full.ldac',format='fits',hdu=2)

gal_match=htm.Matcher(16,ra=gals['ra'],dec=gals['dec'])
all_ind,truth_ind, dist=gal_match.match(ra=mcal['ra'],dec=mcal['dec'],maxmatch=1,radius=8E-4)


plt.plot((gals[truth_ind]['mom_size'])**4,mcal[all_ind]['T_mcal'],'.',label='mcal',alpha=0.5)
plt.plot((gals[truth_ind]['mom_size'])**4,mcal[all_ind]['T_gmix'],'.',label='gmix',alpha=0.5)
#plt.plot(gals[truth_ind]['g1_nopsf'],mcal[all_ind]['g1_Rinv'],'.',label='<R11>^-1')
#plt.plot(gals[truth_ind]['g1_nopsf'],mcal[all_ind]['g1_MC'],'.',label='Projected into R')
plt.xlabel('truth hsm_sigma**4'); plt.ylabel('T size')
plt.xlim(0,20); plt.ylim(-1,10)
plt.legend()


plt.savefig('MetacalT_v_truthMomSize.png')