Beispiel #1
0
 def __init__(self, datar, randomr, nofz, universe_params=None):
     #
     # make sure catalogs have the desired format
     #
     # cosmology
     if universe_params is None:
         universe_params = universeparams
     cosmo = Cosmology(Om0=universe_params['Om0'],
                       H0=universe_params['H0'],
                       flat=universe_params['flat'])
     data = catit(datar)
     randoms = catit(randomr)
     data = nb.ArrayCatalog(data)
     randoms = nb.ArrayCatalog(randoms)
     data['Position'] = SkyToCartesian(data['RA'],
                                       data['DEC'],
                                       data['Z'],
                                       cosmo=cosmo)
     randoms['Position'] = SkyToCartesian(randoms['RA'],
                                          randoms['DEC'],
                                          randoms['Z'],
                                          cosmo=cosmo)
     #
     self.data = data
     self.randoms = randoms
     self.nofz = nofz
Beispiel #2
0
def finalize_data(s, cosmo, P0_FKP=None):
    """
    Finalize the creation of a CatalogSource from a data file by
    adding 'Position', 'Weight', and 'FKPWeight'.

    Parameters
    ----------
    s : CatalogSource
        the catalog source object
    cosmo : Cosmology
        the cosmology parameters
    P0_FKP : float, optional
        the P0 value to use to for FKPWeights
    """
    from nbodykit.transform import SkyToCartesian

    # add the Position column
    s['Position'] = SkyToCartesian(s['RA'],
                                   s['DEC'],
                                   s['Z'],
                                   cosmo,
                                   degrees=True)

    # add systematic weights
    if 'WEIGHT_NOZ' in s and 'WEIGHT_FOCAL' not in s:
        s['Weight'] = s['WEIGHT_SYSTOT'] * (s['WEIGHT_NOZ'] + s['WEIGHT_CP'] -
                                            1.)
    elif 'WEIGHT_FOCAL' in s:
        s['Weight'] = s['WEIGHT_SYSTOT'] * s['WEIGHT_CP'] * s['WEIGHT_FOCAL']

    # FKP WEIGHT
    if P0_FKP is not None:
        s['FKPWeight'] = 1. / (1 + s['NZ'] * P0_FKP)
Beispiel #3
0
valid  = (randoms['Z'] >= ZMIN) & (randoms['Z'] <= ZMAX)
if 'COMP_BOSS' in randoms.columns:
    valid &= randoms['COMP_BOSS']  > compmin
if 'sector_SSR' in randoms.columns:
    valid &= randoms['sector_SSR'] > compmin

valid &= randoms['RA'] > 140.
randoms = randoms[valid]



# the fiducial BOSS DR12 cosmology
cosmo = Cosmology(h=0.676).match(Omega0_m=0.31)

# add Cartesian position column
data['Position']    = SkyToCartesian(data['RA'],    data['DEC'],    data['Z'],    cosmo=cosmo)
randoms['Position'] = SkyToCartesian(randoms['RA'], randoms['DEC'], randoms['Z'], cosmo=cosmo)

# apply the Completeness weights to both data and randoms
if sys_tot:
    if rank ==0:print('including sys_tot')
    data['WEIGHT']      = data['WEIGHT_SYSTOT']    * data['WEIGHT_NOZ']    * data['WEIGHT_CP']
else:
    if rank ==0:print('excluding sys_tot')    
    data['WEIGHT']      = data['WEIGHT_NOZ']    * data['WEIGHT_CP'] # data['WEIGHT_SYSTOT'] 
    
randoms['WEIGHT']   = randoms['WEIGHT_SYSTOT'] * randoms['WEIGHT_NOZ'] * randoms['WEIGHT_CP']

# combine the data and randoms into a single catalog
fkp  = nb.FKPCatalog(data, randoms, nbar='NZ')
mesh = fkp.to_mesh(Nmesh=nmesh, fkp_weight='WEIGHT_FKP', comp_weight='WEIGHT', window='tsc')
Beispiel #4
0
print(cat)

cat.write('../dat/lrg_cat.fits', format='fits', overwrite=True)

indices = np.random.choice(len(cat), 500, replace=False)

cat = cat[indices]

cat['Dec'] = cat['DEC']

del cat['DEC']

cat['COLOR'] = 'FUCHSIA'
# cat['ALPHA'] =    0.2

print(cat)

# cat.write('../dat/lrg_cat_viewer.fits', format='fits', overwrite=True)

#
# np.savetxt('../dat/lrg_cat_viewer.txt', cat['RA', 'Dec'])

pos = SkyToCartesian(cat['RA'], cat['Dec'], cat['REDSHIFT'], Planck15)
pos = np.array(pos)

pos[:, 0] -= pos[:, 0].mean()
pos[:, 1] -= pos[:, 1].mean()
pos[:, 2] -= pos[:, 2].mean()

np.savetxt('../dat/lrg_cat_pos.txt', pos, delimiter=',')
Beispiel #5
0
def main(ns):
    data = BigFileCatalog(ns.cat, dataset=ns.data)
    rand = BigFileCatalog(ns.cat, dataset=ns.rand)

    dndz_data = RedshiftHistogram(data, fsky=1.0, cosmo=Planck15, redshift='Z')

    ssdata = data.persist(['RA', 'DEC', 'Z'])
    ssrand = rand.persist(['RA', 'DEC', 'Z'])

    dndz_data = RedshiftHistogram(ssdata, fsky=1, cosmo=Planck15, redshift='Z')
    dndz_rand = RedshiftHistogram(ssrand, fsky=1, cosmo=Planck15, redshift='Z')

    hmap = healpix.histogrammap(ssdata['RA'].compute(),
                                ssdata['DEC'].compute(),
                                nside=128,
                                perarea=True)
    data_hmap = data.comm.allreduce(hmap.astype('f8'))

    hmap = healpix.histogrammap(ssrand['RA'].compute(),
                                ssrand['DEC'].compute(),
                                nside=128,
                                perarea=True)
    rand_hmap = data.comm.allreduce(hmap.astype('f8'))

    ssdata['NZ'] = dndz_data.interpolate(ssdata['Z'])
    ssrand['NZ'] = dndz_data.interpolate(ssrand['Z'])

    ssdata['Position'] = SkyToCartesian(ssdata['RA'], ssdata['DEC'],
                                        ssdata['Z'], Planck15)
    ssrand['Position'] = SkyToCartesian(ssrand['RA'], ssrand['DEC'],
                                        ssrand['Z'], Planck15)

    cat = FKPCatalog(
        data=ssdata,
        randoms=ssrand,
    )

    fkp = ConvolvedFFTPower(cat, poles=[0, 2, 4], Nmesh=512 * 4)
    basename, ext = ns.output.rsplit('.', 1)
    fkp.save(basename + '-fkp' + '.' + ext)

    edges = numpy.arange(4, 140, 4)
    everydata = max(int(ssdata.size / 40000 + 0.5), 1)
    everyrand = max(int(ssrand.size / 40000 + 0.5), 1)

    xir = SurveyData2PCF(mode='2d',
                         data1=ssdata[::everydata],
                         randoms1=ssrand[::everyrand],
                         cosmo=Planck15,
                         redshift='Z',
                         edges=edges,
                         Nmu=10,
                         show_progress=True)
    xir.save(basename + '-xir' + '.' + ext)

    if data.comm.rank == 0:
        data_hmap.tofile(basename + 'data-hmap.f8')
        rand_hmap.tofile(basename + 'rand-hmap.f8')

        from matplotlib.figure import Figure
        from matplotlib.gridspec import GridSpec
        from matplotlib.backends.backend_agg import FigureCanvasAgg

        fig = Figure(figsize=(6, 12), dpi=200)
        gs = GridSpec(5, 2)

        for i, l in enumerate([0, 2, 4]):
            ax = fig.add_subplot(gs[i, 0])

            ax.plot(fkp.poles['k'],
                    fkp.poles[f'power_{l}'] - fkp.attrs['shotnoise'],
                    label=f'l={l}')

            ax.set_xscale('log')
            ax.set_yscale('log')
            ax.set_xlabel('k [h/Mpc]')
            ax.set_ylabel('P(k)')
            ax.grid()
            ax.legend()

        poles = xir.corr.to_poles([0, 2, 4])
        for i, l in enumerate([0, 2, 4]):
            ax = fig.add_subplot(gs[i, 1])
            ax.plot(poles['r'],
                    poles['r']**2 * poles[f'corr_{l}'],
                    label=f'l = {l}')
            ax.set_xlabel('r [Mpc/h]')
            ax.set_ylabel('r^2 xi(r)')
            ax.grid()
            ax.legend()
            ax.set_title('Downsample D%d R%d' % (everydata, everyrand))

        ax = fig.add_subplot(gs[3, 0])

        ax.plot(dndz_data.bin_centers, dndz_data.nbar, label='n(z) data')
        ax.plot(dndz_rand.bin_centers,
                dndz_rand.nbar * (data.csize / rand.csize),
                label='n(z) * D / R random')
        ax.grid()
        ax.legend()
        ax.set_xlabel('z')
        ax.set_ylabel('n(z)')

        ax = fig.add_subplot(gs[3, 1])

        ax.hist(data_hmap, histtype='step', label='n(A) data', log=True)
        ax.hist(rand_hmap * data.csize / rand.csize,
                histtype='step',
                label='n(A) * D / R random',
                log=True)
        ax.set_xlabel("N per sqdeg")
        ax.set_ylabel('counts')
        ax.legend()
        ax.grid()

        ax = fig.add_subplot(gs[4, 0], projection="ast.mollweide")
        ax.mapshow(data_hmap)
        ax.set_title("data")

        ax = fig.add_subplot(gs[4, 1], projection="ast.mollweide")
        ax.mapshow(rand_hmap)
        ax.set_title("randoms")

        canvas = FigureCanvasAgg(fig)
        fig.tight_layout()
        fig.savefig(basename + '.png', bbox_inches='tight')
Beispiel #6
0
 def sky_to_xyz(self, cosmo):
     self['Position'] = SkyToCartesian(self['RA'], self['DEC'], self['Z'], cosmo=cosmo)