flaminkit.core ============== .. py:module:: flaminkit.core Functions --------- .. autoapisummary:: flaminkit.core.halofile flaminkit.core.infalling_groups flaminkit.core.particles_around flaminkit.core._find_particles_around flaminkit.core.subhalos_in_clusters flaminkit.core.subhalo_particle_statistic flaminkit.core.output_file flaminkit.core.parse_args flaminkit.core.read_args Module Contents --------------- .. py:function:: halofile(args, info=True) Name of file containing halo information, based on command-line arguments Parameters ---------- args : output of ``parse_args`` Returns ------- halofile: ``str`` filename .. py:function:: infalling_groups(halofile, cluster_mass_min=0, cluster_mass_max=np.inf, clusters=None, distance_max=5, group_mass_min=0, n=None, overdensity='200_crit', so_cols=None, random_seed=None) Find groups falling into a sample of clusters This function looks for all clusters in the chosen mass range that are the most massive cluster within ``distance_max`` and then identifies all groups around them. Here, groups are defined simply by a lower mass cut. The cluster center is taken as the center of mass. Parameters ---------- halofile : ``str`` hdf5 file name cluster_mass_min, cluster_mass_max : ``float``, optional minimum and maximum spherical overdensity cluster mass, in solar masses distance_max : ``float`` maximum 3d distance around which to search for groups, in units of the ``SORadius`` specified by ``overdensity`` group_mass_min : ``float``, optional minimum infall group mass n : ``int``, optional number of clusters to return, chosen randomly given the mass range. If not specified all clusters are returned overdensity : ``str`` spherical overdensity as named in ``halofile`` so_cols : ``list``, optional list of spherical overdensity columns to include in addition to ``TotalMass`` -- NOT YET IMPLEMENTED random_seed : ``int``, optional random seed used to select ``n`` clusters, if applicable. Returns ------- main_clusters: ``pd.DataFrame`` most massive clusters within their own ``distance_max * SORadius``. If ``clusters`` is provided this will be a subset of it infallers : ``pd.DataFrame`` infalling groups .. py:function:: particles_around(particle_file, coords, dmax, particle_type, dmin=0 * unyt.Mpc, squeeze=True, progress=True, nthreads=1) Find particles no further than a given distance from sets of coordinates Parameters ---------- particle_file : ``str`` coords : ``unyt.unyt_array``, `shape: (N, 3)` coordinates of interest dmax : ``unyt.unyt_quantity`` maximum 3d distance to include particles particle_type : `iterable` items must be any subset of ``("dm", "gas", "stars")`` dmin : ``unyt.unyt_quantity``, optional minimum 3d distance squeeze : ``bool`` return squeezed array if only one particle type is provided progress : ``bool`` whether to show a progress bar. Disabled if ``nthreads>1`` nthreads : ``int`` number of threads to use to match particles. Returns ------- particles : ``swiftsimio.reader.SWIFTDataset`` or list Loaded particles within cubical masks matching : ``list`` of ``np.ndarray``, each with ``len = len(coords)`` List of indices pointing to ``particles`` corresponding to all particles around each subhalo within the distance constraints .. py:function:: _find_particles_around(particle_coords, xyz, dmid, rng, idx=None) Helper function for ``particles_around`` .. py:function:: subhalos_in_clusters(halofile, cluster_mask=None, clusters=None, n=None, subhalo_mask=None, overdensity='200_crit', subhalo_cols=None, so_cols=None, random_seed=None, subsample_by=None) Find subhalos within a given cluster population .. note:: Only works with HBT+ catalogs for now Parameters ---------- halofile : ``str`` hdf5 file name cluster_mass_min, cluster_mass_max : ``float``, optional minimum and maximum spherical overdensity cluster mass, in Msun cluster_mask : ``dict``, optional minimum and maximum values for cluster propoerties. Each entry in the dictionary should correspond to a ``Dataset`` name in ``halofile``, and its value correspond to an iterable with elements ``(vmin,vmax)``. The mask is applied as ``vmin <= x < vmax``. Ignored if ``clusters`` is provided. For instance, :: cluster_mask = {"SO/200_crit/TotalMass": (1e15, np.inf)} clusters : ``pd.DataFrame``, optional cluster sample. Must contain at least the columns ``(HostFOFId,CentreOfMass_x,CentreOfMass_y,CentreOfMass_z)`` n : ``int``, optional number of clusters to return, chosen randomly given the mass range. If not specified all clusters that comply with ``cluster_mask`` are returned subhalo_mask : ``dict``, optional minimum and maximum subhalo values, given as an iterable of ``(vmin, vmax)`` for each desired column. Dictionary keys can be any subset of columns from ``BoundSubhalo``. The mask is applied as ``vmin <= x < vmax`` overdensity : ``str`` spherical overdensity as named in ``halofile`` subhalo_cols : ``list``, optional list of columns from ``BoundSubhalo`` to include in addition to ``(HostFOFId,TrackId,Depth)``. Because the object returned is a ``pd.DataFrame``, columns with more than one dimension are not yet supported so_cols : ``list``, optional list of spherical overdensity columns to include in addition to ``TotalMass``. Ignored if ``clusters`` is provided random_seed : ``int``, optional subsample_by : ``str``, optional if subsampling the catalog (for quick runs), specifies a column name, which must be present in the catalog, and the ``n`` first entries in that column will be used. Otherwise the subsampling will be random Returns ------- cluster_galaxies : ``pd.DataFrame`` galaxies within clusters .. py:function:: subhalo_particle_statistic(particle_data, subhalo_particles, statistic, weights=None, **kwargs) Calculate subhalo properties from the particle distribution Parameters ---------- particle_data : ``swiftsimio.objects.cosmo_array`` particle property, i.e., column from a ``swiftsimio.reader.SWIFTDataset`` subhalo_particles : ``np.ndarray`` or ``list`, `len: N` list of indices or masks relating elements of ``particle_data`` to each subhalo statistic : ``callable`` function to apply to the particles of each subhalo. weights : ``swiftsimio.objects.cosmo_array`` or ``np.ndarray``, optional weights applied to obtain a weighted statistic kwargs : ``dict``, optional additional arguments passed to ``statistic``. Note that if this includes another ``swiftsimio.objects.cosmo_array`` (e.g., as weights) it is recommended to give the ``ndarray_view`` to ensure proper behaviour Returns ------- subhalo_property : ``np.ndarray``, `shape: (N,)` subhalo property obtained from the particles Notes ----- - If a property has more than one dimension (e.g., a position or velocity) it is easiest to pass each array to this function separately as :: mean_velocity = [subhalo_particle_statistic( particles.velocities[:,i], subhalo_particles, np.mean) for i in range(3)] .. py:function:: output_file(args, root, ext=None) .. py:function:: parse_args(args=None) Parse command-line arguments Parameters ---------- args : ``list``-like, optional additional arguments to include in the parser. Each element in ``args`` should contain two elements: the string(s) enabling the argument and the kwargs to add it to the parser. For instance, :: args=(('--foo', {'type': int, 'default': 1}), ('--bar', {'action': 'store_true'})) Returns ------- args : output of `parser.parse_args` .. py:function:: read_args() Set up the base command-line arguments Call this function from any program if there are additional command-line arguments in it (to be added manually from that program) Note that any program might ignore any of these default command-line arguments if only a subset are relevant Returns ------- parser : ``argparse.ArgumentParser`` object