Exemple #1
0
def partial_profile(backcat_ids,RA0,DEC0,Z,
                    RIN,ROUT,ndots,h,nboot=100):

        cosmo = LambdaCDM(H0=100*h, Om0=0.3, Ode0=0.7)
        
        backcat = S.data.loc[backcat_ids]
        
        ndots = int(ndots)
               
        if 'KiDS' in np.array(backcat.CATNAME)[0]:
                mask = (backcat.Z_B > (Z + 0.1))*(backcat.ODDS >= 0.5)*(backcat.Z_B < 0.9)*(backcat.Z_B > 0.2)
        else:
                mask = (backcat.Z_B > (Z + 0.1))*(backcat.ODDS >= 0.5)*(backcat.Z_B > 0.2)
        
        catdata = backcat[mask]


        dl, ds, dls = gentools.compute_lensing_distances(np.array([Z]), catdata.Z_B, precomputed=True)
        dl  = (dl*0.7)/h
        ds  = (ds*0.7)/h
        dls = (dls*0.7)/h
        
        KPCSCALE   = dl*(((1.0/3600.0)*np.pi)/180.0)*1000.0
        BETA_array = dls/ds
        
        Dl = dl*1.e6*pc
        sigma_c = (((cvel**2.0)/(4.0*np.pi*G*Dl))*(1./BETA_array))*(pc**2/Msun)



        rads, theta, test1,test2 = eq2p2(np.deg2rad(catdata.RAJ2000),
                                        np.deg2rad(catdata.DECJ2000),
                                        np.deg2rad(RA0),
                                        np.deg2rad(DEC0))
               
        #Correct polar angle for e1, e2
        theta = theta+np.pi/2.
        
        e1     = catdata.e1
        e2     = catdata.e2
        
        
        
        #get tangential ellipticities 
        et = (-e1*np.cos(2*theta)-e2*np.sin(2*theta))*sigma_c
        #get cross ellipticities
        ex = (-e1*np.sin(2*theta)+e2*np.cos(2*theta))*sigma_c
        
        del(e1)
        del(e2)
        
        r=np.rad2deg(rads)*3600*KPCSCALE
        del(rads)
        
        peso = catdata.weight
        peso = peso/(sigma_c**2) 
        m    = catdata.m
        
        Ntot = len(catdata)
        del(catdata)    
        
        bines = np.logspace(np.log10(RIN),np.log10(ROUT),num=ndots+1)
        dig = np.digitize(r,bines)
        
        DSIGMAwsum_T = []
        DSIGMAwsum_X = []
        WEIGHTsum    = []
        Mwsum        = []
        BOOTwsum_T   = np.zeros((nboot,ndots))
        BOOTwsum_X   = np.zeros((nboot,ndots))
        BOOTwsum     = np.zeros((nboot,ndots))
        NGAL         = []
        
        
        for nbin in range(ndots):
                mbin = dig == nbin+1              
                
                DSIGMAwsum_T = np.append(DSIGMAwsum_T,(et[mbin]*peso[mbin]).sum())
                DSIGMAwsum_X = np.append(DSIGMAwsum_X,(ex[mbin]*peso[mbin]).sum())
                WEIGHTsum    = np.append(WEIGHTsum,(peso[mbin]).sum())
                Mwsum        = np.append(Mwsum,(m[mbin]*peso[mbin]).sum())
                NGAL         = np.append(NGAL,mbin.sum())
                
                index = np.arange(mbin.sum())
                if mbin.sum() == 0:
                        continue
                else:
                        with NumpyRNGContext(1):
                                bootresult = bootstrap(index, nboot)
                        INDEX=bootresult.astype(int)
                        BOOTwsum_T[:,nbin] = np.sum(np.array(et[mbin]*peso[mbin])[INDEX],axis=1)
                        BOOTwsum_X[:,nbin] = np.sum(np.array(ex[mbin]*peso[mbin])[INDEX],axis=1)
                        BOOTwsum[:,nbin]   = np.sum(np.array(peso[mbin])[INDEX],axis=1)
        
        output = {'DSIGMAwsum_T':DSIGMAwsum_T,'DSIGMAwsum_X':DSIGMAwsum_X,
                   'WEIGHTsum':WEIGHTsum, 'Mwsum':Mwsum, 
                   'BOOTwsum_T':BOOTwsum_T, 'BOOTwsum_X':BOOTwsum_X, 'BOOTwsum':BOOTwsum, 
                   'Ntot':Ntot,'NGAL':NGAL}
        
        return output
def partial_profile(backcat_ids,
                    RA0,
                    DEC0,
                    Z,
                    pangle,
                    RIN,
                    ROUT,
                    ndots,
                    nboot=100):

    backcat = S.data.loc[backcat_ids]

    ndots = int(ndots)

    mask = backcat.Z_B > (Z + 0.1)

    catdata = backcat[mask]

    dl, ds, dls = gentools.compute_lensing_distances(np.array([Z]),
                                                     catdata.Z_B,
                                                     precomputed=True)
    # dl, ds, dls = gentools.compute_lensing_distances(Z, catdata.Z_B, precomputed=True)

    KPCSCALE = dl * (((1.0 / 3600.0) * np.pi) / 180.0) * 1000.0
    BETA_array = dls / ds

    Dl = dl * 1.e6 * pc
    sigma_c = (((cvel**2.0) / (4.0 * np.pi * G * Dl)) *
               (1. / BETA_array)) * (pc**2 / Msun)

    rads, theta, test1, test2 = eq2p2(np.deg2rad(catdata.RAJ2000),
                                      np.deg2rad(catdata.DECJ2000),
                                      np.deg2rad(RA0), np.deg2rad(DEC0))

    theta2 = (2. * np.pi - theta) + np.pi / 2.
    theta_ra = theta2
    theta_ra[theta2 > 2. * np.pi] = theta2[theta2 > 2. * np.pi] - 2. * np.pi

    #Correct polar angle for e1, e2
    theta = theta + np.pi / 2.

    e1 = catdata.e1
    e2 = catdata.e2

    #get tangential ellipticities
    et = (-e1 * np.cos(2 * theta) - e2 * np.sin(2 * theta)) * sigma_c
    #get cross ellipticities
    ex = (-e1 * np.sin(2 * theta) + e2 * np.cos(2 * theta)) * sigma_c

    del (e1)
    del (e2)

    r = np.rad2deg(rads) * 3600 * KPCSCALE
    del (rads)

    peso = catdata.weight
    peso = peso / (sigma_c**2)
    m = catdata.m

    Ntot = len(catdata)
    del (catdata)

    bines = np.logspace(np.log10(RIN), np.log10(ROUT), num=ndots + 1)
    dig = np.digitize(r, bines)

    at = theta_ra - pangle

    DSIGMAwsum_T = []
    DSIGMAwsum_X = []
    WEIGHTsum = []
    Mwsum = []

    BOOTwsum_T = np.zeros((nboot, ndots))
    BOOTwsum_X = np.zeros((nboot, ndots))
    BOOTwsum = np.zeros((nboot, ndots))

    GAMMATcos_wsum = []
    GAMMAXsin_wsum = []
    WEIGHTcos_sum = []
    WEIGHTsin_sum = []

    BOOTwsum_Tcos = np.zeros((nboot, ndots))
    BOOTwsum_Xsin = np.zeros((nboot, ndots))
    BOOTwsum_cos = np.zeros((nboot, ndots))
    BOOTwsum_sin = np.zeros((nboot, ndots))

    GAMMATcos_wsum_c = []
    GAMMAXsin_wsum_c = []
    WEIGHTcos_sum_c = []
    WEIGHTsin_sum_c = []

    BOOTwsum_Tcos_c = np.zeros((nboot, ndots))
    BOOTwsum_Xsin_c = np.zeros((nboot, ndots))
    BOOTwsum_cos_c = np.zeros((nboot, ndots))
    BOOTwsum_sin_c = np.zeros((nboot, ndots))

    for nbin in range(ndots):
        mbin = dig == nbin + 1

        DSIGMAwsum_T = np.append(DSIGMAwsum_T, (et[mbin] * peso[mbin]).sum())
        DSIGMAwsum_X = np.append(DSIGMAwsum_X, (ex[mbin] * peso[mbin]).sum())
        WEIGHTsum = np.append(WEIGHTsum, (peso[mbin]).sum())
        Mwsum = np.append(Mwsum, (m[mbin] * peso[mbin]).sum())

        GAMMATcos_wsum = np.append(GAMMATcos_wsum,
                                   (et[mbin] * np.cos(2. * at[mbin]) *
                                    peso[mbin]).sum())
        GAMMAXsin_wsum = np.append(GAMMAXsin_wsum,
                                   (ex[mbin] * np.sin(2. * at[mbin]) *
                                    peso[mbin]).sum())
        WEIGHTcos_sum = np.append(WEIGHTcos_sum, ((np.cos(2. * at[mbin])**2) *
                                                  peso[mbin]).sum())
        WEIGHTsin_sum = np.append(WEIGHTsin_sum, ((np.sin(2. * at[mbin])**2) *
                                                  peso[mbin]).sum())

        GAMMATcos_wsum_c = np.append(GAMMATcos_wsum_c,
                                     (et[mbin] * np.cos(2. * theta_ra[mbin]) *
                                      peso[mbin]).sum())
        GAMMAXsin_wsum_c = np.append(GAMMAXsin_wsum_c,
                                     (ex[mbin] * np.sin(2. * theta_ra[mbin]) *
                                      peso[mbin]).sum())
        WEIGHTcos_sum_c = np.append(WEIGHTcos_sum_c,
                                    ((np.cos(2. * theta_ra[mbin])**2) *
                                     peso[mbin]).sum())
        WEIGHTsin_sum_c = np.append(WEIGHTsin_sum_c,
                                    ((np.sin(2. * theta_ra[mbin])**2) *
                                     peso[mbin]).sum())

        index = np.arange(mbin.sum())
        if mbin.sum() == 0:
            continue
        else:
            with NumpyRNGContext(1):
                bootresult = bootstrap(index, nboot)
            INDEX = bootresult.astype(int)
            BOOTwsum_T[:,
                       nbin] = np.sum(np.array(et[mbin] * peso[mbin])[INDEX],
                                      axis=1)
            BOOTwsum_X[:,
                       nbin] = np.sum(np.array(ex[mbin] * peso[mbin])[INDEX],
                                      axis=1)
            BOOTwsum[:, nbin] = np.sum(np.array(peso[mbin])[INDEX], axis=1)

            BOOTwsum_Tcos[:, nbin] = np.sum(np.array(
                et[mbin] * np.cos(2. * at[mbin]) * peso[mbin])[INDEX],
                                            axis=1)
            BOOTwsum_Xsin[:, nbin] = np.sum(np.array(
                ex[mbin] * np.sin(2. * at[mbin]) * peso[mbin])[INDEX],
                                            axis=1)
            BOOTwsum_cos[:, nbin] = np.sum(np.array(
                peso[mbin] * (np.cos(2. * at[mbin])**2))[INDEX],
                                           axis=1)
            BOOTwsum_sin[:, nbin] = np.sum(np.array(
                peso[mbin] * (np.sin(2. * at[mbin])**2))[INDEX],
                                           axis=1)

            BOOTwsum_Tcos_c[:, nbin] = np.sum(np.array(
                et[mbin] * np.cos(2. * theta_ra[mbin]) * peso[mbin])[INDEX],
                                              axis=1)
            BOOTwsum_Xsin_c[:, nbin] = np.sum(np.array(
                ex[mbin] * np.sin(2. * theta_ra[mbin]) * peso[mbin])[INDEX],
                                              axis=1)
            BOOTwsum_cos_c[:, nbin] = np.sum(np.array(
                peso[mbin] * (np.cos(2. * theta_ra[mbin])**2))[INDEX],
                                             axis=1)
            BOOTwsum_sin_c[:, nbin] = np.sum(np.array(
                peso[mbin] * (np.sin(2. * theta_ra[mbin])**2))[INDEX],
                                             axis=1)

    output = {
        'DSIGMAwsum_T': DSIGMAwsum_T,
        'DSIGMAwsum_X': DSIGMAwsum_X,
        'WEIGHTsum': WEIGHTsum,
        'Mwsum': Mwsum,
        'BOOTwsum_T': BOOTwsum_T,
        'BOOTwsum_X': BOOTwsum_X,
        'BOOTwsum': BOOTwsum,
        'GAMMATcos_wsum': GAMMATcos_wsum,
        'GAMMAXsin_wsum': GAMMAXsin_wsum,
        'WEIGHTcos_sum': WEIGHTcos_sum,
        'WEIGHTsin_sum': WEIGHTsin_sum,
        'GAMMATcos_wsum_c': GAMMATcos_wsum_c,
        'GAMMAXsin_wsum_c': GAMMAXsin_wsum_c,
        'WEIGHTcos_sum_c': WEIGHTcos_sum_c,
        'WEIGHTsin_sum_c': WEIGHTsin_sum_c,
        'BOOTwsum_Tcos': BOOTwsum_Tcos,
        'BOOTwsum_Xsin': BOOTwsum_Xsin,
        'BOOTwsum_cos': BOOTwsum_cos,
        'BOOTwsum_sin': BOOTwsum_sin,
        'BOOTwsum_Tcos_c': BOOTwsum_Tcos,
        'BOOTwsum_Xsin_c': BOOTwsum_Xsin,
        'BOOTwsum_cos_c': BOOTwsum_cos,
        'BOOTwsum_sin_c': BOOTwsum_sin,
        'Ntot': Ntot
    }

    return output