SubhaloMockFactory

class halotools.empirical_models.SubhaloMockFactory(**kwargs)[source] [edit on github]

Bases: halotools.empirical_models.MockFactory

Class responsible for populating a simulation with a population of mock galaxies based on models generated by SubhaloModelFactory.

Can be thought of as a factory that takes a model and simulation halocat as input, and generates a mock galaxy population. The returned collection of galaxies possesses whatever attributes were requested by the model, such as xyz position, central/satellite designation, star-formation rate, etc.

See Tutorial on the algorithm for subhalo-based mock-making for an in-depth tutorial on the mock-making algorithm.

Parameters:

halocat : object, keyword argument

Object containing the halo catalog and other associated data. Produced by CachedHaloCatalog

model : object, keyword argument

A model built by a sub-class of SubhaloModelFactory.

populate : boolean, optional

If set to False, the class will perform all pre-processing tasks but will not call the model to populate the galaxy_table with mock galaxies and their observable properties. Default is True.

Methods Summary

populate([seed]) Method populating subhalos with mock galaxies.
precompute_galprops() Method pre-processes the input subhalo catalog, and pre-computes all halo properties that will be inherited by the galaxy_table.
preprocess_halo_catalog(halocat) Method to pre-process a halo catalog upon instantiation of the mock object.

Methods Documentation

populate(seed=None)[source] [edit on github]

Method populating subhalos with mock galaxies.

By calling the populate method of your mock, you will repopulate the halo catalog with a new realization of the model based on whatever values of the model parameters are currently stored in the param_dict of the model.

For an in-depth discussion of how this method is implemented, see the Tutorial on the algorithm for subhalo-based mock-making section of the documentation.

Parameters:

seed : int, optional

Random number seed used in the Monte Carlo realization. Default is None, which will produce stochastic results.

Notes

Note the difference between the halotools.empirical_models.SubhaloMockFactory.populate method and the closely related method halotools.empirical_models.SubhaloModelFactory.populate_mock. The populate_mock method is bound to a composite model instance and is called the first time a composite model is used to generate a mock. Calling the populate_mock method creates the SubhaloMockFactory instance and binds it to composite model. From then on, if you want to repopulate a new Universe with the same composite model, you should instead call the populate method bound to model.mock. The reason for this distinction is that calling populate_mock triggers a large number of relatively expensive pre-processing steps and self-consistency checks that need only be carried out once. See the Examples section below for an explicit demonstration.

In particular, if you are running an MCMC type analysis, you will choose your halo catalog and completeness cuts, and call populate_mock with the appropriate arguments. Thereafter, you can explore parameter space by changing the values stored in the param_dict dictionary attached to the model, and then calling the populate method bound to model.mock. Any changes to the param_dict of the model will automatically propagate into the behavior of the populate method.

Normally, repeated calls to the populate method should not increase the RAM usage of halotools because a new mock catalog is created and the old one deleted. However, on certain machines the memory usage was found to increase over time. If this is the case and memory usage is critical you can try calling gc.collect() immediately following the call to mock.populate to manually invoke python’s garbage collection.

Examples

>>> from halotools.empirical_models import PrebuiltSubhaloModelFactory
>>> model_instance = PrebuiltSubhaloModelFactory('behroozi10')

Here we will use a fake simulation, but you can populate mocks using any instance of CachedHaloCatalog or UserSuppliedHaloCatalog.

>>> from halotools.sim_manager import FakeSim
>>> halocat = FakeSim()
>>> model_instance.populate_mock(halocat)

Your model_instance now has a mock attribute bound to it. You can call the populate method bound to the mock, which will repopulate the halo catalog with a new Monte Carlo realization of the model.

>>> model_instance.mock.populate()

If you want to change the behavior of your model, just change the values stored in the param_dict. Differences in the parameter values will change the behavior of the mock-population.

>>> model_instance.param_dict['scatter_model_param1'] = 0.25
>>> model_instance.mock.populate()
precompute_galprops()[source] [edit on github]

Method pre-processes the input subhalo catalog, and pre-computes all halo properties that will be inherited by the galaxy_table.

For example, in subhalo-based models, the phase space coordinates of the galaxies are hard-wired to be equal to the phase space coordinates of the parent subhalos, so these keys of the galaxy_table can be pre-computed once and for all.

Additionally, a feature of some composite models may have explicit dependence upon the type of halo/galaxy. The gal_type_func mechanism addresses this potential need by adding an additional column(s) to the galaxy_table. These additional columns can also be pre-computed as halo types do not depend upon model parameter values.

preprocess_halo_catalog(halocat)[source] [edit on github]

Method to pre-process a halo catalog upon instantiation of the mock object.