yt.analysis_modules.halo_analysis.halo_catalog module

HaloCatalog object

class yt.analysis_modules.halo_analysis.halo_catalog.HaloCatalog(halos_ds=None, data_ds=None, data_source=None, finder_method=None, finder_kwargs=None, output_dir='halo_catalogs/catalog')[source]

Bases: yt.utilities.parallel_tools.parallel_analysis_interface.ParallelAnalysisInterface

Create a HaloCatalog: an object that allows for the creation and association of data with a set of halo objects.

A HaloCatalog object pairs a simulation dataset and the output from a halo finder, allowing the user to perform analysis on each of the halos found by the halo finder. Analysis is performed by providing callbacks: functions that accept a Halo object and perform independent analysis, return a quantity to be associated with the halo, or return True or False whether a halo meets various criteria. The resulting set of quantities associated with each halo is then written out to disk at a “halo catalog.” This halo catalog can then be loaded in with yt as any other simulation dataset.

Parameters:
  • halos_ds (str) – Dataset created by a halo finder. If None, a halo finder should be provided with the finder_method keyword.
  • data_ds (str) – Dataset created by a simulation.
  • data_source (data container) – Data container associated with either the halos_ds or the data_ds.
  • finder_method (str) – Halo finder to be used if no halos_ds is given.
  • output_dir (str) – The top level directory into which analysis output will be written. Default: ”.”
  • finder_kwargs (dict) – Arguments to pass to the halo finder if finder_method is given.

Examples

>>> # create profiles or overdensity vs. radius for each halo and save to disk
>>> import yt
>>> from yt.analysis_modules.halo_analysis.api import *
>>> data_ds = yt.load("DD0064/DD0064")
>>> halos_ds = yt.load("rockstar_halos/halos_64.0.bin",
...                    output_dir="halo_catalogs/catalog_0064")
>>> hc = HaloCatalog(data_ds=data_ds, halos_ds=halos_ds)
>>> # filter out halos with mass < 1e13 Msun
>>> hc.add_filter("quantity_value", "particle_mass", ">", 1e13, "Msun")
>>> # create a sphere object with radius of 2 times the virial_radius field
>>> hc.add_callback("sphere", factor=2.0, radius_field="virial_radius")
>>> # make radial profiles
>>> hc.add_callback("profile", "radius", [("gas", "overdensity")],
...                 weight_field="cell_volume", accumulation=True)
>>> # save the profiles to disk
>>> hc.add_callback("save_profiles", output_dir="profiles")
>>> # create the catalog
>>> hc.create()
>>> # load in the saved halo catalog and all the profile data
>>> halos_ds = yt.load("halo_catalogs/catalog_0064/catalog_0064.0.h5")
>>> hc = HaloCatalog(halos_ds=halos_ds,
                     output_dir="halo_catalogs/catalog_0064")
>>> hc.add_callback("load_profiles", output_dir="profiles")
>>> hc.load()
add_callback(callback, *args, **kwargs)[source]

Add a callback to the halo catalog action list.

A callback is a function that accepts and operates on a Halo object and does not return anything. Callbacks must exist within the callback_registry. Give additional args and kwargs to be passed to the callback here.

Parameters:callback (string) – The name of the callback.

Examples

>>> # Here, a callback is defined and added to the registry.
>>> def _say_something(halo, message):
...     my_id = halo.quantities['particle_identifier']
...     print "Halo %d: here is a message - %s." % (my_id, message)
>>> add_callback("hello_world", _say_something)
>>> # Now this callback is accessible to the HaloCatalog object
>>> hc.add_callback("hello_world", "this is my message")
add_default_quantities(field_type='halos')[source]
add_filter(halo_filter, *args, **kwargs)[source]

Add a filter to the halo catalog action list.

A filter is a function that accepts a Halo object and returns either True or False. If True, any additional actions added to the list are carried out and the results are added to the final halo catalog. If False, any further actions are skipped and the halo will be omitted from the final catalog. Filters must exist within the filter_registry. Give additional args and kwargs to be passed to the filter function here.

Parameters:halo_filter (string) – The name of the filter.

Examples

>>> # define a filter and add it to the register.
>>> def _my_filter(halo, mass_value):
...     return halo.quantities["particle_mass"] > YTQuantity(mass_value, "Msun")
>>> # add it to the register
>>> add_filter("mass_filter", _my_filter)
>>> # add the filter to the halo catalog actions
>>> hc.add_filter("mass_value", 1e12)
add_quantity(key, *args, **kwargs)[source]

Add a quantity to the halo catalog action list.

A quantity is a function that accepts a Halo object and return a value or values. These values are stored in a “quantities” dictionary associated with the Halo object. Quantities must exist within the quantity_registry. Give additional args and kwargs to be passed to the quantity function here.

Parameters:
  • key (string) – The name of the callback.
  • field_type (string) – If not None, the quantity is the value of the field provided by the key parameter, taken from the halo finder dataset. This is the way one pulls values for the halo from the halo dataset. Default : None

Examples

>>> # pull the virial radius from the halo finder dataset
>>> hc.add_quantity("virial_radius", field_type="halos")
>>> # define a custom quantity and add it to the register
>>> def _mass_squared(halo):
...     # assume some entry "particle_mass" exists in the quantities dict
...     return halo.quantities["particle_mass"]**2
>>> add_quantity("mass_squared", _mass_squared)
>>> # add it to the halo catalog action list
>>> hc.add_quantity("mass_squared")
add_recipe(recipe, *args, **kwargs)[source]

Add a recipe to the halo catalog action list.

A recipe is an operation consisting of a series of callbacks, quantities, and/or filters called in succession. Recipes can be used to store a more complex series of analysis tasks as a single entity.

Currently, the available recipe is calculate_virial_quantities.

Parameters:halo_recipe (string) – The name of the recipe.

Examples

>>> import yt
>>> from yt.analysis_modules.halo_analysis.api import HaloCatalog
>>>
>>> data_ds = yt.load('Enzo_64/RD0006/RedshiftOutput0006')
>>> halos_ds = yt.load('rockstar_halos/halos_0.0.bin')
>>> hc = HaloCatalog(data_ds=data_ds, halos_ds=halos_ds)
>>>
>>> # Filter out less massive halos
>>> hc.add_filter("quantity_value", "particle_mass", ">", 1e14, "Msun")
>>>
>>> # Calculate virial radii
>>> hc.add_recipe("calculate_virial_quantities", ["radius", "matter_mass"])
>>>
>>> hc.create()
comm = None
create(save_halos=False, save_catalog=True, njobs=-1, dynamic=False)[source]

Create the halo catalog given the callbacks, quantities, and filters that have been provided.

This is a wrapper around the main _run function with default arguments tuned for halo catalog creation. By default, halo objects are not saved but the halo catalog is written, opposite to the behavior of the load function.

Parameters:
  • save_halos (bool) – If True, a list of all Halo objects is retained under the “halo_list” attribute. If False, only the compiles quantities are saved under the “catalog” attribute. Default: False
  • save_catalog (bool) – If True, save the final catalog to disk. Default: True
  • njobs (int) – The number of jobs over which to divide halo analysis. Choose -1 to allocate one processor per halo. Default: -1
  • dynamic (int) – If False, halo analysis is divided evenly between all available processors. If True, parallelism is performed via a task queue. Default: False

See also

load()

get_dependencies(fields)
load(save_halos=True, save_catalog=False, njobs=-1, dynamic=False)[source]

Load a previously created halo catalog.

This is a wrapper around the main _run function with default arguments tuned for reloading halo catalogs and associated data. By default, halo objects are saved and the halo catalog is not written, opposite to the behavior of the create function.

Parameters:
  • save_halos (bool) – If True, a list of all Halo objects is retained under the “halo_list” attribute. If False, only the compiles quantities are saved under the “catalog” attribute. Default: True
  • save_catalog (bool) – If True, save the final catalog to disk. Default: False
  • njobs (int) – The number of jobs over which to divide halo analysis. Choose -1 to allocate one processor per halo. Default: -1
  • dynamic (int) – If False, halo analysis is divided evenly between all available processors. If True, parallelism is performed via a task queue. Default: False

See also

create()

partition_index_2d(axis)
partition_index_3d(ds, padding=0.0, rank_ratio=1)
partition_index_3d_bisection_list()

Returns an array that is used to drive _partition_index_3d_bisection, below.

partition_region_3d(left_edge, right_edge, padding=0.0, rank_ratio=1)

Given a region, it subdivides it into smaller regions for parallel analysis.

save_catalog()[source]

Write out hdf5 file with all halo quantities.