### Install Specific Release from Source Source: https://github.com/astropy/halotools/blob/master/docs/install.rst Installs a tagged official release (e.g., v0.7) after cloning the repository. Requires checking out the specific tag before installation. ```bash git checkout v0.7 pip install . ``` -------------------------------- ### Install Master Branch from Source Source: https://github.com/astropy/halotools/blob/master/docs/install.rst Installs the latest development version from the master branch after cloning the repository. Use with awareness that the API may not be stable. ```bash git checkout master pip install . ``` -------------------------------- ### Install Halotools using Pip Source: https://github.com/astropy/halotools/blob/master/docs/install.rst Alternative installation method using pip. Conda-forge is generally recommended due to its more robust dependency solver. ```bash pip install halotools ``` -------------------------------- ### Build Halotools Documentation with Tox Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/development/getting_started.rst This command builds the project's documentation using tox. Make sure tox is installed and the documentation environment is set up. ```bash tox -e build_docs ``` -------------------------------- ### Binning Host Halo Masses Source: https://github.com/astropy/halotools/blob/master/docs/notebooks/galcat_analysis/intermediate_examples/quenching_gradient_tutorial.ipynb Prepares bins and midpoints for analyzing the quiescent fraction as a function of host halo mass. This is a setup step for further analysis. ```python from scipy.stats import binned_statistic log_mhost_bins = np.linspace(11, 14.85, 25) mhost_bins = 10**log_mhost_bins mhost_mids = 10**(0.5*(log_mhost_bins[:-1]+log_mhost_bins[1:])) quiescent_fraction1, __, __ = binned_statistic(sats['halo_mvir_host_halo'], ``` -------------------------------- ### Install Halotools using Conda-Forge Source: https://github.com/astropy/halotools/blob/master/docs/install.rst Recommended method for installing the latest release of Halotools. Ensure your environment is activated if using a virtual environment. ```bash conda install -c conda-forge halotools ``` -------------------------------- ### Build Behroozi et al. (2010) Model Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/preloaded_models/behroozi10_composite_model.rst Instantiate the 'behroozi10' composite subhalo model using the PrebuiltSubhaloModelFactory. This is the basic way to get started with the model. ```python from halotools.empirical_models import PrebuiltSubhaloModelFactory model = PrebuiltSubhaloModelFactory('behroozi10') ``` -------------------------------- ### Instantiate and Populate Zheng07 Model Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/preloaded_models/zheng07_composite_model.rst Demonstrates how to create a FakeSim, instantiate the 'zheng07' HOD model, and populate the mock simulation with galaxies. This is a starting point for generating mock galaxy catalogs. ```python from halotools.sim_manager import FakeSim halocat = FakeSim() model = PrebuiltHodModelFactory('zheng07') model.populate_mock(halocat = halocat) # doctest: +SKIP ``` -------------------------------- ### Building Alternative HOD Model with SubhaloPhaseSpace Source: https://github.com/astropy/halotools/blob/master/docs/usage_tutorials/empirical_models/subhalo_phase_space/subhalo_phase_space_tutorial.rst This example demonstrates how to construct an alternative HOD model by replacing the default satellite profile with a SubhaloPhaseSpace model, allowing satellites to be placed on subhalos instead of tracing an NFW profile. ```python from halotools.empirical_models import PrebuiltHodModelFactory orig_model = PrebuiltHodModelFactory('leauthaud11') from halotools.empirical_models import SubhaloPhaseSpace alt_profile_model = SubhaloPhaseSpace('satellites', np.logspace(10.5, 15.2, 15)) from halotools.empirical_models import HodModelFactory new_model_dictionary = orig_model.model_dictionary new_model_dictionary['satellites_profile'] = alt_profile_model ``` -------------------------------- ### Install Halotools with Clang Compiler on Mac Source: https://github.com/astropy/halotools/blob/master/docs/installation_troubleshooting.rst On Mac, if you encounter issues with the default gcc compiler, try switching to clang for installation. This command temporarily sets the C compiler to clang before installing Halotools. ```bash export CC=clang; pip install halotools ``` -------------------------------- ### Initialize Fake Halo Catalogs Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/catalog_analysis/halocat_analysis/crossmatching_halo_catalogs.rst Generates two fake halo catalogs using FakeSim and extracts their halo tables. This sets up the data for the cross-matching examples. ```python from halotools.sim_manager import FakeSim halocat1 = FakeSim() halo_table1 = halocat1.halo_table halocat2 = FakeSim() mask = halocat2.halo_table['halo_mvir'] > 1e11 halo_table2 = halocat2.halo_table[mask] ``` -------------------------------- ### Run Halotools Tests with Tox Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/development/getting_started.rst Use this command to run the test suite for Halotools. Ensure you have tox installed and configured. ```bash tox -e test ``` -------------------------------- ### Allocate Memory for Galaxy Table Source: https://github.com/astropy/halotools/blob/master/docs/source_notes/empirical_models/factories/hod_mock_factory_source_notes.rst This snippet shows the initialization of the galaxy_table and the setup of the calling sequence for subsequent mock generation methods within the HodMockFactory. ```python def allocate_memory(self): self.galaxy_table = Table() # ``self`` refers to the ``model.mock`` object self._remaining_methods_to_call = copy(self.model._mock_generation_calling_sequence) ``` -------------------------------- ### Populate Mock with Hearin et al. (2015) Model Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/preloaded_models/hearin15_composite_model.rst Populate an N-body simulation with mock galaxy catalogs using the instantiated Hearin et al. (2015) model. This example uses `FakeSim` for demonstration purposes. ```python from halotools.sim_manager import FakeSim halocat = FakeSim() model = PrebuiltHodModelFactory('hearin15') model.populate_mock(halocat) # doctest: +SKIP ``` -------------------------------- ### Import Libraries and Load Halo Catalog Source: https://github.com/astropy/halotools/blob/master/docs/notebooks/galcat_analysis/intermediate_examples/quenching_gradient_tutorial.ipynb Imports necessary libraries and loads a cached halo catalog for a specific simulation and redshift. This is the initial setup for data analysis. ```python %matplotlib inline import numpy as np from matplotlib import pyplot as plt from halotools.sim_manager import CachedHaloCatalog halocat = CachedHaloCatalog(simname='bolplanck', redshift=0) print(halocat.halo_table.keys()) ``` -------------------------------- ### Setting Up HOD Model Components Source: https://github.com/astropy/halotools/blob/master/docs/notebooks/intrinsic_alignments/measuring_correlations_tutorial.ipynb Defines and configures the components for a HOD model, including central and satellite galaxy occupation, phase space distribution, and alignment properties. This setup is for a SubhaloAlignment model for satellites. ```python # MODELS # Alignment Strengths satellite_alignment = 0.6 central_alignment = 0.8 # Central galaxy components cens_occ_model = Zheng07Cens() cens_prof_model = TrivialPhaseSpace() cens_orientation_model = CentralAlignment(central_alignment_strength=central_alignment) # Satellite galaxy Components sats_occ_model = Zheng07Sats() prof_args = ("satellites", np.logspace(10.5, 15.2, 15)) sats_prof_model = SubhaloPhaseSpace(*prof_args, inherited_subhalo_props_dict=alignment_inherited_subhalo_props_dict) sats_orientation_model = SubhaloAlignment(satellite_alignment_strength=satellite_alignment, halocat=halocat) ``` -------------------------------- ### Populate Mock with Zu & Mandelbaum et al. (2016) Model Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/preloaded_models/zu_mandelbaum16_composite_model.rst Populate an N-body simulation with mock galaxy catalogs using the Zu & Mandelbaum et al. (2016) model. This example uses a FakeSim for demonstration purposes. ```python from halotools.sim_manager import FakeSim halocat = FakeSim() model = PrebuiltHodModelFactory('zu_mandelbaum16') model.populate_mock(halocat) # doctest: +SKIP ``` -------------------------------- ### Instantiate HodMockFactory and Populate Mock Source: https://github.com/astropy/halotools/blob/master/docs/source_notes/empirical_models/factories/hod_mock_factory_source_notes.rst Demonstrates the common workflow of creating a PrebuiltHodModelFactory, loading a halo catalog, and populating a mock galaxy catalog. ```python from halotools.empirical_models import PrebuiltHodModelFactory zheng07_model = PrebuiltHodModelFactory('zheng07') from halotools.sim_manager import CachedHaloCatalog default_halocat = CachedHaloCatalog() zheng07_model.populate_mock(default_halocat) ``` -------------------------------- ### Build Documentation Locally Source: https://github.com/astropy/halotools/wiki/Building-the-documentation Run this command to build the documentation locally. The `-o` flag will automatically open the documentation in your browser. ```bash python setup.py build_sphinx -o ``` -------------------------------- ### Load Prebuilt Subhalo Model and Halo Catalog Source: https://github.com/astropy/halotools/blob/master/docs/notebooks/galcat_analysis/basic_examples/galaxy_catalog_analysis_tutorial3.ipynb Initializes a PrebuiltSubhaloModelFactory and loads a CachedHaloCatalog. This is the first step in setting up the mock galaxy population. ```python from halotools.empirical_models import PrebuiltSubhaloModelFactory model = PrebuiltSubhaloModelFactory('behroozi10') from halotools.sim_manager import CachedHaloCatalog halocat = CachedHaloCatalog(simname='bolshoi', redshift=0, halo_finder='rockstar') model.populate_mock(halocat) ``` -------------------------------- ### Find Halotools Installation Location Source: https://github.com/astropy/halotools/blob/master/docs/install.rst Determine the file path of the active Halotools installation to resolve version conflicts. ```python import halotools print(halotools.__file__) ``` -------------------------------- ### Generate Mock Galaxy Catalog with Prebuilt Model Source: https://github.com/astropy/halotools/blob/master/docs/notebooks/galcat_analysis/intermediate_examples/galaxy_catalog_intermediate_analysis_tutorial1.ipynb Initializes a prebuilt subhalo model for generating mock galaxy catalogs. This is the first step in creating a mock universe. ```python from halotools.empirical_models import PrebuiltSubhaloModelFactory model = PrebuiltSubhaloModelFactory('smhm_binary_sfr') ``` -------------------------------- ### Custom Concentration-Mass Relation Example Source: https://github.com/astropy/halotools/blob/master/docs/source_notes/empirical_models/phase_space_models/nfw_profile_source_notes.rst Example of how to define and use a custom concentration-mass relation with the NFWPhaseSpace class. This function takes a table and returns a constant concentration value. ```python def custom_conc_mass(table): mass = table['halo_mvir'] return np.zeros_like(mass) + 5. nfw_model = NFWPhaseSpace(conc_mass_model=custom_conc_mass) ``` -------------------------------- ### Clone Halotools Repository Source: https://github.com/astropy/halotools/blob/master/docs/install.rst Initial step for building Halotools from source. Clones the repository and navigates into the directory. ```bash git clone https://github.com/astropy/halotools.git cd halotools ``` -------------------------------- ### Minimal HOD Occupation Component Example Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/composing_models/hod_modeling/writing_your_own_hod_occupation_component.rst A basic example demonstrating the structure of a custom occupation component. It subclasses `OccupationComponent` and defines a `mean_occupation` method that returns a constant probability. ```python from halotools.empirical_models import OccupationComponent class MyCentralOccupation(OccupationComponent): def __init__(self, gal_type, threshold): OccupationComponent.__init__(self, gal_type = gal_type, threshold = threshold, upper_occupation_bound = 1) def mean_occupation(self, **kwargs): table = kwargs['table'] return np.zeros(len(table)) + 0.1 ``` -------------------------------- ### Populating Mock Catalogs with a New Model Source: https://github.com/astropy/halotools/blob/master/docs/usage_tutorials/empirical_models/subhalo_phase_space/subhalo_phase_space_tutorial.rst Demonstrates how to create a new Halotools composite model and use it to populate a mock catalog. It also shows how to populate a mock catalog with an original model for comparison. ```python from halotools.sim_manager import CachedHaloCatalog halocat = CachedHaloCatalog(simname='bolplanck') new_model.populate_mock(halocat, seed=43) orig_model.populate_mock(halocat, seed=43) ``` -------------------------------- ### Check Halotools Version Source: https://github.com/astropy/halotools/blob/master/docs/install.rst Verify the installed version of the Halotools package. ```python import halotools print(halotools.__version__) ``` -------------------------------- ### Instantiate and Populate Mock Model Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/mock_observations/mock_obs_pos_formatting.rst Instantiates a prebuilt subhalo model and populates it with a fake simulation catalog. This sets up the mock object with a galaxy table. ```python model = PrebuiltSubhaloModelFactory('smhm_binary_sfr') from halotools.sim_manager import FakeSim halocat = FakeSim() model.populate_mock(halocat) ``` -------------------------------- ### Example of _galprop_dtypes_to_allocate usage Source: https://github.com/astropy/halotools/blob/master/docs/source_notes/empirical_models/factories/model_factory_composite_sequence_mechanisms.rst Instances of your model component must have a `_galprop_dtypes_to_allocate` attribute. Assign any `numpy.dtype` object to this attribute during the `__init__` constructor. ```python import numpy as np class MyComponent: def __init__(self, **kwargs): # ... other initialization self._galprop_dtypes_to_allocate = np.dtype(float) # or any other numpy dtype # ... rest of initialization ``` -------------------------------- ### Modify Model Parameters Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/preloaded_models/zheng07_composite_model.rst Alter model parameters after instantiation by modifying the param_dict. This example changes the minimum halo mass for hosting a central galaxy. ```python model.param_dict['logMmin'] = 12.5 ``` -------------------------------- ### Instantiate and Populate Subhalo Mock Source: https://github.com/astropy/halotools/blob/master/docs/source_notes/empirical_models/factories/subhalo_mock_factory_source_notes.rst Demonstrates the common usage pattern for creating a SubhaloMockFactory instance and populating it with mock galaxies using a pre-built model and a cached halo catalog. ```python from halotools.empirical_models import PrebuiltSubhaloModelFactory behroozi10_model = PrebuiltSubhaloModelFactory('behroozi10') from halotools.sim_manager import CachedHaloCatalog default_halocat = CachedHaloCatalog() behroozi10_model.populate_mock(default_halocat) ``` -------------------------------- ### Create and Populate HodModelFactory Source: https://github.com/astropy/halotools/blob/master/docs/notebooks/intrinsic_alignments/measuring_correlations_tutorial.ipynb Initializes a HodModelFactory with specified occupation and profile models, then populates the mock galaxy catalog. ```python model_instance = HodModelFactory(centrals_occupation = cens_occ_model, centrals_profile = cens_prof_model, satellites_occupation = sats_occ_model, satellites_profile = sats_prof_model, centrals_orientation = cens_orientation_model, satellites_orientation = sats_orientation_model, model_feature_calling_sequence = ( 'centrals_occupation', 'centrals_profile', 'satellites_occupation', 'satellites_profile', 'centrals_orientation', 'satellites_orientation') ) #seed=132358712 seed=None model_instance.populate_mock(halocat, seed=seed) ``` -------------------------------- ### Create a Mock Galaxy Population Source: https://github.com/astropy/halotools/blob/master/README.rst This snippet demonstrates how to select a pre-built HOD model and a halo catalog, then populate the catalog with a mock galaxy population. ```python from halotools.empirical_models import PrebuiltHodModelFactory model = PrebuiltHodModelFactory('zheng07') from halotools.sim_manager import CachedHaloCatalog halocat = CachedHaloCatalog(simname='bolshoi', redshift=0, halo_finder='rockstar') model.populate_mock(halocat) ``` -------------------------------- ### Modify Cacciato et al. (2009) Model Parameter Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/preloaded_models/cacciato09_composite_model.rst Change model parameters after instantiation by modifying the 'param_dict'. This example changes the scatter in the mass-to-light ratio. ```python model.param_dict['sigma'] = 0.2 ``` -------------------------------- ### Initialize DownloadManager Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/quickstart_guides/working_with_halotools_provided_catalogs.rst Import and instantiate the DownloadManager class to manage catalog downloads. ```python from halotools.sim_manager import DownloadManager dman = DownloadManager() ``` -------------------------------- ### Define a custom central occupation model Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/composing_models/hod_modeling/zheng07_using_cenocc_model_tutorial.rst Create a new OccupationComponent subclass for central galaxies. This example defines a trivial model with a single parameter 'new_cen_param'. ```python from halotools.empirical_models import OccupationComponent class MyCenModel(OccupationComponent): def __init__(self, threshold): OccupationComponent.__init__(self, gal_type='centrals', threshold=threshold, upper_occupation_bound=1.) self.param_dict['new_cen_param'] = 0.5 def mean_occupation(self, **kwargs): halo_table = kwargs['table'] result = np.zeros(len(halo_table)) + self.param_dict['new_cen_param'] return result ``` -------------------------------- ### Build Documentation Locally (Offline) Source: https://github.com/astropy/halotools/wiki/Building-the-documentation Use this command to build the documentation when an internet connection is unavailable. The `-o` flag will automatically open the documentation in your browser. ```bash python setup.py --offline build_sphinx -o ``` -------------------------------- ### Instantiate Pre-built HOD Model Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/getting_started_overview.rst Shows how to instantiate a pre-built HOD model factory for galaxy-halo connection studies. ```python from halotools.empirical_models import PrebuiltHodModelFactory zheng07_model = PrebuiltHodModelFactory('zheng07', threshold = -19.5, redshift = 0.5) ``` -------------------------------- ### Load Halo Catalog and Get Properties Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/cam_tutorial_pages/cam_tutorial.rst Loads the CachedHaloCatalog for a specific simulation and redshift, then extracts halo mass and accretion rate. Requires halotools library. ```python from halotools.sim_manager import CachedHaloCatalog halocat = CachedHaloCatalog(simname='bolplanck', redshift=0) halo_mass = halocat.halo_table['halo_mvir'] from halotools.empirical_models import Behroozi10SmHm model = Behroozi10SmHm(redshift=0) halo_mstar = model.mc_stellar_mass(prim_haloprop=halo_mass) halo_acc_rate = halocat.halo_table['halo_dmvir_dt_100myr'] ``` -------------------------------- ### Command-line Download Script Usage Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/quickstart_guides/working_with_halotools_provided_catalogs.rst Illustrates how to use the command-line script for downloading halo catalogs. Use the --help flag to see the full argument list. ```bash python scripts/download_additional_halocat.py --help ``` -------------------------------- ### Initialize Mock Galaxy Catalog Source: https://github.com/astropy/halotools/blob/master/docs/notebooks/galcat_analysis/basic_examples/galaxy_catalog_analysis_tutorial4.ipynb Loads a pre-built HOD model and a cached halo catalog to populate a mock galaxy population. Requires `PrebuiltHodModelFactory` and `CachedHaloCatalog`. ```python from halotools.empirical_models import PrebuiltHodModelFactory model = PrebuiltHodModelFactory('tinker13', threshold = 10.25) from halotools.sim_manager import CachedHaloCatalog halocat = CachedHaloCatalog(simname='bolshoi', redshift=0, halo_finder='rockstar') model.populate_mock(halocat) ``` -------------------------------- ### Example Usage of Leauthaud11 Model Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/preloaded_models/leauthaud11_composite_model.rst This snippet demonstrates how to use the Leauthaud11 composite model to infer halo mass from stellar mass. Ensure the model is properly instantiated before use. ```python >>> inferred_log_halo_mass = model.mean_log_halo_mass_centrals(log_stellar_mass) ``` -------------------------------- ### Populate Mock with Halo Catalog Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/getting_started_overview.rst Populates a pre-built galaxy-halo model with data from a halo catalog. ```python zheng07_model.populate_mock(halocat) # doctest: +SKIP ``` -------------------------------- ### Composing Models with a New Component Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/composing_models/subhalo_modeling/subhalo_modeling_tutorial4.rst Incorporate a new component model into a composite model using SubhaloModelFactory. This example shows how to add a 'shape' component to an existing 'behroozi10' model. ```python galaxy_shape = Shape('halo_mvir') from halotools.empirical_models import PrebuiltSubhaloModelFactory, SubhaloModelFactory behroozi_model = PrebuiltSubhaloModelFactory('behroozi10') new_model = SubhaloModelFactory(baseline_model_instance = behroozi_model, shape = galaxy_shape) ``` -------------------------------- ### Populating Alternative Halo Catalog with HodModelFactory Source: https://github.com/astropy/halotools/blob/master/docs/source_notes/empirical_models/factories/hod_model_factory_source_notes.rst Illustrates how to populate a specific, alternative halo catalog using the populate_mock method. This can be used with any instance of CachedHaloCatalog or UserSuppliedHaloCatalog. ```python from halotools.sim_manager import CachedHaloCatalog my_halocat = CachedHaloCatalog(simname = my_simname, redshift = my_redshift) model.populate_mock(my_halocat) ``` -------------------------------- ### Modify Leauthaud et al. (2011) Model Parameters Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/preloaded_models/leauthaud11_composite_model.rst Change model parameters after instantiation by modifying the 'param_dict'. This example changes the power law slope for satellite occupation number. ```python model.param_dict['alphasat'] = 1.1 ``` -------------------------------- ### Generate Mock Galaxy Catalog Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/catalog_analysis/galcat_analysis/basic_examples/clustering_examples/galaxy_catalog_analysis_tutorial9.rst Initializes a mock galaxy catalog using a prebuilt model and a cached halo catalog. Requires Halotools library. ```python from halotools.empirical_models import PrebuiltSubhaloModelFactory model = PrebuiltSubhaloModelFactory('behroozi10') from halotools.sim_manager import CachedHaloCatalog halocat = CachedHaloCatalog(simname = 'bolshoi', redshift=0) model.populate_mock(halocat) ``` -------------------------------- ### Initialize Occupation and Bookkeeping Dictionaries Source: https://github.com/astropy/halotools/blob/master/docs/source_notes/empirical_models/factories/hod_mock_factory_source_notes.rst This code initializes dictionaries to store galaxy occupation numbers, total abundances, and indices for different galaxy types. This setup is crucial before calling the `mc_occupation_` methods. ```python self._occupation = {} self._total_abundance = {} self._gal_type_indices = {} first_galaxy_index = 0 for gal_type in self.gal_types: occupation_func_name = 'mc_occupation_'+gal_type occupation_func = getattr(self.model, occupation_func_name) # Call the component model to get a Monte Carlo # realization of the abundance of gal_type galaxies self._occupation[gal_type] = occupation_func(table=self.halo_table) # Now use the above result to set up the indexing scheme self._total_abundance[gal_type] = ( self._occupation[gal_type].sum() ) last_galaxy_index = first_galaxy_index + self._total_abundance[gal_type] # Build a bookkeeping device to keep track of # which array elements pertain to which gal_type. self._gal_type_indices[gal_type] = slice( first_galaxy_index, last_galaxy_index) first_galaxy_index = last_galaxy_index # Remove the mc_occupation function from the list of methods to call self._remaining_methods_to_call.remove(occupation_func_name) self.additional_haloprops.append('halo_num_'+gal_type) ``` -------------------------------- ### Create and Populate Mock Galaxy Catalog with IA Source: https://github.com/astropy/halotools/blob/master/docs/notebooks/intrinsic_alignments/hod_modeling_tutorial_with_alignments.ipynb Instantiates the HodModelFactory with the previously defined galaxy components, ensuring the IA strength model precedes the orientation model. Then, populates the mock galaxy catalog with the specified Halotools halo catalog and an optional seed for reproducibility. ```python # Initially create the mock with SubhaloAlignment to overwrite the host information with subhalo model_instance = HodModelFactory(centrals_occupation = cens_occ_model, centrals_profile = cens_prof_model, satellites_occupation = sats_occ_model, satellites_profile = sats_prof_model, satellites_radial_alignment_strength = sats_strength_model, centrals_orientation = cens_orientation_model, satellites_orientation = sats_orientation_model, model_feature_calling_sequence = ( 'centrals_occupation', 'centrals_profile', 'satellites_occupation', 'satellites_profile', 'satellites_radial_alignment_strength', 'centrals_orientation', 'satellites_orientation') ) #seed=132358712 seed=None model_instance.populate_mock(halocat, seed=seed) ``` -------------------------------- ### Access Analytical Relations in Behroozi et al. (2010) Model Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/preloaded_models/behroozi10_composite_model.rst Access the underlying analytical relations of the 'behroozi10' model, such as the stellar-to-halo mass relation. This example demonstrates generating halo masses for analysis. ```python import numpy as np halo_mass = np.logspace(11, 15, 100) ``` -------------------------------- ### Example of new_haloprop_func_dict usage Source: https://github.com/astropy/halotools/blob/master/docs/source_notes/empirical_models/factories/model_factory_composite_sequence_mechanisms.rst To use the `new_haloprop_func_dict` mechanism, create this attribute in your component model's `__init__` constructor. The dictionary keys are new column names, and values are functions that accept and return length-Nhalos arrays. ```python class MyComponent: def __init__(self, **kwargs): # ... other initialization self.new_haloprop_func_dict = { "my_new_halo_property": my_halo_property_func } # ... rest of initialization def my_halo_property_func(table): # Calculate and return a length-Nhalos array return calculated_array ``` -------------------------------- ### Populate Default Halo Catalog with SubhaloModelFactory Source: https://github.com/astropy/halotools/blob/master/docs/source_notes/empirical_models/factories/subhalo_model_factory_source_notes.rst Instantiate a SubhaloModelFactory and use its `populate_mock` method to populate the default halo catalog. Ensure `CachedHaloCatalog` is imported. ```python model = SubhaloModelFactory(**model_dictionary) from halotools.sim_manager import CachedHaloCatalog halocat = CachedHaloCatalog() model.populate_mock(halocat) ``` -------------------------------- ### Download Initial Halo Catalog Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/getting_started_overview.rst Execute the download script to obtain the default halo catalog. This script sets up the cache directory and downloads the catalog to the default location. ```bash $ download_initial_halocat.py -h ``` -------------------------------- ### Instantiate HaloMassInterpolQuenching Models Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/composing_models/hod_modeling/hod_modeling_tutorial2.rst Initializes HaloMassInterpolQuenching models for both satellites and centrals, specifying halo mass control points and corresponding quiescent fractions. ```python from halotools.empirical_models import HaloMassInterpolQuenching sat_quenching = HaloMassInterpolQuenching('halo_mvir', [1e12, 1e13, 1e14, 1e15], [0.35, 0.5, 0.6, 0.9], gal_type = 'satellites') cen_quenching = HaloMassInterpolQuenching('halo_mvir', [1e12, 1e15], [0.25, 0.95], gal_type = 'centrals') ``` -------------------------------- ### Create Fake Subhalo Data Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/merger_tree_analysis_example.rst Generates sample `astropy.table.Table` objects for subhalos at two different snapshots, including halo IDs, descendant IDs, and halo masses. This setup is necessary for demonstrating merger tree analysis. ```python from astropy.table import Table import numpy as np subhalos_z0 = Table() num_subhalos_z0 = 47893 subhalos_z0['halo_id'] = np.arange(num_subhalos_z0).astype('i8') subhalos_z1 = Table() num_subhalos_z1 = 58105 subhalos_z1['halo_id'] = np.arange(num_subhalos_z0, num_subhalos_z0+num_subhalos_z1).astype('i8') subhalos_z1['desc_id'] = np.random.randint(0, 2*num_subhalos_z0, num_subhalos_z1) subhalos_z1['halo_mass'] = np.random.uniform(1e10, 1e15, num_subhalos_z1) ``` -------------------------------- ### Instantiate Zheng07 HOD Model and Populate Mock Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/composing_models/hod_modeling/hod_modeling_tutorial1.rst This snippet shows how to instantiate the Zheng07 HOD model by combining occupation and profile models for centrals and satellites, and then populates a mock galaxy catalog using the composite model instance. ```python from halotools.empirical_models import HodModelFactory from halotools.empirical_models import TrivialPhaseSpace, Zheng07Cens cens_occ_model = Zheng07Cens() cens_prof_model = TrivialPhaseSpace() from halotools.empirical_models import NFWPhaseSpace, Zheng07Sats sats_occ_model = Zheng07Sats() sats_prof_model = NFWPhaseSpace() model_instance = HodModelFactory( centrals_occupation = cens_occ_model, centrals_profile = cens_prof_model, satellites_occupation = sats_occ_model, satellites_profile = sats_prof_model) # The model_instance is a composite model # All composite models can directly populate N-body simulations # with mock galaxy catalogs using the populate_mock method: from halotools.sim_manager import FakeSim halocat = FakeSim() model_instance.populate_mock(halocat) # Setting simname to 'fake' populates a mock into a fake halo catalog # that is generated on-the-fly, but you can use the populate_mock # method with any Halotools-formatted catalog ``` -------------------------------- ### Instantiate Hearin et al. (2015) Model Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/preloaded_models/hearin15_composite_model.rst Build an instance of the Hearin et al. (2015) composite HOD model using the `PrebuiltHodModelFactory`. This is the standard way to create the model for use in simulations. ```python from halotools.empirical_models import PrebuiltHodModelFactory model = PrebuiltHodModelFactory('hearin15') ``` -------------------------------- ### Generate Monte Carlo Realization of Galaxy Population Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/cam_tutorial_pages/cam_tutorial.rst Creates a Monte Carlo realization of a galaxy population with stellar mass and star formation rate (SFR). This example demonstrates generating random variables and interpolating to define means for a normal distribution. ```python import numpy as np ngals = int(1e4) log_mstar = np.random.uniform(10, 12, ngals) galaxy_mstar = 10**log_mstar mean_log_sfr = np.interp(log_mstar, [10, 11, 12], [0, 1, 2]) log_sfr = np.random.normal(loc=mean_log_sfr, scale=0.2, size=ngals) galaxy_sfr = 10**log_sfr ``` -------------------------------- ### Load Halo Catalog and Populate Mock Source: https://github.com/astropy/halotools/blob/master/docs/notebooks/galcat_analysis/intermediate_examples/galaxy_catalog_intermediate_analysis_tutorial1.ipynb Loads a cached halo catalog for a specific simulation and redshift, then populates the previously defined mock model with this catalog. ```python from halotools.sim_manager import CachedHaloCatalog halocat = CachedHaloCatalog(simname = 'bolshoi', redshift = 0, halo_finder = 'rockstar') model.populate_mock(halocat) ``` -------------------------------- ### Download Alternate Halo Catalogs Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/getting_started_overview.rst Use the download script to fetch alternative halo catalogs, specifying simulation name, halo finder, version, and redshift. The --help flag provides usage information. ```bash $ download_additional_halocat.py multidark rockstar most_recent 0.5 ``` ```bash $ download_alternate_halocats.py --help ``` -------------------------------- ### Custom Satellite Occupation Component Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/composing_models/hod_modeling/writing_your_own_hod_occupation_component.rst Defines a custom satellite occupation component with a non-standard mc_occupation method. This example overrides the default behavior to model a scenario where a halo has either 0 or 5 satellites, useful for studying occupation statistics beyond nearest-integer or Poisson distributions. ```python from halotools.empirical_models import OccupationComponent class MySatelliteOccupation(OccupationComponent): def __init__(self, threshold): OccupationComponent.__init__(self, gal_type = 'satellites', threshold = threshold, upper_occupation_bound = 5) def mean_occupation(self, **kwargs): table = kwargs['table'] return np.zeros(len(table)) + 2.5 def mc_occupation(self, **kwargs): table = kwargs['table'] meanocc = self.mean_occupation(**kwargs) result = np.where(meanocc < 2.5, 0, 5) table['halo_num_satellites'] = result return result ``` -------------------------------- ### Initialize Galaxy Positions and Velocities Source: https://github.com/astropy/halotools/blob/master/docs/source_notes/empirical_models/factories/hod_mock_factory_source_notes.rst Initializes the host-centric positions and velocities of galaxies to match their host halo's properties. This is a preliminary step before detailed intra-halo distribution modeling. ```python self.galaxy_table['x'] = self.galaxy_table['halo_x'] self.galaxy_table['y'] = self.galaxy_table['halo_y'] self.galaxy_table['z'] = self.galaxy_table['halo_z'] self.galaxy_table['vx'] = self.galaxy_table['halo_vx'] self.galaxy_table['vy'] = self.galaxy_table['halo_vy'] self.galaxy_table['vz'] = self.galaxy_table['halo_vz'] ``` -------------------------------- ### Instantiate and Populate Subhalo Model Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/composing_models/subhalo_modeling/subhalo_modeling_tutorial1.rst This snippet demonstrates instantiating a Behroozi10SmHm model, creating a SubhaloModelFactory with a custom nickname for stellar mass, and populating a mock galaxy population using a CachedHaloCatalog. It then prints the first 5 rows of the resulting galaxy table. ```python sm_model = Behroozi10SmHm(redshift = 0) model_instance = SubhaloModelFactory(mstar = sm_model) from halotools.sim_manager import CachedHaloCatalog halocat = CachedHaloCatalog(simname = 'bolshoi') model_instance.populate_mock(halocat) print(model_instance.mock.galaxy_table[0:5]) ``` -------------------------------- ### Build and Populate a Composite HOD Model Source: https://github.com/astropy/halotools/blob/master/docs/quickstart_and_tutorials/tutorials/model_building/composing_models/hod_modeling/hod_modeling_tutorial3.rst Instantiate custom component models for different galaxy types (centrals, satellites), then use HodModelFactory to combine them with a pre-built HOD model. Finally, populate a mock catalog using the new composite model. ```python cen_size = Size('centrals') sat_size = Size('satellites') from halotools.empirical_models import PrebuiltHodModelFactory, HodModelFactory zheng_model = PrebuiltHodModelFactory('zheng07') new_model = HodModelFactory(baseline_model_instance = zheng_model, centrals_size = cen_size, satellites_size = sat_size) # Your new model can generate a mock in the same way as always from halotools.sim_manager import CachedHaloCatalog halocat = CachedHaloCatalog(simname = 'bolshoi') new_model.populate_mock(halocat) ```