예제 #1
0
def fubar_halo(obj):
    """Halo-by-halo group finding procedure.
    Romeel Davé March 2020

    FUBAR stands for Friends-of-friends Unbinding after Rockstar; the
    name is no longer valid, but it stuck.  Here we perform an FOF
    operation for each grouping and create the master caesar lists.

    For halos we consider dark matter + gas + stars.  For galaxies
    however, we only consider high density gas and stars (dust and
    blackholes if included).

    For clouds we consider all gas particles.
    
    Parameters
    ----------
    obj : :class:`main.CAESAR`
        Main caesar object.
    group_type : str
        Can be either 'halo', 'galaxy' or 'cloud'; determines what objects
        we find with FOF.

    """

    #pdb.set_trace()

    from caesar.fof6d import fof6d
    from caesar.group import get_group_properties
    from caesar.fubar import get_mean_interparticle_separation

    # set up number of processors
    obj.nproc = 1  # defaults to single core
    if 'nproc' in obj._kwargs:
        obj.nproc = int(obj._kwargs['nproc'])
    if obj.nproc != 1:
        import joblib
        if obj.nproc < 0:
            obj.nproc += joblib.cpu_count() + 1
        if obj.nproc == 0:
            obj.nproc = joblib.cpu_count()
    mylog.info('member_search() running on %d cores' % obj.nproc)
    obj.load_haloid = False
    if 'haloid' in obj._kwargs and 'snap' in obj._kwargs['haloid']:
        obj.load_haloid = True

    # Process halos
    halos = fof6d(obj, 'halo')  #instantiate a fof6d object
    halos.MIS = get_mean_interparticle_separation(
        obj).d  # also computes omega_baryon and related quantities
    halos.load_haloid()
    halos.obj.data_manager._member_search_init(
        select=halos.haloid
    )  # load particle info, but only those selected to be in a halo
    if not halos.plist_init(
    ):  # not enough halo particles found, nothing to do!
        return
    halos.load_lists()  # create halos, load particle indexes for halos
    if len(halos.obj.halo_list) == 0:  # no valid halos found
        mylog.warning('No valid halos found! Aborting member search')
        return
    get_group_properties(halos, halos.obj.halo_list)  # compute halo properties

    # Find galaxies, or load galaxy membership info
    if not obj.simulation.baryons_present:  # if no baryons, we're done
        return
    fof6d_flag = True
    if 'fof6d' in obj._kwargs and not obj._kwargs[
            'fof6d']:  # fof6d for galaxies/clouds not requested
        mylog.warning(
            'fof6d not requested, and no other galaxy finder available! Aborting member search'
        )
        return
    if 'fof6d_file' in obj._kwargs and obj._kwargs['fof6d_file'] is not None:
        fof6d_flag = halos.load_fof6dfile()  # load galaxy ID's from fof6d_file
    if fof6d_flag:
        halos.run_fof6d('galaxy')  # run fof6d on halos to find galaxies
        halos.save_fof6dfile()  # save fof6d info
        #snapname = ('%s/%s'%(obj.simulation.fullpath,obj.simulation.basename))
        #nparts,gas_index,star_index,bh_index = run_fof_6d(snapname,16,0.02,1.0,nproc)

    # Process galaxies
    galaxies = fof6d(obj, 'galaxy')  #instantiate a fof6d object
    galaxies.plist_init(
        parent=halos)  # get particle list for computing galaxy properties
    if galaxies.nparttot == 0:  # plist_init didn't find any particles in a galaxy
        mylog.warning('Not enough eligible galaxy particles found!')
        return
    galaxies.load_lists(
        parent=halos
    )  # create galaxy_list, load particle index lists for galaxies
    get_group_properties(galaxies,
                         galaxies.obj.galaxy_list)  # compute galaxy properties
    if ('fsps_bands' in obj._kwargs) and obj._kwargs['fsps_bands'] is not None:
        from caesar.pyloser.pyloser import photometry
        galphot = photometry(obj, galaxies.obj.galaxy_list)
        galphot.run_pyloser()

    # Find and process clouds
    if ('fofclouds' in obj._kwargs) and obj._kwargs['fofclouds']:
        galaxies.run_fof6d('cloud')  # run fof6d to find cloudid's
        galaxies.load_lists('cloud')  # load particle index lists for galaxies
        clouds = fof6d(obj, 'cloud')  #instantiate a fof6d object
        clouds.plist_init(
            parent=galaxies)  # initialize comptutation of cloud properties
        if clouds.nparttot == 0:
            return  # plist_init didn't find enough particles to group
        galaxies.load_lists('cloud')
        get_group_properties(clouds,
                             clouds.obj.cloud_list)  # compute cloud properties

    # reset particle lists to have original snapshot ID's; must do this after all group processing is finished
    reset_global_particle_IDs(obj)
    # load global lists
    load_global_lists(obj)

    return
예제 #2
0
import caesar
from caesar.pyloser import pyloser
from caesar.cyloser import compute_AV

# _dir = '/cosma7/data/dp104/dc-dave2/sim/m100n1024/s50j7k/'
_dir = '/orange/narayanan/desika.narayanan/gizmo_runs/simba/m100n1024/'
cs = caesar.load(_dir + 'Groups/m100n1024_078.hdf5')

_dat = json.load(open('m100/galaxy_selection.json', 'r'))
halos = [cs.halos[n['hidx']] for k, n in _dat['078'].items()]

# subset_dir='/blue/narayanan/c.lovell/simba/m100n1024/out/snap_078/'
# ds = yt.load(subset_dir+'subset_00000.h5')

ds = yt.load(_dir + 'snap_m100n1024_078.hdf5')
phot = pyloser.photometry(cs, [halos[0]], ds=ds)

phot.ssp_table_file = \
    '/home/c.lovell/codes/caesar/FSPS_Chab_EL.hdf5'
# '/cosma7/data/dp004/dc-love2/codes/caesar/FSPS_Chab_EL.hdf5'

phot.init_pyloser()


def transform_coods(theta, phi, tol=20, test=False):

    alpha = np.arcsin(-1 * np.round(np.sin(theta), tol) *
                      np.round(np.sin(phi), tol))
    beta = np.round(
        np.arcsin((np.round(np.cos(phi), tol) * np.round(np.sin(theta), tol)) /
                  np.round(np.cos(alpha), tol)), tol)
예제 #3
0
파일: test_phot.py 프로젝트: Hoptune/caesar
                    sim.simulation.effective_resolution**
                    3)  # galaxy mass resolution limit: 32 gas particle masses
    sfr = np.asarray([i.sfr for i in myobjs])
    ssfr = np.log10(
        1.e9 * sfr / ms +
        10**(-2.5 +
             0.3 * sim.simulation.redshift))  # with a floor to prevent NaN's

    # now do photometry in post-processing
    #from caesar.pyloser.pyloser import photometry
    #ds  = sim.yt_dataset
    myobjs = sim.galaxies
    from caesar.pyloser.pyloser import photometry
    galphot = photometry(sim,
                         myobjs,
                         ds=ds,
                         band_names='sdss',
                         ext_law='composite',
                         nproc=16)
    #galphot.run_pyloser(ssp_model='BPASS')
    spect_dust, spec_nodust = galphot.run_pyloser()
    print('Default (should be same):', galphot.groups[0].absmag['sdss_r'])

    galphot = photometry(sim,
                         myobjs,
                         ds=ds,
                         band_names='sdss',
                         ssp_model='BPASS',
                         ssp_table_file='/home/rad/caesar/BPASS_Chab100.hdf5',
                         ext_law='composite',
                         nproc=16)
    spect_dust, spec_nodust = galphot.run_pyloser()
예제 #4
0
fig, ((ax1, ax2, ax3), (ax4, ax5, ax6)) = plt.subplots(2, 3, figsize=(10, 5))
axes = [ax1, ax2, ax3, ax4, ax5, ax6]

cmap = cmaps.night()
roll, extent = 0, 30
## ---------- ##

for s, s_file in enumerate(subset_files):
    # if True:
    #     s = 0
    #     s_file = subset_files[0]
    ds = yt.load(subset_dir + s_file)

    halo = halos[s]
    galaxy = galaxies[s]
    phot = pyloser.photometry(cs, halo)
    phot.ssp_table_file = '/home/c.lovell/codes/caesar/FSPS_Chab_EL.hdf5'
    init_kerntab(phot)
    hcood = galaxy.pos.value

    with h5py.File(subset_dir + s_file, 'r') as f:
        _fact = 1 / cs.simulation.hubble_constant
        gpos = f['PartType0']['Coordinates'][:] * _fact
        spos = f['PartType4']['Coordinates'][:] * _fact
        gm = f['PartType0']['Masses'][:] * 1e10
        gZ = f['PartType0']['Dust_Masses'][:] * 1e10
        gZ /= gm
        ghsm = f['PartType0']['SmoothingLength'][:]

    _pos = galaxy.pos.to('kpccm').value
    _mask = (cdist(spos, [_pos]) < 30).flatten()