예제 #1
0
def flux_err_method(ra, dec, band, flux_err, flatSkyGrid, SNRthreshold=5):
    # 5sigma Magnitude limit= average of 5*flux_err for all objs in each pixel (and then transformed to magnitude)
    # SNRthreshold= 5 => 5sigma depth.

    # Since want mags (mean, std) at the end, need to first run the createMeanStdMaps with
    # 5flux_error to get the mean flux map which can be converted to fluxea.
    # To get std mags, need to run createMeanStdMaps with 5*flux_error converted to mags and keep only the std.

    depth, dontcare = createMeanStdMaps(ra,
                                        dec,
                                        quantity=SNRthreshold * flux_err,
                                        flatSkyGrid=flatSkyGrid,
                                        plotMaps=False)

    # convert from fluxes to mags
    depth = 10.**(23 + 6) * depth
    depth[~np.isnan(depth)] = -2.5 * np.log10(depth[~np.isnan(depth)]) + 23.9

    # find the std.
    quantity = 10.**(23 + 6) * SNRthreshold * flux_err
    quanity = -2.5 * np.log10(quantity) + 23.9
    dontcare, depth_std = createMeanStdMaps(ra,
                                            dec,
                                            quantity=quantity,
                                            flatSkyGrid=flatSkyGrid)

    #Zeros in empty pixels
    nc = createCountsMap(ra, dec, flatSkyGrid)
    depth[nc < 1] = 0
    depth_std[nc < 1] = 0

    return depth, depth_std
예제 #2
0
def createMask(ra,dec,flags,flatsky_base,reso_mask) :
    """
    Creates a mask based on the position of random objects and a set of flags.
    ra,dec : angular coordinates of the random objects
    flags : list of arrays containing the flags used to mask areas of the sky.
            pixels containing objects with any flags=True will be masked.
            Pass [] if you just want to define a mask based on object positions.
    flatsky_base : FlatMapInfo for the base mask, defined by the presence of not
                   of object in pixels defined by this FlatMapInfo
    reso_mask : resolution of the final mask (dx or dy)
    returns mask and associated FlatMapInfo
    """
    fsg0=flatsky_base

    #Create mask based on object positions
    mpr=createCountsMap(ra,dec,fsg0,returnMap=True,plotMap=False)
    mskr=np.zeros(fsg0.get_size()); mskr[mpr>0]=1

    if(np.sum(mpr*mskr)/np.sum(mskr)<5) :
        raise Warning('Base resolution may be too high %.1lf'%(np.sum(mpr*mskr)/np.sum(mskr)))

    if np.fabs(reso_mask)>np.fabs(fsg0.dx) :
        fsg,mpn=fsg0.d_grade(mpr,int(np.fabs(reso_mask/fsg0.dx)+0.5))
    else :
        fsg,mpn=fsg0.u_grade(mpr,int(np.fabs(fsg0.dx/reso_mask)+0.5))

    mskn=np.zeros(fsg.get_size()); mskn[mpn>0]=1
    ipix=fsg.pos2pix(ra,dec)
    for flag in flags :
        ipixmask=ipix[flag]
        p=np.unique(ipixmask)
        mskn[p]=0

    #Classify all connected regions
    msk2d=mskn.astype(int).reshape([fsg.ny,fsg.nx])
    labeled_array,num_features=label(msk2d)
    #Identify largest connected region (0 is background)
    i0=np.argmax(np.histogram(labeled_array,bins=num_features+1,range=[-0.5,num_features+0.5])[0][1:])+1
    #Remove all other regions
    mask_clean=labeled_array.copy().flatten()
    mask_clean[mask_clean!=i0]=0
    msk_out=mask_clean.astype(float)
    
    return msk_out,fsg
        bincosmosz = weights_file[msk_cosmos]['cosmos_photoz']
        hz, bz = np.histogram(bincosmosz,
                              bins=o.nz_bin_num,
                              range=[0., o.nz_bin_max],
                              weights=binweights)
        hnz, bnz = np.histogram(bincosmosz,
                                bins=o.nz_bin_num,
                                range=[0., o.nz_bin_max])
        ehz = np.zeros(len(hnz))
        ehz[hnz > 0] = (hz[hnz > 0] + 0.) / np.sqrt(hnz[hnz > 0] + 0.)
    else:
        zmcs = subcat[column_zmc]
        hz, bz = np.histogram(zmcs,
                              bins=o.nz_bin_num,
                              range=[0., o.nz_bin_max])
    nmap = createCountsMap(subcat['ra'], subcat['dec'], fsk)
    if o.use_cosmos:
        nzs.append([bz[:-1], bz[1:], hz + 0., ehz])
    else:
        nzs.append([bz[:-1], bz[1:], hz + 0.])
    maps.append(nmap)
nzs = np.array(nzs)
maps = np.array(maps)

#Save maps and N(z)s
if len(maps[0]) != fsk.npix:
    raise ValueError("Map doesn't conform to this pixelization")

header = fsk.wcs.to_header()
hdus = []
for im, m in enumerate(maps):
예제 #4
0
systdesc['dust']=np.array(dustdesc)

# 2- Nstar
#    This needs to be done for stars passing the same cuts as the sample (except for the s/g separator)
sel_maglim=np.ones(len(cat),dtype=bool); sel_maglim[cat['%scmodel_mag'%o.band]-cat['a_%s'%o.band]>o.depth_cut]=0
sel_blended=np.ones(len(cat),dtype=bool); sel_blended[cat['iblendedness_abs_flux']>=0.42169650342]=0 #abs_flux<10^-0.375
sel_fluxcut_i=np.ones(len(cat),dtype=bool); sel_fluxcut_i[cat['icmodel_flux']<10*cat['icmodel_flux_err']]=0
sel_fluxcut_g=np.ones(len(cat),dtype=int); sel_fluxcut_i[cat['gcmodel_flux']<5*cat['gcmodel_flux_err']]=0
sel_fluxcut_r=np.ones(len(cat),dtype=int); sel_fluxcut_i[cat['rcmodel_flux']<5*cat['rcmodel_flux_err']]=0
sel_fluxcut_z=np.ones(len(cat),dtype=int); sel_fluxcut_i[cat['zcmodel_flux']<5*cat['zcmodel_flux_err']]=0
sel_fluxcut_y=np.ones(len(cat),dtype=int); sel_fluxcut_i[cat['ycmodel_flux']<5*cat['ycmodel_flux_err']]=0
sel_fluxcut_grzy=(sel_fluxcut_g+sel_fluxcut_r+sel_fluxcut_z+sel_fluxcut_y>=2)
sel_fluxcut=sel_fluxcut_i*sel_fluxcut_grzy
sel_stars=np.ones(len(cat),dtype=bool);  sel_stars[cat['iclassification_extendedness']>0.99]=0
sel_gals =np.ones(len(cat),dtype=bool);  sel_gals[cat['iclassification_extendedness']<0.99]=0
mstar=createCountsMap(cat['ra'][sel_maglim*sel_stars*sel_fluxcut*sel_blended],
                      cat['dec'][sel_maglim*sel_stars*sel_fluxcut*sel_blended],fsk)+0.
if o.gen_plot :
  fsk.view_map(mstar,posColorbar=True,title='N_star',xlabel='ra',ylabel='dec',
               fnameOut=o.out_prefix+'_nstar_'+o.band+'%.2lf.png'%(o.depth_cut))
syst['nstar_'+o.band+'%.2lf'%(o.depth_cut)]=mstar
systdesc['nstar_'+o.band+'%.2lf'%(o.depth_cut)]='Stars, '+o.band+'<%.2lf'%(o.depth_cut)
if o.sv_syst :
   for k in syst.keys() :
     fsk.write_flat_map(o.out_prefix+'_syst_'+k+'.fits',syst[k],descript=systdesc[k])

####
# Generate bright-object mask
#Binary BO mask
mask_bo,fsg=createMask(cat['ra'],cat['dec'],
                       [cat['iflags_pixel_bright_object_center'],
                        cat['iflags_pixel_bright_object_any']],
예제 #5
0
    #Read systematics maps
    fskb,mp_dust=fm.read_flat_map(predir+field+'/'+field+"_syst_dust.fits",2)
    if fsk.get_dims()!=fskb.get_dims() :
        raise ValueError("Inconsistent fskys")
    fskb,mp_star=fm.read_flat_map(predir+field+'/'+field+"_syst_nstar_i%.2lf.fits"%mlim)
    if fsk.get_dims()!=fskb.get_dims() :
        raise ValueError("Inconsistent fskys")

    #Read catalog and cut based on BO mask
    cat=fits.open(predir+field+"/"+field+'_Catalog_i%.2lf.fits'%mlim)[1].data
    mskob=(~cat['iflags_pixel_bright_object_center'])*(~cat['iflags_pixel_bright_object_any'])
    cat=cat[mskob]

    #Compute ndens map
    nmap=createCountsMap(cat['ra'],cat['dec'],fsk)
    ndens=np.sum(nmap*msk_t)/np.sum(mskfrac*msk_t)
    delta=np.zeros_like(weight)
    delta[goodpix]=nmap[goodpix]/(ndens*mskfrac[goodpix])-1

    #fsk.view_map(mp_depth,title='Depth '+field,colorMin=24)
    #fsk.view_map(mp_dust*weight,title='Dust '+field)
    #fsk.view_map(mp_star*weight,title='$n_{\\rm star}$ '+field)
    #mpp=delta*weight
    #mpp[weight<=0]=-100
    #fsk.view_map(mpp,title='$\\delta_g$ '+field,colorMin=-1,colorMax=2,
    #             xlabel='R.A.',ylabel='dec',fnameOut=field+"_dg.png",addColorbar=False)
    #plt.show()

    #Compute power spectra
    cl_raw,bpws,wsp=fsk.compute_power_spectrum(delta,weight,return_bpw=True,return_wsp=True)