Exemplo n.º 1
0
def build_observations(Mr=21, b_normal=0.25, make=['data', 'covariance']):
    ''' Wrapper to build all the required fake observations and their
    corresponding covariance matrices. 
    '''
    # download the Multidark halo catalog if necessary
    try:
        halocat = CachedHaloCatalog(simname='multidark',
                                    halo_finder='rockstar',
                                    redshift=0.0)
    except InvalidCacheLogEntry:
        from halotools.sim_manager import DownloadManager
        dman = DownloadManager()
        dman.download_processed_halo_table('multidark', 'rockstar', 0.0)

    if 'data' in make:
        # xi, nbar, gmf
        build_xi_bins(Mr=Mr)
        print 'Building randoms and RRs for the subvolumes'
        build_randoms_RR(Nr=5e5, box='md_sub')
        print 'Building nbar, xi(r), GMF data vector... '
        build_nbar_xi_gmf(Mr=Mr, b_normal=b_normal)

    if 'covariance' in make:
        print 'Computing covariance matrix of data...'
        print 'building the sample covariance'
        build_MCMC_cov_nbar_xi_gmf(Mr=Mr, b_normal=b_normal)
        print 'building the poisson covariance'
        build_ABC_cov_nbar_xi_gmf(Mr=Mr, b_normal=b_normal)

    return None
Exemplo n.º 2
0
def build_observations(Mr=21, b_normal=0.25, make=['data', 'covariance']):
    ''' Wrapper to build all the required fake observations and their
    corresponding covariance matrices. 
    '''
    # download the Multidark halo catalog if necessary
    try:
        halocat = CachedHaloCatalog(simname='multidark',
                                    halo_finder='rockstar',
                                    redshift=0.0)
    except InvalidCacheLogEntry:
        from halotools.sim_manager import DownloadManager
        dman = DownloadManager()
        dman.download_processed_halo_table('multidark', 'rockstar', 0.0)
    
    if 'data' in make: 
        # xi, nbar, gmf
        build_xi_bins(Mr=Mr)
        print 'Building randoms and RRs for the subvolumes'
        build_randoms_RR(Nr=5e5, box='md_sub')
        print 'Building nbar, xi(r), GMF data vector... '
        build_nbar_xi_gmf(Mr=Mr, b_normal=b_normal)
    
    if 'covariance' in make:
        print 'Computing covariance matrix of data...'
        print 'building the sample covariance'
        build_MCMC_cov_nbar_xi_gmf(Mr=Mr, b_normal=b_normal)
        print 'building the poisson covariance'
        build_ABC_cov_nbar_xi_gmf(Mr=Mr, b_normal=b_normal)

    return None
ptcl_version_name = sim_defaults.default_ptcl_version_name

if args.ptcls_only is True: 
    download_halos = False
else:
    download_halos = True

if args.halos_only is True: 
    download_ptcls = False
else:
    download_ptcls = True

# Done parsing inputs

downman = DownloadManager()

##################################################################
# First check to see if the log has any matching entries before 
# requesting the download 
# This is technically redundant with the functionality in the downloading methods, 
# but this makes it easier to issue the right error message
if args.overwrite == False:

    if download_halos == True:

        gen = downman.halo_table_cache.matching_log_entry_generator
        matching_halocats = list(
            gen(simname = simname, halo_finder = halo_finder, 
                version_name = version_name, redshift = redshift, dz_tol = 0.1))
Exemplo n.º 4
0
    def __init__(self, simname, halo_finder, redshift, comm=None):

        from halotools.sim_manager import CachedHaloCatalog, DownloadManager
        from halotools.sim_manager.supported_sims import supported_sim_dict

        # do seme setup
        self.comm = comm
        meta_cols = ['Lbox', 'redshift', 'particle_mass']

        # try to automatically load from the Halotools cache
        exception = None
        if self.comm.rank == 0:
            kws = {'simname':simname, 'halo_finder':halo_finder, 'redshift':redshift}
            try:
                cached_halos = CachedHaloCatalog(dz_tol=0.1, **kws)
                fname = cached_halos.fname # the filename to load
                meta = {k:getattr(cached_halos, k) for k in meta_cols}
            except Exception as e:

                # try to download on the root rank
                try:
                    # download
                    dl = DownloadManager()
                    dl.download_processed_halo_table(dz_tol=0.1, **kws)

                    # access the cached halo catalog and get fname attribute
                    # NOTE: this does not read the data
                    cached_halos = CachedHaloCatalog(dz_tol=0.1, **kws)
                    fname = cached_halos.fname
                    meta = {k:getattr(cached_halos, k) for k in meta_cols}
                except Exception as e:
                    exception = e
        else:
            fname = None
            meta = None

        # re-raise a download error on all ranks if it occurred
        exception = self.comm.bcast(exception, root=0)
        if exception is not None:
            raise exception

        # broadcast the file we are loading
        fname = self.comm.bcast(fname, root=0)
        meta = self.comm.bcast(meta, root=0)

        # initialize an HDF catalog and add Position/Velocity
        cat = HDFCatalog(fname, comm=comm)
        cat['Position'] = transform.StackColumns(cat['halo_x'], cat['halo_y'], cat['halo_z'])
        cat['Velocity'] = transform.StackColumns(cat['halo_vx'], cat['halo_vy'], cat['halo_vz'])

        # get the cosmology from Halotools
        cosmo = supported_sim_dict[simname]().cosmology # this is astropy cosmology
        cosmo = Cosmology.from_astropy(cosmo)

        # initialize the HaloCatalog
        HaloCatalog.__init__(self, cat, cosmo, meta['redshift'], mdef='vir', mass='halo_mvir')

        # add some meta-data
        # NOTE: all Halotools catalogs have to these attributes
        self.attrs['BoxSize'] = meta['Lbox']
        self.attrs['redshift'] = meta['redshift']
        self.attrs['particle_mass'] = meta['particle_mass']

        # save the cosmology
        self.cosmo = cosmo
        self.attrs['cosmo'] = dict(self.cosmo)
Exemplo n.º 5
0
    def __init__(self, simname, halo_finder, redshift, comm=None):

        from halotools.sim_manager import CachedHaloCatalog, DownloadManager
        from halotools.sim_manager.supported_sims import supported_sim_dict

        # do seme setup
        self.comm = comm
        meta_cols = ['Lbox', 'redshift', 'particle_mass']

        # try to automatically load from the Halotools cache
        exception = None
        if self.comm.rank == 0:
            kws = {
                'simname': simname,
                'halo_finder': halo_finder,
                'redshift': redshift
            }
            try:
                cached_halos = CachedHaloCatalog(dz_tol=0.1, **kws)
                fname = cached_halos.fname  # the filename to load
                meta = {k: getattr(cached_halos, k) for k in meta_cols}
            except Exception as e:

                # try to download on the root rank
                try:
                    # download
                    dl = DownloadManager()
                    dl.download_processed_halo_table(dz_tol=0.1, **kws)

                    # access the cached halo catalog and get fname attribute
                    # NOTE: this does not read the data
                    cached_halos = CachedHaloCatalog(dz_tol=0.1, **kws)
                    fname = cached_halos.fname
                    meta = {k: getattr(cached_halos, k) for k in meta_cols}
                except Exception as e:
                    exception = e
        else:
            fname = None
            meta = None

        # re-raise a download error on all ranks if it occurred
        exception = self.comm.bcast(exception, root=0)
        if exception is not None:
            raise exception

        # broadcast the file we are loading
        fname = self.comm.bcast(fname, root=0)
        meta = self.comm.bcast(meta, root=0)

        # initialize an HDF catalog and add Position/Velocity
        cat = HDFCatalog(fname, comm=comm)
        cat['Position'] = transform.StackColumns(cat['halo_x'], cat['halo_y'],
                                                 cat['halo_z'])
        cat['Velocity'] = transform.StackColumns(cat['halo_vx'],
                                                 cat['halo_vy'],
                                                 cat['halo_vz'])

        # get the cosmology from Halotools
        cosmo = supported_sim_dict[simname](
        ).cosmology  # this is astropy cosmology
        cosmo = Cosmology.from_astropy(cosmo)

        # initialize the HaloCatalog
        HaloCatalog.__init__(self,
                             cat,
                             cosmo,
                             meta['redshift'],
                             mdef='vir',
                             mass='halo_mvir')

        # add some meta-data
        # NOTE: all Halotools catalogs have to these attributes
        self.attrs['BoxSize'] = meta['Lbox']
        self.attrs['redshift'] = meta['redshift']
        self.attrs['particle_mass'] = meta['particle_mass']

        # save the cosmology
        self.cosmo = cosmo
        self.attrs['cosmo'] = dict(self.cosmo)