SubhaloMockFactory¶
- class halotools.empirical_models.SubhaloMockFactory(**kwargs)[source]¶
Bases:
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:
- halocatobject, keyword argument
Object containing the halo catalog and other associated data. Produced by
CachedHaloCatalog
- modelobject, keyword argument
A model built by a sub-class of
SubhaloModelFactory
.- populateboolean, optional
If set to
False
, the class will perform all pre-processing tasks but will not call themodel
to populate thegalaxy_table
with mock galaxies and their observable properties. Default isTrue
.
Methods Summary
populate
([seed])Method populating subhalos with mock galaxies.
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]¶
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 theparam_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:
- seedint, 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 methodhalotools.empirical_models.SubhaloModelFactory.populate_mock
. Thepopulate_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 thepopulate_mock
method creates theSubhaloMockFactory
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 thepopulate
method bound tomodel.mock
. The reason for this distinction is that callingpopulate_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 theparam_dict
dictionary attached to the model, and then calling thepopulate
method bound tomodel.mock
. Any changes to theparam_dict
of the model will automatically propagate into the behavior of thepopulate
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 tomock.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
orUserSuppliedHaloCatalog
.>>> from halotools.sim_manager import FakeSim >>> halocat = FakeSim() >>> model_instance.populate_mock(halocat)
Your
model_instance
now has amock
attribute bound to it. You can call thepopulate
method bound to themock
, 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]¶
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.