def clump_tracker(fprefix, param=None, directory=None, nsmooth=32, verbose=True): """ Finds and tracks clumps over a simulation with multiple time steps and calculates various physical properties of the clumps. Runs all the steps necessary to find/track clumps, these are: get_fnames pFind_clumps pClump_properties pLink2 multilink build_clumps If the iord property is not found, the linking will only work if the number of particles remains constant through the simulation **ARGUMENTS** fprefix : str Prefix of the simulation outputs param : str (recommended) Filename of a .param file for the simulation directory : str (optional) Directory to search through. Default is current working directory nsmooth : int (optional) Number of nearest neighbors used for particle smoothing in the simulation. This is used in the definition of a density threshold for clump finding. verbose : bool (optional) Verbosity flag. Default is True **RETURNS** clump_list : list A list containing dictionaries for all clumps foujohn obryan fiddlend in the simulation See clump_properties for a list of the properties calculated for clumps """ # Get a list of all snapshot files fnames = get_fnames(fprefix, directory) nfiles = len(fnames) # Run the clump (halo) finder if verbose: print "\n\nRunning clump finder on {} files\n\n".format(nfiles) clumpnum_list = pFind_clumps(fnames, nsmooth, param, verbose=verbose) nclumps = np.zeros(nfiles, dtype=int) for i, clumpnums in enumerate(clumpnum_list): nclumps[i] = clumpnums.max() if nclumps.max() <= 0: if verbose: print 'No clumps found' return [] # Calculate the physical properties of the clumps if verbose: print "\n\nCalculating the physical of properties of clumps\n\n" properties = pClump_properties(fnames, clumpnum_list) # Link clumps on consecutive time-steps if verbose: print "\n\nLinking Clumps\n\n" link_list = pLink2(properties) # Link on multiple time-steps multilink_list = multilink(link_list) # Build the clumps clump_list = build_clumps(multilink_list, properties, fnames, param) return clump_list
def pSpiralpower_t(simdirs, fprefix, rbins=100, thetabins=100, binspacing='log', \ rlim=None, paramnames=None, center=True): """ Parallel implementation of spiralpower_t for looping over simulation diretories. Assumes simulation outputs are standard ChaNGa format. Only simdirs and paramnames can change from simulation to simulation. See spiralpower_t for other parameters Parameters ---------- simdirs : list or arraylike list of simulation directories (strings) fprefix : str or list prefix or prefixes of simulation snapshots (see pychanga.get_fnames) **kwargs See spiralpower_t for other parameters Returns ------- output : dict Output for every simulation (see spiralpower_t) """ nSim = len(simdirs) if not hasattr(paramnames, '__iter__'): paramnames = nSim*[paramnames] if not hasattr(fprefix, '__iter__'): fprefix = nSim * [fprefix] # Generate the list of arguments for each simulation arglist = [] for i in range(nSim): flist = get_fnames(fprefix[i], simdirs[i]) paramname = paramnames[i] arglist.append([flist, rbins, thetabins, binspacing, rlim, paramname, \ center]) pool = Pool(cpu_count()) try: results = pool.map(_spiralpower_t, arglist, chunksize=1) finally: pool.close() pool.join() power = [] t = [] r = [] for result in results: power.append(result[0]) t.append(result[1]) r.append(result[2]) output = {'power':power, 't': t, 'r': r} return output
def pSpiralpower_t(simdirs, fprefix, rbins=100, thetabins=100, binspacing='log', \ rlim=None, paramnames=None, center=True): """ Parallel implementation of spiralpower_t for looping over simulation diretories. Assumes simulation outputs are standard ChaNGa format. Only simdirs and paramnames can change from simulation to simulation. See spiralpower_t for other parameters Parameters ---------- simdirs : list or arraylike list of simulation directories (strings) fprefix : str or list prefix or prefixes of simulation snapshots (see pychanga.get_fnames) **kwargs See spiralpower_t for other parameters Returns ------- output : dict Output for every simulation (see spiralpower_t) """ nSim = len(simdirs) if not hasattr(paramnames, '__iter__'): paramnames = nSim * [paramnames] if not hasattr(fprefix, '__iter__'): fprefix = nSim * [fprefix] # Generate the list of arguments for each simulation arglist = [] for i in range(nSim): flist = get_fnames(fprefix[i], simdirs[i]) paramname = paramnames[i] arglist.append([flist, rbins, thetabins, binspacing, rlim, paramname, \ center]) pool = Pool(cpu_count()) try: results = pool.map(_spiralpower_t, arglist, chunksize=1) finally: pool.close() pool.join() power = [] t = [] r = [] for result in results: power.append(result[0]) t.append(result[1]) r.append(result[2]) output = {'power': power, 't': t, 'r': r} return output