Пример #1
0
def create_zdist_bright():
    zphot_0 = \
            read_shear_catalog(BRIGHT_CAT_NPZ,
                               ('zphot',),
                               None,
                               remove_z_problem = False)
    zphot_1 = \
            read_shear_catalog(BRIGHT_CAT_NPZ,
                               ('zphot',),
                               None,
                               remove_z_problem = True)

    z = np.arange(0, 5, 0.01)

    i0 = z.searchsorted(zphot_0[0])
    i1 = z.searchsorted(zphot_1[0])

    OF_0 = open(BRIGHT_ZDIST, 'w')
    OF_1 = open(BRIGHT_ZDIST_ZPROB0, 'w')

    for i in range(len(z)):
        OF_0.write('%.6f %.6g\n' % (z[i], len(np.where(i0==i)[0])))
        OF_1.write('%.6f %.6g\n' % (z[i], len(np.where(i1==i)[0])))

    OF_0.close()
    OF_1.close()
Пример #2
0
def create_zdist_bright():
    zphot_0 = \
            read_shear_catalog(BRIGHT_CAT_NPZ,
                               ('zphot',),
                               None,
                               remove_z_problem = False)
    zphot_1 = \
            read_shear_catalog(BRIGHT_CAT_NPZ,
                               ('zphot',),
                               None,
                               remove_z_problem = True)

    z = np.arange(0, 5, 0.01)

    i0 = z.searchsorted(zphot_0[0])
    i1 = z.searchsorted(zphot_1[0])

    OF_0 = open(BRIGHT_ZDIST, 'w')
    OF_1 = open(BRIGHT_ZDIST_ZPROB0, 'w')

    for i in range(len(z)):
        OF_0.write('%.6f %.6g\n' % (z[i], len(np.where(i0 == i)[0])))
        OF_1.write('%.6f %.6g\n' % (z[i], len(np.where(i1 == i)[0])))

    OF_0.close()
    OF_1.close()
Пример #3
0
def fit_zdist(catalog_file, nbins=100, plot=True):
    """
    using a COSMOS catalog, return (z0, a, b) such that the distribution
    n(z) ~ z^a * exp[-(z/z0)^b]
    best describes the observed redshift distribution.

    nbins gives the number of bins at which the function should be evaluated.
    """
    z = read_shear_catalog(catalog_file, ['zphot'], remove_z_problem=True)[0]

    N, bins = np.histogram(z, nbins)

    bincenters = 0.5*( bins[1:] + bins[:-1])
    N = N * 1./N.sum()

    x0 = [0.5, 2.0, 1.5]

    ret = optimize.fmin(minfunc, x0, (N, bincenters))

    z0, a, b = ret

    if plot:
        pylab.plot(bincenters, N)
        zp = bincenters#np.linspace(z.min(), z.max(), 1000)
        nz = zp**a * np.exp(-(zp/z0)**b)
        nz /= np.sum(nz)
        pylab.plot(zp, nz)

    return ret
Пример #4
0
def plot_distribution(filename):
    RA,DEC = read_shear_catalog(filename,('Ra','Dec'),None)

    RAmin,RAmax = min(RA), max(RA)
    DECmin,DECmax = min(DEC),max(DEC)
    
    xmin = np.floor(RAmin*60.)
    xmax = np.ceil(RAmax*60.)
    
    ymin = np.floor(DECmin*60.)
    ymax = np.ceil(DECmax*60.)
    
    xrange = np.arange(xmin,xmax+1)/60.
    yrange = np.arange(ymin,ymax+1)/60.
    
    H,xedges,yedges = np.histogram2d(RA,DEC,bins=(xrange,yrange))
    
    pylab.imshow(H.T,
                 origin='lower',
                 interpolation='nearest',
                 extent = (xrange[0],xrange[-1],yrange[0],yrange[-1]),
                 cmap=pylab.cm.binary)
    pylab.colorbar().set_label(r'$\mathdefault{n_{gal}\ (arcmin^{-2})}$')
    pylab.xlabel('RA (deg)')
    pylab.ylabel('DEC (deg)')

    return len(RA)
Пример #5
0
def bootstrap_catalog(catalog_file,
                      N_bootstraps,
                      dtheta,
                      RAmin=None,
                      DECmin=None,
                      NRA=None,
                      NDEC=None):
    """
    Estimate shear uncertainty using a bootstrap resampling of shear
    data in the catalog.

    Parameters
    ----------
    catalog_file : file of COSMOS shear catalog
    N_bootstraps : number of resamplings to use
    dtheta : pixel size in arcmin

    Other Parameters
    ----------------
    If these are unspecified, they will be determined from the data
    RAmin : minimum of RA bins (degrees).
    NRA : number of RA bins
    DECmin : minimum of DEC bins (degrees)
    NDEC : number of DEC bins

    Returns
    -------
    (Ngal, dgamma2)
    Ngal : array[int], shape = (NRA, NDEC)
        number of galaxies in each shear bin
    dgamma2 : array[float], shape = (NRA, NDEC)
        estimated squared shear error in each shear bin
    """
    RA, DEC, gamma1, gamma2 = read_shear_catalog(
        catalog_file,
        ('Ra', 'Dec', 'e1iso_rot4_gr_snCal', 'e2iso_rot4_gr_snCal'), None)

    gamma = gamma1 - 1j * gamma2

    if RAmin is None:
        RAmin = RA.min()
    if DECmin is None:
        DECmin = DEC.min()

    if NRA is None:
        NRA = int(np.ceil((RA.max() - RAmin + 1E-8) * 60. / dtheta))
    if NDEC is None:
        NDEC = int(np.ceil((DEC.max() - DECmin + 1E-8) * 60. / dtheta))

    return bootstrap_resample(gamma, RA, DEC, RAmin, dtheta / 60., NRA, DECmin,
                              dtheta / 60., NDEC, N_bootstraps)
Пример #6
0
def bootstrap_catalog(catalog_file, N_bootstraps, dtheta,
                      RAmin = None, DECmin = None,
                      NRA = None, NDEC = None):
    """
    Estimate shear uncertainty using a bootstrap resampling of shear
    data in the catalog.

    Parameters
    ----------
    catalog_file : file of COSMOS shear catalog
    N_bootstraps : number of resamplings to use
    dtheta : pixel size in arcmin

    Other Parameters
    ----------------
    If these are unspecified, they will be determined from the data
    RAmin : minimum of RA bins (degrees).
    NRA : number of RA bins
    DECmin : minimum of DEC bins (degrees)
    NDEC : number of DEC bins

    Returns
    -------
    (Ngal, dgamma2)
    Ngal : array[int], shape = (NRA, NDEC)
        number of galaxies in each shear bin
    dgamma2 : array[float], shape = (NRA, NDEC)
        estimated squared shear error in each shear bin
    """
    RA, DEC, gamma1, gamma2 = read_shear_catalog(catalog_file,
                                                 ('Ra', 'Dec',
                                                  'e1iso_rot4_gr_snCal',
                                                  'e2iso_rot4_gr_snCal'),
                                                 None)

    gamma = gamma1 - 1j*gamma2

    if RAmin is None:
        RAmin = RA.min()
    if DECmin is None:
        DECmin = DEC.min()

    if NRA is None:
        NRA = int(np.ceil((RA.max() - RAmin + 1E-8) * 60. / dtheta))
    if NDEC is None:
        NDEC = int(np.ceil((DEC.max() - DECmin + 1E-8) * 60. / dtheta))

    return bootstrap_resample(gamma, RA, DEC,
                              RAmin, dtheta/60., NRA,
                              DECmin, dtheta/60., NDEC,
                              N_bootstraps)
Пример #7
0
def shear_mask_vector(catalog_file, dtheta,
                      RAmin = None, DECmin = None,
                      NRA = None, NDEC = None):
    """
    return the mask vector for a 2D shear field.

    Parameters
    ----------
    catalog_file : file of COSMOS shear catalog
    dtheta : pixel size in arcmin

    Other Parameters
    ----------------
    If these are unspecified, they will be determined from the data
    RAmin : minimum of RA bins (degrees).
    NRA : number of RA bins
    DECmin : minimum of DEC bins (degrees)
    NDEC : number of DEC bins

    Returns
    -------
    (Ngal, RArange, DECrange)
    Ngal : array, shape = (NRA, NDEC)
        number of galaxies in each bin
    RArange : array, shape = (NRA + 1,)
        edges of bins in RA
    DECrange : array, shape = (NDEC + 1,)
        edges of bins in DEC
    """
    RA, DEC = read_shear_catalog(catalog_file, ('Ra', 'Dec'), None)

    if RAmin is None:
        RAmin = RA.min()
    if DECmin is None:
        DECmin = DEC.min()

    if NRA is None:
        NRA = int(np.ceil((RA.max() - RAmin + 1E-8) * 60. / dtheta))
    if NDEC is None:
        NDEC = int(np.ceil((DEC.max() - DECmin + 1E-8) * 60. / dtheta))

    RArange = RAmin + (dtheta / 60.) * np.arange(NRA + 1)
    DECrange = DECmin + (dtheta / 60.) * np.arange(NDEC + 1)

    Ngal, xedges, yedges = np.histogram2d(RA, DEC, bins=(RArange, DECrange))

    return Ngal, xedges, yedges
Пример #8
0
def plot_redshift_distribution(catalog_file, nbins=100, z0=0.5, a=2.0, b=1.5):
    z = read_shear_catalog(catalog_file, ['zphot'], remove_z_problem=True)[0]

    N, bins = np.histogram(z, nbins)
    print N
    
    zmid = 0.5*( bins[1:] + bins[:-1])
    N = N * 1./N.sum()

    nz = zmid**a * np.exp(-(zmid/z0)**b)

    nz /= nz.sum()

    pylab.subplot(211)
    pylab.plot(zmid, N)
    pylab.subplot(212)
    pylab.plot(zmid, nz)
Пример #9
0
def plot_Map(filename, dpix=1.0):
    RA, DEC, gamma1, gamma2 = read_shear_catalog(filename,
                                                 ('Ra','Dec',
                                                  'e1iso_rot4_gr_snCal',
                                                  'e2iso_rot4_gr_snCal'),
                                                 None)
    RAmin, RAmax = min(RA), max(RA)
    DECmin, DECmax = min(DEC), max(DEC)

    dpix_deg = dpix/60.

    pos = RA + 1j*DEC
    gamma = gamma1 + 1j*gamma2

    RA_out = np.arange(RAmin,RAmax+dpix_deg,dpix_deg)
    DEC_out = np.arange(DECmin,DECmax+dpix_deg,dpix_deg)

    RA_out,DEC_out = np.meshgrid(RA_out,DEC_out)

    pos_out = RA_out + 1j*DEC_out
    
    shape = pos_out.shape

    Map = Aperture_Mass(gamma, pos, pos_out.reshape(-1))

    Map = Map.reshape(shape)

    pylab.figure()
    pylab.imshow(Map.real.T,
                 origin='lower')
    pylab.colorbar()

    pylab.figure()
    pylab.imshow(Map.imag.T,
                 origin='lower')
    pylab.colorbar()
Пример #10
0
def plot_shear(filename, dpix=1.0):
    """
    dpix is pixel size in arcmin
    """
    RA, DEC, gamma1, gamma2 = read_shear_catalog(filename,
                                                 ('Ra','Dec',
                                                  'e1iso_rot4_gr_snCal',
                                                  'e2iso_rot4_gr_snCal'),
                                                 None)
    Ngal = len(RA)

    #bin data into pixels
    RAmin, RAmax = min(RA), max(RA)
    DECmin, DECmax = min(DEC), max(DEC)
    
    i = np.floor( (RA-RAmin)*60./dpix ).astype(int)
    j = np.floor( (DEC-DECmin)*60./dpix ).astype(int)

    Nx = np.max(i)+1
    Ny = np.max(j)+1

    print Nx,Ny

    gamma = np.zeros((Nx,Ny), dtype=complex)
    ngal  = np.zeros((Nx,Ny), dtype=int)

    for ind in xrange(Ngal):
        gamma[i[ind], j[ind]] += gamma1[ind] - 1j*gamma2[ind]
        ngal[i[ind], j[ind]] += 1

    izero = np.where(ngal==0)
    ngal[izero] = 1
    gamma /= ngal
    ngal[izero] = 0

    kappa = gamma_to_kappa(gamma,dpix)

    extent = (-0.5*dpix, (Nx-0.5)*dpix,
               -0.5*dpix, (Ny-0.5)*dpix)

    pylab.figure()
    pylab.imshow(ngal.T, origin='lower', extent=extent, interpolation='nearest')
    pylab.colorbar().set_label(r'$\mathdefault{n_{gal} (per pixel)}$')
    whiskerplot(gamma, dpix, dpix)
    pylab.axis(extent)

    pylab.figure()
    pylab.imshow(kappa.real.T, origin='lower', 
                 extent=extent)
    cb1 = pylab.colorbar()
    clim = cb1.get_clim()
    pylab.title('kappa: E-mode')
    pylab.axis(extent)

    pylab.figure()
    pylab.imshow(kappa.imag.T, origin='lower', 
                 extent=extent)
    cb2 = pylab.colorbar()
    cb2.set_clim(clim)
    pylab.title('kappa: B-mode')
    pylab.axis(extent)
Пример #11
0
def get_gamma_vector(catalog_file, dtheta,
                     RAmin = None, DECmin = None,
                     NRA = None, NDEC = None,
                     remove_z_problem = True,
                     N_bootstraps=0):
    """
    return the mask vector for a 2D shear field.

    Parameters
    ----------
    catalog_file : file of COSMOS shear catalog or list of files
                
    dtheta : pixel size in arcmin

    Other Parameters
    ----------------
    If these are unspecified, they will be determined from the data
    RAmin : minimum of RA bins (degrees).
    NRA : number of RA bins
    DECmin : minimum of DEC bins (degrees)
    NDEC : number of DEC bins
    N_bootstraps : number of bootstraps to perform.
        If zero, don't return noise

    Returns
    -------
    (gamma, Ngal, RArange, DECrange)
    gamma : array[complex], shape = (NRA, NDEC)
        average shear within each bin
    Ngal : array[integer], shape = (NRA, NDEC)
        number of galaxies in each bin
    RArange : array[float], shape = (NRA + 1,)
        edges of bins in RA
    DECrange : array[float], shape = (NDEC + 1,)
        edges of bins in DEC
    """
    RA, DEC, gamma1, gamma2 = \
        read_shear_catalog(catalog_file,
                           ('Ra', 'Dec',
                            'e1iso_rot4_gr_snCal',
                            'e2iso_rot4_gr_snCal'),
                           None,
                           remove_z_problem)

    if RAmin is None:
        RAmin = RA.min()
    if DECmin is None:
        DECmin = DEC.min()

    if NRA is None:
        NRA = int(np.ceil((RA.max() - RAmin + 1E-8) * 60. / dtheta))
    if NDEC is None:
        NDEC = int(np.ceil((DEC.max() - DECmin + 1E-8) * 60. / dtheta))

    RArange = RAmin + (dtheta / 60.) * np.arange(NRA + 1)
    DECrange = DECmin + (dtheta / 60.) * np.arange(NDEC + 1)

    gamma = gamma1 - 1j*gamma2

    gamma_mean, Ngal_bins, d2gamma, sigma_estimate = bootstrap_resample(
        gamma, RA, DEC,
        RAmin, dtheta/60., NRA,
        DECmin, dtheta/60., NDEC, N_bootstraps)

    if N_bootstraps > 0:
        return gamma_mean, Ngal_bins, d2gamma, RArange, DECrange
    else:
        return gamma_mean, Ngal_bins, RArange, DECrange