コード例 #1
0
def _rockstar_method(ds, **finder_kwargs):
    r"""
    Run the Rockstar halo finding method.
    """

    from yt.frontends.rockstar.data_structures import \
     RockstarDataset
    from yt.analysis_modules.halo_finding.rockstar.api import \
     RockstarHaloFinder

    rh = RockstarHaloFinder(ds, **finder_kwargs)
    rh.run()

    if 'outbase' in finder_kwargs:
        outbase = finder_kwargs['outbase']
    else:
        outbase = "rockstar_halos"

    halos_ds = RockstarDataset(outbase + "/halos_0.0.bin")
    try:
        halos_ds.create_field_info()
    except ValueError:
        return None

    return halos_ds
コード例 #2
0
def _rockstar_method(ds, **finder_kwargs):
    r"""
    Run the Rockstar halo finding method.
    """

    from yt.frontends.rockstar.data_structures import \
     RockstarDataset
    from yt.analysis_modules.halo_finding.rockstar.api import \
     RockstarHaloFinder
    
    rh = RockstarHaloFinder(ds, **finder_kwargs)
    rh.run()

    halos_ds = RockstarDataset("rockstar_halos/halos_0.0.bin")
    try:
        halos_ds.create_field_info()
    except ValueError:
        return None

    return halos_ds
コード例 #3
0
ファイル: run_rockstar.py プロジェクト: cosmosquark/ramses_pp
if not os.path.exists('%s/rockstar/' % sim.path()):
    os.mkdir('%s/rockstar/' % sim.path())

#cd to rockstar/
os.chdir('rockstar/')
print 'In dir: %s' % os.getcwd()
print 'Starting rockstar...'

outputs = np.arange(1, sim.num_snapshots() + 1)
dirs = []
#Add the datasets
for ioutput in outputs:
    #ds = yt.load('../output_%05d/info_%05d.txt'%(ioutput, ioutput))
    ds = sim.snapshot(ioutput, module='yt').raw_snapshot()
    #assert(ds.add_particle_filter("dark_matter"))
    dirs.append(ds)

#es = yt.load('../output_*/info_*.txt')
es = DatasetSeries(dirs, setup_function=setup_ds)
#es = DatasetSeries(dirs)

readers = int(ncpu / 4.)
#Reserve one cpu for the server
writers = ncpu - readers - 1
print 'Running rockstar with %i writers and %i readers' % (writers, readers)
rh = RockstarHaloFinder(es,
                        num_readers=readers,
                        num_writers=writers,
                        particle_type="dark_matter")
rh.run()
コード例 #4
0
    return filter

add_particle_filter("dark_matter", function=DarkMatter, filtered_type='all', requires=["particle_type"])

path_man = path_manager(args.root_data_dir, args.root_output_dir,
                        sim_num=args.sim_number, snap_name=args.time_slice,
                        data_dir_prefix=args.data_prefix)

if not dataset_finished(path_man.get_exp_path()):
    print("Sim number %s is not yet finished. Exp path was (%s) Skipping." % (args.sim_number, path_man.get_exp_path()))
    sys.exit(0)

if yt.is_root():
    path_man.ensure_directories()


ds = yt.load(path_man.get_dataset_path())
ds.add_particle_filter('dark_matter')
ad = ds.all_data()

min_dm_mass = ad.quantities.extrema(('dark_matter', 'particle_mass'))[0]

def MaxResDarkMatter(pfilter, data):
    return data["particle_mass"] <= 1.01*min_dm_mass

add_particle_filter("max_res_dark_matter", function=MaxResDarkMatter, filtered_type='dark_matter', requires=["particle_mass"])
ds.add_particle_filter('max_res_dark_matter')
    
hf_rockstar = RockstarHaloFinder(ds, dm_only=True, particle_type='max_res_dark_matter', outbase=path_man.get_rockstar_halo_dirname(), num_readers=1, num_writers=1)
hf_rockstar.run()
コード例 #5
0
ファイル: rs-halo.py プロジェクト: shichao116/git_cluster
#find all of our simulation files
files = glob.glob("../DD*/*hierarchy")
#files += glob.glob("DD0046/*hierarchy")
#files += glob.glob("DD02*/*hierarchy")
#files += glob.glob("RD*/*hierarchy")

#files = ["DD0003/output_0003", "DD0004/output_0004"]
files.sort()

#sort the filelist by time
nfiles = len(files)
if nmax == None: nmax = nfiles
times = na.zeros(nfiles)
tmp = []
for i,f in enumerate(files[:]):
    pf = load(f)
    times[i] = pf.current_time
    tmp.append(pf)
isort = times.argsort()
pfs = []
nmax = min(nmax, nfiles)
for i in range(nfiles-nmax,nfiles):
    pfs.append(tmp[isort[i]])
ts = TimeSeriesData(pfs)
rh = RockstarHaloFinder(ts, num_readers=32, particle_type='finest',
                        total_particles=322375680, particle_mass=28807.25*0.71,
                        force_res=8.4638e-7)
rh.run(restart=False)

コード例 #6
0
ファイル: runRockstar.py プロジェクト: saitanmayi/yt-agora
def run_rockstar(
    sim_dir,
    snap_base="*",
    particle_types=["darkmatter"],
    recognized_star_types=["stars", "specie5"],
    multi_mass=False,
    force_res=None,
    initial_metric_scaling=1,
    out_dir="rockstar_output",
    num_readers=1,
):
    """
    Run Rockstar for a set of snapshots in the given simulation directory

    Parameters
    ----------
    sim_dir : str
         Simulation directory to be analyzed

    snap_base : str
         Snapshot files to be analyzed. You can use wild cards in SNAP_BASE
         to select a set of snapshots that match a given pattern

    particle_types: str list/array
         The particle types to use for halo finding, as named in yt fields or  
         derived fields. This can be filtered or inherent types.
         If particles with different masses are found for the given particle_types
         only the particles with the lowest mass will be used, unless the 
         multi_mass option is set to True

    recognized_star_types: str list/array
         Particle types to be recognized as stars. All types in particle_types 
         that are not included in this list will be treated as dark matter particles

    multi_mass : bool
         If True all the particle species in particle_types will be passed to 
         Rockstar even if they have different masses

    force_res : float
         Force resolution in units of Mpc/h. Halos whose centers are closer than 
         FORCE_RES are usually noise, and are subject to stricter removal tests
         than other halos. If no value is provided, this parameter is automatically 
         set to the width of the smallest grid element in the simulation from the
         last data snapshot (i.e. the one where time has evolved the longest)

    initial_metric_scaling : float
         The position element of the fof distance metric is divided by this 
         parameter, set to 1 by default. If the initial_metric_scaling=0.1 the
         position element will have 10 times more weight than the velocity element,
         biasing the metric towards position information more so than velocity
         information. That was found to be needed for hydro-ART simulations with
         with 10's of parsecs resolution

    out_dir : str
         Directory where the Rockstar output will be placed

    num_readers : int
         If the number of files per snapshot is more than one, setting
         num_readers > 1 can help I/O performance
    
    Returns
    -------
    None

    """
    if MPI.COMM_WORLD.Get_rank() == 0:
        print
        print "Beginning Rockstar analysis in ", sim_dir
        print "Placing output in ", out_dir

    # Generate data series
    snap_base = sim_dir + "/" + snap_base + "*"
    ts = yt.DatasetSeries(snap_base)
    if len(ts) > 1:
        first_snap = ts[0]
        last_snap = ts[-1]
        if MPI.COMM_WORLD.Get_rank() == 0:
            print "first snapshot: ", first_snap.basename
            print "last snapshot: ", last_snap.basename
    else:
        last_snap = ts[0]
        if MPI.COMM_WORLD.Get_rank() == 0:
            print "snapshot: ", last_snap.basename

    # Create particle union if needed
    punion = None
    if len(particle_types) > 1:
        punion = ParticleUnion("rockstar_analysis_particles", particle_types)
        last_snap.add_particle_union(punion)
        particle_type = "rockstar_analysis_particles"
    else:
        particle_type = particle_types[0]
    ad = last_snap.all_data()
    particle_masses = yt.np.unique(ad[(particle_type, "particle_mass")].in_units("Msun/h"))
    total_particles = ad.quantities.total_quantity((particle_type, "particle_ones"))

    if MPI.COMM_WORLD.Get_rank() == 0:
        print "Using particle(s) ", particle_types, " with mass(es) ", particle_masses
        print

    # Get the particle_type field of the star particles, and the min mass of the DM particles
    dm_masses = []
    star_types = []
    for type in particle_types:
        if type in recognized_star_types:
            star_types = yt.np.concatenate((star_types, yt.np.unique(ad[(type, "particle_type")])))
        else:
            dm_masses = yt.np.concatenate((dm_masses, yt.np.unique(ad[(type, "particle_mass")].in_units("Msun/h"))))
    dm_masses = last_snap.arr(dm_masses.value, "Msun/h")
    dm_min_mass = dm_masses.min()

    # In not multi mass select only the DM particles with the min mass
    if not multi_mass and len(particle_masses) > 1:

        @yt.particle_filter("hires_particles", filtered_type=particle_type, requires=["particle_mass"])
        def _hires_filter(pfilter, data):
            return data["particle_mass"] == dm_min_mass

        def setup_ds(ds):
            if punion:
                ds.add_particle_union(punion)
            ds.add_particle_filter("hires_particles")

        particle_type = "hires_particles"
    else:

        def setup_ds(ds):
            if punion:
                ds.add_particle_union(punion)

    # Remove last/first_snap from memory and cache
    if len(ts) > 1:
        del first_snap
    del last_snap
    _cached_datasets.clear()

    # Pass the setup_function to the time series
    ts._setup_function = setup_ds

    # Run rockstar
    rh = RockstarHaloFinder(
        ts,
        num_readers=num_readers,
        num_writers=None,
        outbase=out_dir,
        particle_type=particle_type,
        star_types=star_types,
        multi_mass=multi_mass,
        force_res=force_res,
        initial_metric_scaling=initial_metric_scaling,
        particle_mass=dm_min_mass,
        total_particles=total_particles,
    )
    MPI.COMM_WORLD.barrier()
    rh.run()
    MPI.COMM_WORLD.barrier()

    if MPI.COMM_WORLD.Get_rank() == 0:
        print "Successfully finished Rockstar analysis in ", sim_dir
        print
コード例 #7
0
ファイル: runRockstar.py プロジェクト: saitanmayi/yt-agora
def run_rockstar(sim_dir, snap_base='*', particle_types=["darkmatter"],
                 recognized_star_types=["stars", "specie5"], multi_mass=False,
                 force_res=None, initial_metric_scaling=1, out_dir="rockstar_output",
                 num_readers=1):
    '''
    Run Rockstar for a set of snapshots in the given simulation directory

    Parameters
    ----------
    sim_dir : str
         Simulation directory to be analyzed

    snap_base : str
         Snapshot files to be analyzed. You can use wild cards in SNAP_BASE
         to select a set of snapshots that match a given pattern

    particle_types: str list/array
         The particle types to use for halo finding, as named in yt fields or  
         derived fields. This can be filtered or inherent types.
         If particles with different masses are found for the given particle_types
         only the particles with the lowest mass will be used, unless the 
         multi_mass option is set to True

    recognized_star_types: str list/array
         Particle types to be recognized as stars. All types in particle_types 
         that are not included in this list will be treated as dark matter particles

    multi_mass : bool
         If True all the particle species in particle_types will be passed to 
         Rockstar even if they have different masses

    force_res : float
         Force resolution in units of Mpc/h. Halos whose centers are closer than 
         FORCE_RES are usually noise, and are subject to stricter removal tests
         than other halos. If no value is provided, this parameter is automatically 
         set to the width of the smallest grid element in the simulation from the
         last data snapshot (i.e. the one where time has evolved the longest)

    initial_metric_scaling : float
         The position element of the fof distance metric is divided by this 
         parameter, set to 1 by default. If the initial_metric_scaling=0.1 the
         position element will have 10 times more weight than the velocity element,
         biasing the metric towards position information more so than velocity
         information. That was found to be needed for hydro-ART simulations with
         with 10's of parsecs resolution

    out_dir : str
         Directory where the Rockstar output will be placed

    num_readers : int
         If the number of files per snapshot is more than one, setting
         num_readers > 1 can help I/O performance
    
    Returns
    -------
    None

    '''
    if MPI.COMM_WORLD.Get_rank()==0:
        print
        print 'Beginning Rockstar analysis in ', sim_dir
        print 'Placing output in ', out_dir
   
    # Generate data series
    snap_base = sim_dir+ '/' + snap_base + '*'
    ts = yt.DatasetSeries(snap_base)
    if len(ts) > 1:
        first_snap = ts[0]
        last_snap = ts[-1]
        if MPI.COMM_WORLD.Get_rank()==0:    
            print 'first snapshot: ', first_snap.basename
            print 'last snapshot: ', last_snap.basename    
    else:
        last_snap = ts[0]
        if MPI.COMM_WORLD.Get_rank()==0:    
            print 'snapshot: ', last_snap.basename    

    # Create particle union if needed    
    punion=None
    if len(particle_types) > 1:
        punion = ParticleUnion("rockstar_analysis_particles", particle_types)
        last_snap.add_particle_union(punion)
        particle_type = "rockstar_analysis_particles"
    else:
        particle_type = particle_types[0]
    ad = last_snap.all_data()
    particle_masses = yt.np.unique(ad[(particle_type, 'particle_mass')].in_units('Msun/h'))
    total_particles = ad.quantities.total_quantity((particle_type, "particle_ones"))
  
    if MPI.COMM_WORLD.Get_rank()==0:
        print 'Using particle(s) ', particle_types, ' with mass(es) ', particle_masses 
        print

    # Get the particle_type field of the star particles, and the min mass of the DM particles    
    dm_masses = []
    star_types = []
    for type in particle_types:
        if  type in recognized_star_types:
            star_types = yt.np.concatenate((star_types, yt.np.unique(ad[(type, 'particle_type')])))
        else:
            dm_masses = \
                yt.np.concatenate((dm_masses,yt.np.unique(ad[(type, 'particle_mass')].in_units('Msun/h'))))
    dm_masses = last_snap.arr(dm_masses.value, 'Msun/h')
    dm_min_mass = dm_masses.min()

    # In not multi mass select only the DM particles with the min mass
    if not multi_mass and len(particle_masses) > 1:
        @yt.particle_filter('hires_particles', filtered_type=particle_type, requires=['particle_mass'])
        def _hires_filter(pfilter, data):
            return data['particle_mass'] == dm_min_mass

        def setup_ds(ds):
            if punion: ds.add_particle_union(punion)
            ds.add_particle_filter('hires_particles')

        particle_type = 'hires_particles'    
    else:
        def setup_ds(ds):
            if punion: ds.add_particle_union(punion)

    # Remove last/first_snap from memory and cache
    if len(ts) > 1 : del first_snap
    del last_snap
    _cached_datasets.clear()

    # Pass the setup_function to the time series  
    ts._setup_function=setup_ds
    
    # Run rockstar         
    rh = RockstarHaloFinder(ts, 
                            num_readers=num_readers,
                            num_writers=None,
                            outbase=out_dir,
                            particle_type=particle_type,
                            star_types=star_types,
                            multi_mass=multi_mass,
                            force_res=force_res, 
                            initial_metric_scaling=initial_metric_scaling,
                            particle_mass=dm_min_mass,
                            total_particles=total_particles)
    MPI.COMM_WORLD.barrier()    
    rh.run()
    MPI.COMM_WORLD.barrier()

    if MPI.COMM_WORLD.Get_rank()==0:
        print 'Successfully finished Rockstar analysis in ', sim_dir
        print
コード例 #8
0
from mpi4py import MPI
import yt
from yt.analysis_modules.halo_finding.rockstar.api import \
    RockstarHaloFinder
from yt.data_objects.particle_filters import \
    particle_filter
yt.enable_parallelism()

comm = MPI.Comm.Get_parent()

@particle_filter("dark_matter", requires=["creation_time"])
def _dm_filter(pfilter, data):
    return data["creation_time"] <= 0.0

def setup_ds(ds):
    ds.add_particle_filter("dark_matter")

es = yt.simulation("Enzo_64/64.param", "Enzo")
es.get_time_series(setup_function=setup_ds,
                   redshifts=[1., 0.])

rh = RockstarHaloFinder(es, num_readers=1, num_writers=1,
                        particle_type="dark_matter")
rh.run()

comm.Disconnect()