def __init__(self, cb, cv, ci, cz, field='n', drop='b', key='g04'): """ Read the catalogs in all four filters. """ self.c = {} self.bands = ['f435w', 'f606w', 'f775w', 'f850lp'] self.c['f435w'] = cb self.c['f606w'] = cv self.c['f775w'] = ci self.c['f850lp'] = cz if field in ['n', 's']: self.zeropoints = hst_zeropoints.zpt_goodsv2 elif field == 'udf': self.zeropoints = hst_zeropoints.zpt_udf self.magiso_1sig = {} self.magauto_1sig = {} self.drop = drop for b in self.bands: # calculate 1-sigma FLUX_ISO flux_iso = self.c[b].flux_iso fluxerr_iso = self.c[b].fluxerr_iso flux_iso_1sig = where(flux_iso / fluxerr_iso > 1., flux_iso, fluxerr_iso) mag_iso_1sig = self.zeropoints[b] - 2.5 * log10(flux_iso_1sig) self.magiso_1sig[b] = mag_iso_1sig # calculate 1-sigma FLUX_AUTO flux_auto = self.c[b].flux_auto fluxerr_auto = self.c[b].fluxerr_auto flux_auto_1sig = where(flux_auto / fluxerr_auto > 1., flux_auto, fluxerr_auto) mag_auto_1sig = self.zeropoints[b] - 2.5 * log10(flux_auto_1sig) self.magauto_1sig[b] = mag_auto_1sig self.lcc_dropout = lcc.colorcrit() self.lcc_dropout(drop, key)
def __init__(self, catalog, field, interpolate=True, interp_dz=0.02, expand=[0.0, 0.0], SN_lolim={'acs_f850lp': 5.0}, SN_hilim={'acs_f435w': 5.0}, mag_in='m1500_in', re_in='re_in_arcsec'): z0 = 5.0 KernelFactory.__init__(self, catalog, z0, 3.5, 6.5, interpolate=interpolate, expand=expand, mag_in=mag_in, re_in=re_in, zeropoints=zeropoints_goodsv2) self.field = field self.lcc = lcc.colorcrit() self.lcc = self.lcc('f606w_drop', 'Gia04') self.SN_lolim = SN_lolim self.SN_hilim = SN_hilim self.bands = ['acs_f435w', 'acs_f606w', 'acs_f775w', 'acs_f850lp'] self.area = area[field] self.area_unit = area_unit self.pixscale = pixscale
def __init__( self, catalog, field, droplabel="UBVY105", interpolate=True, interp_dz=0.02, n_repeat=5, expand=[0.0, 0.0], mag0=22.0, SN_lolim={ 'wfc3_f160w': 5.0, 'wfc3_f105w': 5.0, 'acs_f435w': 3.0, 'acs_f606w': 5.0 }, mag_in='m1500_in', re_in='re_in_arcsec', hstBands=['acs_f435w', 'acs_f606w', 'wfc3_f105w', 'wfc3_f160w'], uband='vimos_u'): z0 = 3.5 KernelFactory.__init__(self, catalog, z0, 2.5, 4.5, interpolate=interpolate, n_repeat=n_repeat, expand=expand, mag_in=mag_in, re_in=re_in) self.field = field self.lcc = lcc.colorcrit() self.SN_lolim = SN_lolim print "droplabel: ", droplabel self.lcc = self.lcc('uvimos', droplabel) print "Eval_string:", self.lcc.eval # if self.field.lower() == 'ers': # if droplabel == None: # droplabel = 'UBVY098' # self.lcc = self.lcc('uvimos', droplabel) # # self.bands=['acs_f435w','acs_f606w','wfc3_f098m','wfc3_f160w'] # else: # if droplabel == None: # droplabel = 'UBVY105' # self.lcc = self.lcc('uvimos', droplabel) # self.bands=['acs_f435w','acs_f606w','wfc3_f105w','wfc3_f160w'] self.bands = hstBands self.uband = uband self.area = area[field] self.area_unit = area_unit self.pixscale = pixscale self.umag_kpdf = umag_kpdf[field] self.umag_1sig_kpdf = umag_1sig_kpdf[field] self._drawn_umag = False self.mag0 = mag0
def select_idrops_goodss(c, filename, key='g11', veto=True): """Select i-dropouts usage: idrops = select_idrops_goodss(c, filename, key) where filename is the name of the output catalog. """ SN_b = c.acs_f435w_flux / c.acs_f435w_fluxerr SN_v = c.acs_f606w_flux / c.acs_f606w_fluxerr SN_i = c.acs_f775w_flux / c.acs_f775w_fluxerr SN_z = c.acs_f850lp_flux / c.acs_f850lp_fluxerr SN_J = c.wfc3_f125w_flux / c.wfc3_f125w_fluxerr SN_H = c.wfc3_f160w_flux / c.wfc3_f160w_fluxerr imag = where((SN_i > 1.) & (c.acs_f775w_flux > 0), uJy_to_mag(c.acs_f775w_flux), uJy_to_mag(c.acs_f775w_fluxerr)) zmag = where((SN_z > 1.) & (c.acs_f850lp_flux > 0), uJy_to_mag(c.acs_f850lp_flux), uJy_to_mag(c.acs_f850lp_fluxerr)) jmag = where((SN_J > 1.) & (c.wfc3_f125w_flux > 0), uJy_to_mag(c.wfc3_f125w_flux), uJy_to_mag(c.wfc3_f125w_fluxerr)) hmag = where((SN_H > 1.) & (c.wfc3_f160w_flux > 0), uJy_to_mag(c.wfc3_f160w_flux), uJy_to_mag(c.wfc3_f160w_fluxerr)) imz = imag - zmag zmj = zmag - jmag if veto: # use B-band and V-band as veto bands othercrit = ((SN_H >= 5.) & (SN_z >= 3.) & (SN_J >= 3.) & (SN_b <= 2.0) & (SN_v <= 2.0)) #& (c.acs_f775w_fluxerr > 0.) else: othercrit = ((SN_H >= 5.) & (SN_z >= 3.) & (SN_J >= 3.) ) #& (c.acs_f775w_fluxerr > 0.)) cc = lcc.colorcrit() idrops = cc('i', key) idrops.select(imz, zmj) idrops.crit = (idrops.crit & othercrit) idrops.color1_selected = idrops.color1[idrops.crit] idrops.color2_selected = idrops.color2[idrops.crit] print sum(idrops.crit) cols = [] for i in range(len(c.Columns)): cname = c.Columns[i] carray = c.__getitem__(cname)[idrops.crit] cformat = c.d.formats[i] cols += [pyfits.Column(name=cname, format=cformat, array=carray)] coldefs = pyfits.ColDefs(cols) tbhdu = pyfits.new_table(coldefs) if os.path.exists(filename): os.system('rm %s' % filename) tbhdu.writeto(filename) return idrops
def __call__(self,simcatalog,field,plot_diag=False,ktest=None, bands=['acs_f435w','acs_f606w','acs_f775w','acs_f850lp'], sn_lolim={'acs_f850lp':5.0}, sn_hilim={}, interpolate=False,dznew=0.1): """ simcatalog --- the simulation catalog as a FITS table. """ # Initialize i-dropout color criteria self.lcc = lcc.colorcrit(lib=lcc.cc_library) self.lcc = self.lcc('b','g04') # Use Giavalisco et al. 2004 criteria c = Ftable(simcatalog) # Now initialize the attributes for b in bands: bs = filter_dic[b] # short name of filter b flux_iso = getattr(c,'%s_flux_iso'%bs) fluxerr_iso = getattr(c,'%s_fluxerr_iso'%bs) mag_iso = getattr(c,'%s_mag_iso'%bs) # calculate 1-sigma upper limits on sources with S/N < 1 mag_iso = N.where(flux_iso/fluxerr_iso>1.0,mag_iso,zeropoints[b]-2.5*N.log10(fluxerr_iso)) setattr(self,b+'_mag',mag_iso) # MAG_ISO --> for color calculation setattr(self,b+'_flux',getattr(c,'%s_flux_auto'%bs)) # FLUX_AUTO setattr(self,b+'_fluxerr',getattr(c,'%s_fluxerr_auto'%bs)) # FLUXERR_AUTO setattr(self,b+'_sn', getattr(self,'%s_flux'%b)/getattr(self,'%s_fluxerr'%b)) # S/N calculated using FLUX_AUTO # Now construct S/N criteria self.sncrit = N.ones(len(c.d),'bool') for b in sn_lolim.keys(): # enforce S/N lower limits self.sncrit = self.sncrit & (getattr(self,b+'_sn')>=sn_lolim[b]) for b in sn_hilim.keys(): # enforce S/N upper limits (veto bands) self.sncrit = self.sncrit & (getattr(self,b+'_sn')<sn_hilim[b]) print "Total number of objects satisfying the S/N criteria:", \ sum(self.sncrit) print "Do selections..." self.color1 = self.acs_f435w_mag-self.acs_f606w_mag self.color2 = self.acs_f606w_mag-self.acs_f850lp_mag self.lcc.select(self.color1,self.color2) # do color selection! self.lcc.crit = self.lcc.crit & self.sncrit # enforce S/N criteria self.dropcrit = self.lcc.crit & (c.detect==True) # just in case self.detect = c.detect.copy() print "Selection done." print "Total number of objects in the catalog: %d" % len(c.d) print "Total number selected as B-dropouts: %d" % (sum(self.dropcrit)) # Now invoke zdist.zdgrid.__call__ to calculate P(z) zdist.zdgrid.__call__(self,c,interpolate=interpolate,dznew=dznew, plot_diag=plot_diag,ktest=ktest)
def __init__(self, drop='f606w', droplabel='Gia04'): idropsdir = '/Users/khuang/Dropbox/Research/bivariate/vdrops_sample' magfiles = ['vdrops_goods_colors_ext0.0.dat', 'vdrops_goods_colors_ext0.1.dat', 'vdrops_goods_colors_ext0.2.dat', 'vdrops_goods_colors_ext0.3.dat'] for i in range(len(magfiles)): magfiles[i] = os.path.join(idropsdir, magfiles[i]) labels = ['E(B-V)=0','E(B-V)=0.1','E(B-V)=0.2','E(B-V)=0.3'] self.zcenter = 5.0 self.zmarks = [4.0, 4.5, 5.0, 5.5, 6.0] self.color1 = ['f606w', 'f775w'] self.color2 = ['f775w', 'f850lp'] super(VdropsPlotFactory, self).__init__(magfiles, labels, self.zcenter, zmarks=self.zmarks) # can also plot the dropout criteria self.lcc = lcc.colorcrit() self.lcc = self.lcc(drop, droplabel)
def __init__(self, color1, color2, zcenter, magfiles=[], labels=[], galtemplate=LBG_template, ebmv=[0.,0.1,0.2,0.3], drop='f814w', droplabel='MACS0454', starcolors=plot_colors.starcolors_default): """ color1, color2 : The filters that constitute each color, like color1 = ['f814w', 'f105w'] zcenter : The nominal central redshift for the target LBG sample. drop, droplabel: Two keywords for searching a specific set of color cuts in LBG_criteria_data.yml starcolors : A text file containing the expected colors of stars from the Pickles library; it may or may not have all the filters we want... If starcolors == "", we will re-compute the colors within our custom filter set. magfiles : Files containing the expected colors of galaxy templates as a function of redshift. If magfiles == [], we will re-compute the colors within our custom filter set. labels : The label for each galaxy SED in magfiles. The length of magfiles should equal the length of labels. """ # magfiles = ['zdrops_macs0454_colors.dat', # 'zdrops_macs0454_colors_ext0.1.dat', # 'zdrops_macs0454_colors_ext0.2.dat'] # labels = ['E(B-V)=0','E(B-V)=0.1','E(B-V)=0.2'] assert len(magfiles) == len(labels) self.zcenter = zcenter self.color1 = map(lambda x: x.lower(), color1) self.color2 = map(lambda x: x.lower(), color2) self.drop = drop if not len(magfiles): for i in range(len(ebmv)): mf_name = '%s_drops_%s_colors_ext%.2f.dat' % (drop, droplabel, ebmv[i]) self.calc_LBG_colors(galtemplate, mf_name, ebmv=ebmv[i]) magfiles += [mf_name] labels += ['E(B-V)=%.2f' % ebmv[i]] self.zmarks = np.linspace(zcenter-1., zcenter+1., 5) print self.zmarks if not starcolors: raise NotImplementedError, "Please calculate the expected stellar colors first..." super(LBGPlotFactory, self).__init__(magfiles, labels, self.zcenter, zmarks=self.zmarks, starcolors=starcolors) # can also plot the dropout criteria self.lcc = lcc.colorcrit() self.lcc = self.lcc(drop, droplabel)
def select_bdrops_goodss(c, filename, key='g04'): """ Select B-dropouts usage: bdrops = select_bdrops_goodss(c, filename) where filename is the name of the output catalog. """ SN_b = c.acs_f435w_flux / c.acs_f435w_fluxerr SN_v = c.acs_f606w_flux / c.acs_f606w_fluxerr SN_z = c.acs_f850lp_flux / c.acs_f850lp_fluxerr bmag = where((SN_b > 1.) & (c.acs_f435w_flux > 0), uJy_to_mag(c.acs_f435w_flux), uJy_to_mag(c.acs_f435w_fluxerr)) vmag = where((SN_v > 1.) & (c.acs_f606w_flux > 0), uJy_to_mag(c.acs_f606w_flux), uJy_to_mag(c.acs_f606w_fluxerr)) zmag = where((SN_z > 1.) & (c.acs_f850lp_flux > 0), uJy_to_mag(c.acs_f850lp_flux), uJy_to_mag(c.acs_f850lp_fluxerr)) bmv = bmag - vmag vmz = vmag - zmag othercrit = ((SN_z >= 5.0) & (SN_v >= 3.0) & ((c.class_star <= 0.8) | (zmag >= 26.0))) cc = lcc.colorcrit() bdrops = cc('b', key) bdrops.select(bmv, vmz) bdrops.crit = (bdrops.crit & othercrit) bdrops.color1_selected = bdrops.color1[bdrops.crit] bdrops.color2_selected = bdrops.color2[bdrops.crit] print sum(bdrops.crit) cols = [] for i in range(len(c.Columns)): cname = c.Columns[i] carray = c.__getitem__(cname)[bdrops.crit] cformat = c.d.formats[i] cols += [pyfits.Column(name=cname, format=cformat, array=carray)] coldefs = pyfits.ColDefs(cols) tbhdu = pyfits.new_table(coldefs) if os.path.exists(filename): os.system('rm %s' % filename) tbhdu.writeto(filename) return bdrops
def __init__(self, catalog, field, interpolate=True, interp_dz=0.02, expand=[0.0, 0.0], SN_lolim={ 'wfc3_f160w': 5.0, 'wfc3_f125w': 3.5, 'acs_f850lp': 2.0 }, SN_hilim={'acs_f435w': 3.0}, mag_in='m1500_in', re_in='re_in_arcsec'): z0 = 6.0 KernelFactory.__init__(self, catalog, z0, 4.5, 7.5, interpolate=interpolate, expand=expand, mag_in=mag_in, re_in=re_in) self.field = field self.lcc = lcc.colorcrit() self.SN_lolim = SN_lolim self.SN_hilim = SN_hilim self.lcc = self.lcc('f775w_drop', 'Hua13') self.bands = [ 'acs_f435w', 'acs_f606w', 'acs_f775w', 'acs_f850lp', 'wfc3_f125w', 'wfc3_f160w' ] for b in self.bands: self.setMagnitudes(b) self.area = area[field] self.area_unit = area_unit self.pixscale = pixscale
def __init__(self, drop='uvimos', droplabel='UBVY105', bands=['uvimos','f435w','f606w','f105w'], zcenter=3.3): udropsdir = '/Users/khuang/Dropbox/Research/bivariate/udrops_sample' magfiles = ['udrops_gds_colors_ext0.0.dat', 'udrops_gds_colors_ext0.1.dat', 'udrops_gds_colors_ext0.2.dat', 'udrops_gds_colors_ext0.3.dat'] for i in range(len(magfiles)): magfiles[i] = os.path.join(udropsdir, magfiles[i]) labels = ['E(B-V)=0','E(B-V)=0.1','E(B-V)=0.2','E(B-V)=0.3'] self.zcenter = zcenter self.zmarks = [2.5, 3., 3.5, 4.] if len(bands) == 4: self.color1 = [bands[0], bands[1]] self.color2 = [bands[2], bands[3]] else: self.color1 = [bands[0], bands[1]] self.color2 = [bands[1], bands[2]] super(UdropsPlotFactory, self).__init__(magfiles, labels, self.zcenter, zmarks=self.zmarks) # can also plot the dropout criteria self.lcc = lcc.colorcrit() self.lcc = self.lcc(drop, droplabel) self.droplabel = droplabel
def __call__(self, simcatalog, bands=def_bands, key='Hua13', sn_lolim={ 'wfc3_f160w': 5.0, 'wfc3_f125w': 3.5, 'acs_f850lp': 2.0 }, sn_hilim={'acs_f435w': 2.0}, expand=[0., 0.]): ## Most stuff is the same as the 2D case: self.lcc = lcc.colorcrit() self.lcc = self.lcc('f775w_drop', key) c = Ftable(simcatalog) # Now initialize the attributes for b in bands: bs = filter_dic[b] # short name of filter b flux_iso = getattr(c, '%s_flux_iso' % bs) fluxerr_iso = getattr(c, '%s_fluxerr_iso' % bs) mag_iso = getattr(c, '%s_mag_iso' % bs) # calculate 1-sigma upper limits on sources with S/N < 1 mag_iso = N.where(flux_iso / fluxerr_iso > 1.0, mag_iso, zeropoints[b] - 2.5 * N.log10(fluxerr_iso)) setattr(self, b + '_mag', mag_iso) # MAG_ISO --> for color calculation setattr(self, b + '_flux', getattr(c, '%s_flux_auto' % bs)) # FLUX_AUTO setattr(self, b + '_flux_aper', getattr(c, '%s_flux_aper_2' % bs)) # Aperture flux within 0.18" aperture (2.94 pixels) setattr(self, b + '_fluxerr', getattr(c, '%s_fluxerr_auto' % bs)) # FLUXERR_AUTO setattr(self, b + '_fluxerr_aper', getattr(c, '%s_fluxerr_aper_2' % bs)) # Aperture flux errors within 0.18" aperture setattr( self, b + '_sn', getattr(self, '%s_flux' % b) / getattr(self, '%s_fluxerr' % b)) # S/N calculated using AUTO APERTURE setattr( self, b + '_sn_aper', getattr(self, '%s_flux_aper' % b) / getattr(self, '%s_fluxerr_aper' % b)) # S/N calculated using 0.18" APERTURE # Now construct S/N criteria #self.sncrit = N.ones(len(c.d),'bool') self.sn_lolim_crit = N.ones(len(c.d), 'bool') self.sn_hilim_crit = N.ones(len(c.d), 'bool') for b in sn_lolim.keys(): # enforce S/N lower limits self.sn_lolim_crit = self.sn_lolim_crit & \ (getattr(self,b+'_sn')>=sn_lolim[b]) for b in sn_hilim.keys(): # enforce S/N upper limits (veto bands) # but use fixed aperture S/N self.sn_hilim_crit = self.sn_hilim_crit & \ (getattr(self,b+'_sn_aper')<sn_hilim[b]) print "Total number of objects satisfying the S/N criteria:", \ sum((self.sn_hilim_crit)&(self.sn_lolim_crit)) self.sncrit = (self.sn_hilim_crit == True) & (self.sn_lolim_crit == True) print "Do selections..." self.color1 = self.acs_f775w_mag - self.acs_f850lp_mag self.color2 = self.acs_f850lp_mag - self.wfc3_f125w_mag self.lcc.select(self.color1, self.color2) # do color selection! self.colorcrit = self.lcc.crit.copy() self.lcc.crit = self.lcc.crit & self.sncrit # enforce S/N criteria self.dropcrit = self.lcc.crit & (c.detect == True) # just in case self.detect = c.detect.copy() print "Selection done." print "Total number of objects in the catalog: %d" % len(c.d) print "Total number selected as i-dropouts: %d" % (sum(self.dropcrit)) for M in self.M1500arr: # For each magnitude bin, calculate completeness P(z) bincrit = (c.m1500_in >= M) & (c.m1500_in < (M + self.dM)) z_in_bin = c.z_in[bincrit == True] z_in_bin_detect = c.z_in[(bincrit == True) & (c.detect == True)] zhist_bin_input = N.histogram(z_in_bin, self.zarr_edges)[0] zhist_bin_detect = N.histogram(z_in_bin_detect, self.zarr_edges)[0] self.zdist['%.1f'%M] = zhist_bin_detect.astype('float') / \ N.maximum(zhist_bin_input.astype('float'), 1.0) self.zdist['%.1f' % M] = self.zdist['%.1f' % M]
def __call__(self, simcatalog, field, plot_diag=False, ktest=None, bands=def_bands, key='Hua13', sn_lolim={ 'wfc3_f160w': 5.0, 'wfc3_f125w': 3.5, 'acs_f850lp': 2.0 }, sn_hilim={'acs_f435w': 2.0}, interpolate=False, dznew=0.1, expand=[0, 0]): """ simcatalog --- the simulation catalog as a FITS table. """ # Initialize i-dropout color criteria print "dznew=", dznew print "interpolate?", interpolate self.lcc = lcc.colorcrit() self.lcc = self.lcc('f775w_drop', key) c = Ftable(simcatalog) # Now initialize the attributes for b in bands: bs = filter_dic[b] # short name of filter b flux_iso = getattr(c, '%s_flux_iso' % bs) fluxerr_iso = getattr(c, '%s_fluxerr_iso' % bs) mag_iso = getattr(c, '%s_mag_iso' % bs) # calculate 1-sigma upper limits on sources with S/N < 1 mag_iso = N.where(flux_iso / fluxerr_iso > 1.0, mag_iso, zeropoints[b] - 2.5 * N.log10(fluxerr_iso)) setattr(self, b + '_mag', mag_iso) # MAG_ISO --> for color calculation setattr(self, b + '_flux', getattr(c, '%s_flux_auto' % bs)) # FLUX_AUTO setattr(self, b + '_flux_aper', getattr(c, '%s_flux_aper_2' % bs)) # Aperture flux within 0.18" aperture (2.94 pixels) setattr(self, b + '_fluxerr', getattr(c, '%s_fluxerr_auto' % bs)) # FLUXERR_AUTO setattr(self, b + '_fluxerr_aper', getattr(c, '%s_fluxerr_aper_2' % bs)) # Aperture flux errors within 0.18" aperture setattr( self, b + '_sn', getattr(self, '%s_flux' % b) / getattr(self, '%s_fluxerr' % b)) # S/N calculated using AUTO APERTURE setattr( self, b + '_sn_aper', getattr(self, '%s_flux_aper' % b) / getattr(self, '%s_fluxerr_aper' % b)) # S/N calculated using 0.18" APERTURE # Now construct S/N criteria #self.sncrit = N.ones(len(c.d),'bool') self.sn_lolim_crit = N.ones(len(c.d), 'bool') self.sn_hilim_crit = N.ones(len(c.d), 'bool') for b in sn_lolim.keys(): # enforce S/N lower limits self.sn_lolim_crit = self.sn_lolim_crit & \ (getattr(self,b+'_sn')>=sn_lolim[b]) for b in sn_hilim.keys(): # enforce S/N upper limits (veto bands) # but use fixed aperture S/N self.sn_hilim_crit = self.sn_hilim_crit & \ (getattr(self,b+'_sn_aper')<sn_hilim[b]) print "Total number of objects satisfying the S/N criteria:", \ sum((self.sn_hilim_crit)&(self.sn_lolim_crit)) self.sncrit = (self.sn_hilim_crit == True) & (self.sn_lolim_crit == True) print "Do selections..." self.color1 = self.acs_f775w_mag - self.acs_f850lp_mag self.color2 = self.acs_f850lp_mag - self.wfc3_f125w_mag self.lcc.select(self.color1, self.color2) # do color selection! self.colorcrit = self.lcc.crit.copy() self.lcc.crit = self.lcc.crit & self.sncrit # enforce S/N criteria self.dropcrit = self.lcc.crit & (c.detect == True) # just in case self.detect = c.detect.copy() print "Selection done." print "Total number of objects in the catalog: %d" % len(c.d) print "Total number selected as i-dropouts: %d" % (sum(self.dropcrit)) # Now invoke zdist.zdgrid.__call__ to calculate P(z) zdist.zdgrid.__call__(self, c, interpolate=interpolate, dznew=dznew, plot_diag=plot_diag, ktest=ktest, expand=expand)
def __call__(self, simcatalog, field, plot_diag=False, ktest=None, n_repeat=1, sn_lolim={ 'wfc3_f160w': 5.0, 'wfc3_f105w': 5.0, 'acs_f435w': 3.0 }, mode='ubvy', interpolate=False, dznew=0.1, redraw=False, drawnflux=None, testumag=False, testdraw=False, mag0=22.0, expand=[0., 0.], mag_in_col='m1500_in', re_in_col='re_in'): """ simcatalog --- the simulation catalog as a FITS table. Because the U-band magnitudes are randomly drawn from each object, we would like to repeat the magnitude drawing process for a few times to average out any statistical anomalies. mode --- the bands to use for selection (uby v.s. ubvy) """ # Initialize U-dropout color criteria print "n_repeat", n_repeat print "dznew", dznew print "interpolate?", interpolate print "Redraw?", redraw self.lcc = lcc.colorcrit() if mode == 'uby': if field == 'ers': self.lcc = self.lcc('uvimos_drop', 'UBY098') else: self.lcc = self.lcc('uvimos_drop', 'UBY105') elif mode == 'ubvy': if field == 'ers': self.lcc = self.lcc('uvimos_drop', 'UBVY098') else: self.lcc = self.lcc('uvimos_drop', 'UBVY105') c = Ftable(simcatalog) #self.c = c ## First: draw U-band magnitudes, and initialize correct attributes of c ## Tile the arrays by `n_repeat` times if field == 'ers': bands = ['acs_f435w', 'acs_f606w', 'wfc3_f098m', 'wfc3_f160w'] # HST bands only else: bands = ['acs_f435w', 'acs_f606w', 'wfc3_f105w', 'wfc3_f160w'] for b in bands: bs = filter_dic[b] # short name of filter b flux_iso = getattr(c, '%s_flux_iso' % bs) fluxerr_iso = getattr(c, '%s_fluxerr_iso' % bs) mag_iso = getattr(c, '%s_mag_iso' % bs) # calculate 1-sigma upper limits on sources with S/N < 1 mag_iso = N.where((flux_iso / fluxerr_iso) > 1.0, mag_iso, zeropoints[b] - 2.5 * N.log10(fluxerr_iso)) setattr(self, b + '_mag', N.tile(mag_iso, n_repeat)) # MAG_ISO --> for color calculation # setattr(self,b + '_flux', # N.tile(getattr(c, '%s_flux_auto'%bs),n_repeat)) setattr(self, b + '_flux', N.tile(getattr(c, '%s_flux_iso' % bs), n_repeat)) # FLUX_AUTO # setattr(self, b + '_fluxerr', # N.tile(getattr(c,'%s_fluxerr_auto'%bs),n_repeat)) setattr(self, b + '_fluxerr', N.tile(getattr(c, '%s_fluxerr_iso' % bs), n_repeat)) # FLUXERR_AUTO setattr( self, b + '_sn', getattr(self, '%s_flux' % b) / getattr(self, '%s_fluxerr' % b)) # S/N calculated using FLUX_ISO print "Step 1: draw U-band magnitudes and 1-sigma limits from files \ %s and %s" % (self.umag_kpdf, self.umag_1sig_kpdf) # Draw U-band magnitude # Calculate the fraction that have U-band S/N >= 1 if field == 'udf': cu = Ftable( '/Users/khuang/Dropbox/Research/bivariate/bivariate_fit/udrops_fitting/simcatalogs/run1_udf_130625.fits' ) umag_bins = N.arange(25., 38.5, 0.5) else: cu = Ftable( '/Users/khuang/Dropbox/Research/bivariate/bivariate_fit/udrops_fitting/simcatalogs/run2_tfitsim_130322.fits' ) umag_bins = N.arange(25., 38.5, 0.5) umag_in = cu.uvimos_mag_in[cu.uvimos_fitquerr > 0.] u_ston = (cu.uvimos_fitqty / cu.uvimos_fitquerr)[cu.uvimos_fitquerr > 0.] n1 = N.histogram(umag_in[u_ston >= 1.], umag_bins)[0] n2 = N.histogram(umag_in, umag_bins)[0] u_detect_frac = n1.astype('float') / N.maximum(1., n2.astype('float')) if testumag == False: # If not testing anything... if redraw == True: print "Repeat the drawing process %d times" % n_repeat self.vimos_u_mag = uu.draw_umag(N.tile(c.u_mag_in, n_repeat), self.umag_kpdf, mag0=mag0) self.vimos_u_mag_1sig = uu.draw_ulimmag( n_repeat * len(c.u_mag_in), self.umag_1sig_kpdf) # Draw 1-sigma magnitude upper limit # Now replace U-band magnitude with 1-sigma upper limit by using # the S/N > 1 fraction # index_detfrac = (c.u_mag_in - c.u_mag_in.min()) - (c.u_mag_in % 0.5) # index_detfrac = N.minimum(len(u_detect_frac)-1, index_detfrac) # detfrac = u_detect_frac.take(index_detfrac.astype('int')) # # Now randomly draws a reference level to compare with the detection # # fraction # rdn_level = N.random.uniform(0., 1., size=len(c.d)) # self.vimos_u_mag = N.where(detfrac>=rdn_level, self.vimos_u_mag, # self.vimos_u_mag_1sig) self.vimos_u_mag = N.minimum(self.vimos_u_mag, self.vimos_u_mag_1sig) else: print "Read U-band magnitudes from %s." % drawnflux # Read the drawn U-band magnitudes from file drawnflux df = cPickle.load(open(drawnflux)) self.vimos_u_mag_1sig = df.vimos_u_mag_1sig self.vimos_u_mag = df.vimos_u_mag else: self.vimos_u_mag = c.u_mag_in self.vimos_u_mag_1sig = c.u_mag_in # Now construct S/N criteria #self.sncrit = N.ones(len(c.d)*n_repeat,'bool') self.sn_lolim_crit = N.ones(len(c.d) * n_repeat, 'bool') self.detect = c.detect.copy() #print len(self.sncrit), len(self.acs_f435w_sn) if len(sn_lolim.keys()) > 0: print "sn_lolim", sn_lolim for b in sn_lolim.keys(): self.sn_lolim_crit = self.sn_lolim_crit & \ (getattr(self,b+'_sn')>=sn_lolim[b]) #self.sncrit = self.sncrit & (getattr(self,'%s_sn'%b)>=sn_lolim[b]) self.sncrit = (self.sn_lolim_crit == True) ## Second: calculate dropcrit (do color selection) #import select_udrops_uby as suu print "Do selections..." if field == 'ers': self.color1 = self.vimos_u_mag - self.acs_f435w_mag if mode == 'uby': self.color2 = self.acs_f435w_mag - self.wfc3_f098m_mag elif mode == 'ubvy': self.color2 = self.acs_f606w_mag - self.wfc3_f098m_mag self.lcc.select(self.color1, self.color2) else: self.color1 = self.vimos_u_mag - self.acs_f435w_mag if mode == 'uby': self.color2 = self.acs_f435w_mag - self.wfc3_f105w_mag elif mode == 'ubvy': self.color2 = self.acs_f606w_mag - self.wfc3_f105w_mag self.lcc.select(self.color1, self.color2) self.colorcrit = self.lcc.crit.copy() self.lcc.crit = self.lcc.crit & self.sncrit # Fold in S/N criteria #if field=='ers': # self.udrops = suu.udrops_ubvy098(self.c, # bands=['acs_f435w','acs_f606w','wfc3_f098m','wfc3_f160w'], # sn_lolim={'wfc3_f160w':5.0,'acs_f435w':3.0,'wfc3_f098m':5.0}) #else: # self.udrops = suu.udrops_ubvy105(self.c, # bands=['acs_f435w','acs_f606w','wfc3_f105w','wfc3_f160w'], # sn_lolim={'wfc3_f160w':5.0,'acs_f435w':3.0,'wfc3_f105w':5.0}) #dropcrit = self.udrops.crit # the dropout-selection array dropcrit = self.lcc.crit & (N.tile(c.detect, n_repeat) == True) #self.dropcrit = dropcrit[:len(c.d)] self.dropcrit = dropcrit self.detect = c.detect.copy() print "Selections done." print "Total number of objects in the catalog: %d" % len(c.d) print "Total number selected as U-dropouts: %d" % (sum(dropcrit) / float(n_repeat)) ## Third: call make_Pz to calculate P(z) if not testdraw: # Now invoke zdist.zdgrid.__call__ to calculate P(z) zdist.zdgrid.__call__(self, c, interpolate=interpolate, dznew=dznew, plot_diag=plot_diag, ktest=ktest, n_repeat=n_repeat, expand=expand, mag_in_col=mag_in_col, re_in_col=re_in_col) if self.n_repeat > 30: delattr(self, 'color1') delattr(self, 'color2') delattr(self, 'sncrit')