Пример #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
Пример #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
        if len(matching_ptcl_cats) > 0:
            matching_fname = matching_ptcl_cats[0].fname
            raise HalotoolsError(existing_fname_error_msg % matching_fname)        

##################################################################

##################################################################
### Call the download methods
if download_ptcls == True:
    new_ptcl_log_entry = downman.download_ptcl_table(simname = simname,
        redshift = redshift, dz_tol = 0.05, overwrite=args.overwrite, download_dirname = args.dirname,
        initial_download_script_msg = existing_fname_error_msg)

if download_halos == True:
    new_halo_log_entry = downman.download_processed_halo_table(simname = simname,
        halo_finder = halo_finder, redshift = redshift, download_dirname = args.dirname,
        initial_download_script_msg = existing_fname_error_msg,
        overwrite = args.overwrite)

##################################################################




##################################################################
### Issue the success message

cache_dirname = str(os.path.dirname(downman.halo_table_cache.cache_log_fname)).strip()
halo_table_cache_basename = str(os.path.basename(downman.halo_table_cache.cache_log_fname))
ptcl_table_cache_basename = str(os.path.basename(downman.ptcl_table_cache.cache_log_fname))

msg = (
Пример #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)
Пример #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)