From d3abd0a3ea14e9b8a4152d274c56c80584d071cb Mon Sep 17 00:00:00 2001 From: Andrew Hearin Date: Fri, 18 Sep 2020 10:25:49 -0500 Subject: [PATCH] Added new keyword argument halo_boundary_key allowing users to override the enforcement of consistent column names between halo mass and halo boundary --- .../composite_models/hod_models/tests/test_zheng07.py | 7 ++++++- .../analytic_models/centrals/trivial_phase_space.py | 6 +++++- .../analytic_models/profile_model_template.py | 10 ++++++++-- .../satellites/nfw/biased_nfw_phase_space.py | 3 +++ .../analytic_models/satellites/nfw/nfw_profile.py | 8 +++++++- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/halotools/empirical_models/composite_models/hod_models/tests/test_zheng07.py b/halotools/empirical_models/composite_models/hod_models/tests/test_zheng07.py index 79257ad42..2cddcf469 100644 --- a/halotools/empirical_models/composite_models/hod_models/tests/test_zheng07.py +++ b/halotools/empirical_models/composite_models/hod_models/tests/test_zheng07.py @@ -109,7 +109,12 @@ def test_host_centric_distance(): def test_mass_definition_flexibility(): """ Regression test for Issue #993. """ - model = PrebuiltHodModelFactory("zheng07", mdef="200m") + model = PrebuiltHodModelFactory( + "zheng07", mdef="200m", halo_boundary_key="halo_radius_arbitrary" + ) halocat = FakeSim(seed=43) halocat.halo_table["halo_m200m"] = np.copy(halocat.halo_table["halo_mvir"]) + halocat.halo_table["halo_radius_arbitrary"] = np.copy( + halocat.halo_table["halo_mvir"] + ) model.populate_mock(halocat, seed=43) diff --git a/halotools/empirical_models/phase_space_models/analytic_models/centrals/trivial_phase_space.py b/halotools/empirical_models/phase_space_models/analytic_models/centrals/trivial_phase_space.py index ba08a8a31..f5db0b494 100644 --- a/halotools/empirical_models/phase_space_models/analytic_models/centrals/trivial_phase_space.py +++ b/halotools/empirical_models/phase_space_models/analytic_models/centrals/trivial_phase_space.py @@ -27,6 +27,7 @@ def __init__( cosmology=sim_defaults.default_cosmology, redshift=sim_defaults.default_redshift, mdef=model_defaults.halo_mass_definition, + halo_boundary_key=None, **kwargs ): """ @@ -59,7 +60,10 @@ def __init__( self.cosmology = cosmology self.redshift = redshift self.mdef = mdef - self.halo_boundary_key = model_defaults.get_halo_boundary_key(self.mdef) + if halo_boundary_key is None: + self.halo_boundary_key = model_defaults.get_halo_boundary_key(self.mdef) + else: + self.halo_boundary_key = halo_boundary_key def assign_phase_space(self, table, **kwargs): r""" diff --git a/halotools/empirical_models/phase_space_models/analytic_models/profile_model_template.py b/halotools/empirical_models/phase_space_models/analytic_models/profile_model_template.py index 49a99c6d5..16831938d 100644 --- a/halotools/empirical_models/phase_space_models/analytic_models/profile_model_template.py +++ b/halotools/empirical_models/phase_space_models/analytic_models/profile_model_template.py @@ -42,7 +42,7 @@ class AnalyticDensityProf(object): the profile is the necessary and sufficient ingredient. """ - def __init__(self, cosmology, redshift, mdef, **kwargs): + def __init__(self, cosmology, redshift, mdef, halo_boundary_key=None, **kwargs): r""" Parameters ----------- @@ -55,6 +55,9 @@ def __init__(self, cosmology, redshift, mdef, **kwargs): mdef: str String specifying the halo mass definition, e.g., 'vir' or '200m'. + halo_boundary_key : str, optional + Default behavior is to use the column associated with the input mdef. + """ self.cosmology = cosmology self.redshift = redshift @@ -65,7 +68,10 @@ def __init__(self, cosmology, redshift, mdef, **kwargs): self.density_threshold = halo_boundary_functions.density_threshold( cosmology=self.cosmology, redshift=self.redshift, mdef=self.mdef ) - self.halo_boundary_key = model_defaults.get_halo_boundary_key(self.mdef) + if halo_boundary_key is None: + self.halo_boundary_key = model_defaults.get_halo_boundary_key(self.mdef) + else: + self.halo_boundary_key = halo_boundary_key self.prim_haloprop_key = model_defaults.get_halo_mass_key(self.mdef) self.gal_prof_param_keys = [] diff --git a/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/biased_nfw_phase_space.py b/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/biased_nfw_phase_space.py index a7bcf1561..6426b0b8b 100644 --- a/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/biased_nfw_phase_space.py +++ b/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/biased_nfw_phase_space.py @@ -71,6 +71,9 @@ def __init__(self, profile_integration_tol=1e-5, **kwargs): String specifying the halo mass definition, e.g., 'vir' or '200m'. Default is set in `~halotools.empirical_models.model_defaults`. + halo_boundary_key : str, optional + Default behavior is to use the column associated with the input mdef. + concentration_key : string, optional Column name of the halo catalog storing NFW concentration. diff --git a/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/nfw_profile.py b/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/nfw_profile.py index e7ec7eea0..c547c9c8e 100644 --- a/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/nfw_profile.py +++ b/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/nfw_profile.py @@ -43,6 +43,7 @@ def __init__( mdef=model_defaults.halo_mass_definition, conc_mass_model=model_defaults.conc_mass_model, concentration_key=model_defaults.concentration_key, + halo_boundary_key=None, **kwargs ): r""" @@ -60,6 +61,9 @@ def __init__( String specifying the halo mass definition, e.g., 'vir' or '200m'. Default is set in `~halotools.empirical_models.model_defaults`. + halo_boundary_key : str, optional + Default behavior is to use the column associated with the input mdef. + conc_mass_model : string or callable, optional Specifies the function used to model the relation between NFW concentration and halo mass. @@ -80,7 +84,9 @@ def __init__( -------- >>> nfw = NFWProfile() """ - AnalyticDensityProf.__init__(self, cosmology, redshift, mdef) + AnalyticDensityProf.__init__( + self, cosmology, redshift, mdef, halo_boundary_key=halo_boundary_key + ) self.gal_prof_param_keys = ["conc_NFWmodel"] self.halo_prof_param_keys = ["conc_NFWmodel"]