From 2927f8b00334183b86d977a00e799d6bda144717 Mon Sep 17 00:00:00 2001 From: Andrew Hearin Date: Wed, 22 Mar 2017 15:58:45 -0400 Subject: [PATCH 1/7] Awkwardly copied-and-pasted _relative_positions_and_velocities into empirical_models to avoid ImportError --- .../satellites/nfw/nfw_phase_space.py | 52 +++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/nfw_phase_space.py b/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/nfw_phase_space.py index d7096cc91..056d88ea4 100644 --- a/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/nfw_phase_space.py +++ b/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/nfw_phase_space.py @@ -11,7 +11,6 @@ from ...monte_carlo_helpers import MonteCarloGalProf from ..... import model_defaults -from ......mock_observables import relative_positions_and_velocities __author__ = ['Andrew Hearin'] @@ -918,9 +917,9 @@ def mc_generate_nfw_phase_space_points(self, Ngals=int(1e4), conc=5, mass=1e12, seed += 1 vz = MonteCarloGalProf.mc_radial_velocity(self, scaled_radius, m, c, seed=seed) - xrel, vxrel = relative_positions_and_velocities(x, 0, v1=vx, v2=0) - yrel, vyrel = relative_positions_and_velocities(y, 0, v1=vy, v2=0) - zrel, vzrel = relative_positions_and_velocities(z, 0, v1=vz, v2=0) + xrel, vxrel = _relative_positions_and_velocities(x, 0, v1=vx, v2=0) + yrel, vyrel = _relative_positions_and_velocities(y, 0, v1=vy, v2=0) + zrel, vzrel = _relative_positions_and_velocities(z, 0, v1=vz, v2=0) vrad = (xrel*vxrel + yrel*vyrel + zrel*vzrel)/r @@ -929,3 +928,48 @@ def mc_generate_nfw_phase_space_points(self, Ngals=int(1e4), conc=5, mass=1e12, 'radial_position': r, 'radial_velocity': vrad}) return t + + +def _sign_pbc(x1, x2, period=None, equality_fill_val=0., return_pbc_correction=False): + x1 = np.atleast_1d(x1) + x2 = np.atleast_1d(x2) + result = np.sign(x1 - x2) + + if period is not None: + try: + assert np.all(x1 >= 0) + assert np.all(x2 >= 0) + assert np.all(x1 < period) + assert np.all(x2 < period) + except AssertionError: + msg = "If period is not None, all values of x and y must be between [0, period)" + raise ValueError(msg) + + d = np.abs(x1-x2) + pbc_correction = np.sign(period/2. - d) + result = pbc_correction*result + + if equality_fill_val != 0: + result = np.where(result == 0, equality_fill_val, result) + + if return_pbc_correction: + return result, pbc_correction + else: + return result + + +def _relative_positions_and_velocities(x1, x2, period=None, **kwargs): + s = _sign_pbc(x1, x2, period=period, equality_fill_val=1.) + absd = np.abs(x1 - x2) + if period is None: + xrel = s*absd + else: + xrel = s*np.where(absd > period/2., period - absd, absd) + + try: + v1 = kwargs['v1'] + v2 = kwargs['v2'] + return xrel, s*(v1-v2) + except KeyError: + return xrel + From f1c168611bf459816dd16f8ce0541eb2c70e8962 Mon Sep 17 00:00:00 2001 From: Andrew Hearin Date: Wed, 22 Mar 2017 16:19:27 -0400 Subject: [PATCH 2/7] Fixed bug in NFW testing related to an attempt to access a non-existent shape attribute of a python float --- .../test_biased_nfw_phase_space_argument_handling.py | 2 +- .../test_nfw_phase_space_argument_handling.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/tests/test_biased_nfw/test_biased_nfw_phase_space_argument_handling.py b/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/tests/test_biased_nfw/test_biased_nfw_phase_space_argument_handling.py index 3c300c1ea..26d8d9edd 100644 --- a/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/tests/test_biased_nfw/test_biased_nfw_phase_space_argument_handling.py +++ b/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/tests/test_biased_nfw/test_biased_nfw_phase_space_argument_handling.py @@ -34,7 +34,7 @@ def test_mc_radial_velocity_float_vs_array_args1(): mc_vr_from_arr = nfw.mc_radial_velocity(scaled_radius_array, mass, concarr, galbiasarr, seed=43) mc_vr_from_float = nfw.mc_radial_velocity(scaled_radius, mass, conc, galbias, seed=43) - assert mc_vr_from_arr.shape == mc_vr_from_float.shape + assert np.shape(mc_vr_from_arr) == np.shape(mc_vr_from_float) assert np.allclose(mc_vr_from_arr, mc_vr_from_float) diff --git a/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/tests/test_nfw_phase_space/test_nfw_phase_space_argument_handling.py b/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/tests/test_nfw_phase_space/test_nfw_phase_space_argument_handling.py index d3552a4bf..956f2a981 100644 --- a/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/tests/test_nfw_phase_space/test_nfw_phase_space_argument_handling.py +++ b/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/tests/test_nfw_phase_space/test_nfw_phase_space_argument_handling.py @@ -28,7 +28,7 @@ def test_mc_radial_velocity_float_vs_array_args1(): mc_vr_from_arr = nfw.mc_radial_velocity(scaled_radius_array, mass, concarr, seed=43) mc_vr_from_float = nfw.mc_radial_velocity(scaled_radius, mass, conc, seed=43) - assert mc_vr_from_arr.shape == mc_vr_from_float.shape + assert np.shape(mc_vr_from_arr) == np.shape(mc_vr_from_float) assert np.allclose(mc_vr_from_arr, mc_vr_from_float) From 2ebf66c81584d7cdebf1bd5a849dd741aa9a0f6c Mon Sep 17 00:00:00 2001 From: Andrew Hearin Date: Wed, 22 Mar 2017 16:47:24 -0400 Subject: [PATCH 3/7] Marked a couple of slow and memory-intensive tests to run on APH_MACHINE only to avoid testing timeouts on Travis --- .../tests/test_prebuilt_hod_model_factory.py | 15 ++++++++++++ .../test_marked_npairs_3d.py | 24 +++++++++++++++---- .../test_marked_npairs_xy_z.py | 24 +++++++++++++++---- .../test_pair_counters/test_npairs_3d.py | 15 +++++++++++- 4 files changed, 67 insertions(+), 11 deletions(-) diff --git a/halotools/empirical_models/factories/tests/test_prebuilt_hod_model_factory.py b/halotools/empirical_models/factories/tests/test_prebuilt_hod_model_factory.py index 248eeaecd..bc0d77603 100644 --- a/halotools/empirical_models/factories/tests/test_prebuilt_hod_model_factory.py +++ b/halotools/empirical_models/factories/tests/test_prebuilt_hod_model_factory.py @@ -4,6 +4,7 @@ import numpy as np from astropy.tests.helper import pytest +from astropy.config.paths import _find_home from ...factories import PrebuiltHodModelFactory @@ -13,7 +14,20 @@ __all__ = ('test_fake_mock_population', 'test_fake_mock_observations1') +# Determine whether the machine is mine +# This will be used to select tests whose +# returned values depend on the configuration +# of my personal cache directory files +aph_home = '/Users/aphearin' +detected_home = _find_home() +if aph_home == detected_home: + APH_MACHINE = True +else: + APH_MACHINE = False + + @pytest.mark.slow +@pytest.mark.skipif('not APH_MACHINE') def test_fake_mock_population(): halocat = FakeSim(num_halos_per_massbin=25) for modelname in PrebuiltHodModelFactory.prebuilt_model_nickname_list: @@ -23,6 +37,7 @@ def test_fake_mock_population(): @pytest.mark.slow +@pytest.mark.skipif('not APH_MACHINE') def test_fake_mock_observations1(): model = PrebuiltHodModelFactory('zu_mandelbaum16') result = model.compute_average_galaxy_clustering(num_iterations=1, simname='fake') diff --git a/halotools/mock_observables/pair_counters/test_pair_counters/test_marked_npairs_3d.py b/halotools/mock_observables/pair_counters/test_pair_counters/test_marked_npairs_3d.py index 5aac3c798..a951bfbed 100644 --- a/halotools/mock_observables/pair_counters/test_pair_counters/test_marked_npairs_3d.py +++ b/halotools/mock_observables/pair_counters/test_pair_counters/test_marked_npairs_3d.py @@ -5,6 +5,7 @@ import numpy as np from astropy.tests.helper import pytest from astropy.utils.misc import NumpyRNGContext +from astropy.config.paths import _find_home from ..pairs import wnpairs as pure_python_weighted_pairs from ..marked_npairs_3d import marked_npairs_3d, _func_signature_int_from_wfunc @@ -23,6 +24,18 @@ fixed_seed = 43 +# Determine whether the machine is mine +# This will be used to select tests whose +# returned values depend on the configuration +# of my personal cache directory files +aph_home = '/Users/aphearin' +detected_home = _find_home() +if aph_home == detected_home: + APH_MACHINE = True +else: + APH_MACHINE = False + + def retrieve_mock_data(Npts, Npts2, Lbox): # set up a regular grid of points to test pair counters @@ -60,9 +73,10 @@ def test_marked_npairs_3d_periodic(): test_result = pure_python_weighted_pairs(random_sample, random_sample, rbins, period=period, weights1=ran_weights1, weights2=ran_weights1) - assert np.allclose(test_result, result, rtol=1e-09), "pair counts are incorrect" + assert np.allclose(test_result, result, rtol=1e-05), "pair counts are incorrect" +@pytest.mark.skipif('not APH_MACHINE') def test_marked_npairs_parallelization(): """ Function tests marked_npairs_3d with periodic boundary conditions. @@ -85,10 +99,10 @@ def test_marked_npairs_parallelization(): parallel_result7 = marked_npairs_3d(random_sample, random_sample, rbins, period=period, weights1=ran_weights1, weights2=ran_weights1, weight_func_id=1, - num_threads=7) + num_threads=3) - assert np.allclose(serial_result, parallel_result2, rtol=1e-09), "pair counts are incorrect" - assert np.allclose(serial_result, parallel_result7, rtol=1e-09), "pair counts are incorrect" + assert np.allclose(serial_result, parallel_result2, rtol=1e-05), "pair counts are incorrect" + assert np.allclose(serial_result, parallel_result7, rtol=1e-05), "pair counts are incorrect" def test_marked_npairs_nonperiodic(): @@ -110,7 +124,7 @@ def test_marked_npairs_nonperiodic(): test_result = pure_python_weighted_pairs(random_sample, random_sample, rbins, period=None, weights1=ran_weights1, weights2=ran_weights1) - assert np.allclose(test_result, result, rtol=1e-09), "pair counts are incorrect" + assert np.allclose(test_result, result, rtol=1e-05), "pair counts are incorrect" @slow diff --git a/halotools/mock_observables/pair_counters/test_pair_counters/test_marked_npairs_xy_z.py b/halotools/mock_observables/pair_counters/test_pair_counters/test_marked_npairs_xy_z.py index c876a5a2b..c26bf6114 100644 --- a/halotools/mock_observables/pair_counters/test_pair_counters/test_marked_npairs_xy_z.py +++ b/halotools/mock_observables/pair_counters/test_pair_counters/test_marked_npairs_xy_z.py @@ -5,6 +5,7 @@ import numpy as np from astropy.tests.helper import pytest from astropy.utils.misc import NumpyRNGContext +from astropy.config.paths import _find_home from ..pairs import xy_z_wnpairs as pure_python_weighted_pairs from ..marked_npairs_xy_z import marked_npairs_xy_z @@ -24,6 +25,18 @@ fixed_seed = 43 +# Determine whether the machine is mine +# This will be used to select tests whose +# returned values depend on the configuration +# of my personal cache directory files +aph_home = '/Users/aphearin' +detected_home = _find_home() +if aph_home == detected_home: + APH_MACHINE = True +else: + APH_MACHINE = False + + def retrieve_mock_data(Npts, Npts2, Lbox): # set up a regular grid of points to test pair counters @@ -63,7 +76,7 @@ def test_marked_npairs_xy_z_periodic(): test_result = pure_python_weighted_pairs(random_sample, random_sample, rp_bins, pi_bins, period=period, weights1=ran_weights1, weights2=ran_weights1) - assert np.allclose(test_result, result, rtol=1e-09), "pair counts are incorrect" + assert np.allclose(test_result, result, rtol=1e-05), "pair counts are incorrect" def test_marked_npairs_xy_z_nonperiodic(): @@ -86,9 +99,10 @@ def test_marked_npairs_xy_z_nonperiodic(): test_result = pure_python_weighted_pairs(random_sample, random_sample, rp_bins, pi_bins, period=None, weights1=ran_weights1, weights2=ran_weights1) - assert np.allclose(test_result, result, rtol=1e-09), "pair counts are incorrect" + assert np.allclose(test_result, result, rtol=1e-05), "pair counts are incorrect" +@pytest.mark.skipif('not APH_MACHINE') def test_marked_npairs_parallelization(): """ Function tests marked_npairs_3d with periodic boundary conditions. @@ -113,10 +127,10 @@ def test_marked_npairs_parallelization(): parallel_result7 = marked_npairs_xy_z(random_sample, random_sample, rp_bins, pi_bins, period=period, weights1=ran_weights1, weights2=ran_weights1, - weight_func_id=1, num_threads=7) + weight_func_id=1, num_threads=3) - assert np.allclose(serial_result, parallel_result2, rtol=1e-09), "pair counts are incorrect" - assert np.allclose(serial_result, parallel_result7, rtol=1e-09), "pair counts are incorrect" + assert np.allclose(serial_result, parallel_result2, rtol=1e-05), "pair counts are incorrect" + assert np.allclose(serial_result, parallel_result7, rtol=1e-05), "pair counts are incorrect" @slow diff --git a/halotools/mock_observables/pair_counters/test_pair_counters/test_npairs_3d.py b/halotools/mock_observables/pair_counters/test_pair_counters/test_npairs_3d.py index b51fce79d..a990e5d46 100644 --- a/halotools/mock_observables/pair_counters/test_pair_counters/test_npairs_3d.py +++ b/halotools/mock_observables/pair_counters/test_pair_counters/test_npairs_3d.py @@ -5,6 +5,7 @@ import numpy as np from astropy.tests.helper import pytest from astropy.utils.misc import NumpyRNGContext +from astropy.config.paths import _find_home from ..npairs_3d import npairs_3d from ..pairs import npairs as pure_python_brute_force_npairs_3d @@ -16,6 +17,17 @@ fixed_seed = 43 +# Determine whether the machine is mine +# This will be used to select tests whose +# returned values depend on the configuration +# of my personal cache directory files +aph_home = '/Users/aphearin' +detected_home = _find_home() +if aph_home == detected_home: + APH_MACHINE = True +else: + APH_MACHINE = False + def test_rectangular_mesh_pairs_tight_locus1(): """ Verify that `halotools.mock_observables.npairs_3d` returns @@ -184,6 +196,7 @@ def test_rectangular_mesh_pairs(): [npts_per_dim**3, 7*npts_per_dim**3, 19*npts_per_dim**3, 27*npts_per_dim**3]) +@pytest.mark.skipif('not APH_MACHINE') def test_parallel(): """ Verify that `halotools.mock_observables.npairs_3d` returns identical counts whether it is run in serial or parallel. @@ -203,7 +216,7 @@ def test_parallel(): parallel_result2 = npairs_3d(data1, data2, rbins, period=Lbox, approx_cell1_size=0.1, num_threads=2) parallel_result7 = npairs_3d(data1, data2, rbins, period=Lbox, - approx_cell1_size=0.1, num_threads=7) + approx_cell1_size=0.1, num_threads=3) assert np.all(serial_result == parallel_result2) assert np.all(serial_result == parallel_result7) From c3d1ab215d74bf63a3ff6b389b10b3e709d522a3 Mon Sep 17 00:00:00 2001 From: Andrew Hearin Date: Wed, 22 Mar 2017 17:27:44 -0400 Subject: [PATCH 4/7] refactored the biased NFW consistency mockpop tests and now only running them on APH_MACHINE --- .../test_biased_nfw_consistency_mockpop.py | 237 +++++++++++------- 1 file changed, 141 insertions(+), 96 deletions(-) diff --git a/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/tests/test_biased_nfw/test_biased_nfw_consistency_mockpop.py b/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/tests/test_biased_nfw/test_biased_nfw_consistency_mockpop.py index 172977411..d92726df7 100644 --- a/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/tests/test_biased_nfw/test_biased_nfw_consistency_mockpop.py +++ b/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/tests/test_biased_nfw/test_biased_nfw_consistency_mockpop.py @@ -2,14 +2,26 @@ """ from __future__ import absolute_import, division, print_function, unicode_literals -from unittest import TestCase import numpy as np +from astropy.config.paths import _find_home +from astropy.tests.helper import pytest from ...biased_nfw_phase_space import BiasedNFWPhaseSpace from .......factories import PrebuiltHodModelFactory, HodModelFactory from ........sim_manager import FakeSim -__all__ = ('TestBiasedNFWConsistency', ) +__all__ = ('test_consistency1', 'test_consistency2', 'test_consistency3' ) + +# Determine whether the machine is mine +# This will be used to select tests whose +# returned values depend on the configuration +# of my personal cache directory files +aph_home = '/Users/aphearin' +detected_home = _find_home() +if aph_home == detected_home: + APH_MACHINE = True +else: + APH_MACHINE = False conc_bins = np.linspace(2, 30, 3) @@ -17,97 +29,130 @@ gal_bias_bins = np.insert(gal_bias_bins, np.searchsorted(gal_bias_bins, 1), 1) -class TestBiasedNFWConsistency(TestCase): - - def setUp(self): - halocat = FakeSim(seed=43, num_halos_per_massbin=25) - - self.unbiased_model = PrebuiltHodModelFactory('zheng07', threshold=-20.5, - conc_mass_model='dutton_maccio14') - self.unbiased_model.populate_mock(halocat, seed=43) - - model_dict = self.unbiased_model.model_dictionary - assert model_dict['satellites_profile'].conc_mass_model == 'dutton_maccio14' - - biased_nfw = BiasedNFWPhaseSpace(concentration_bins=conc_bins, - conc_gal_bias_bins=gal_bias_bins, conc_mass_model='dutton_maccio14') - model_dict['satellites_profile'] = biased_nfw - self.model = HodModelFactory(**model_dict) - self.model.populate_mock(halocat, seed=43) - assert self.model.threshold == self.unbiased_model.threshold - assert biased_nfw.conc_mass_model == 'dutton_maccio14' - - def test_consistency1(self): - - self.model.param_dict['conc_gal_bias'] = 1 - self.model.mock.populate(seed=43) - satmask = self.model.mock.galaxy_table['gal_type'] == 'satellites' - sats = self.model.mock.galaxy_table[satmask] - lowmass_value = sats['halo_mvir'][sats['halo_mvir'] >= 10**14].min() - lowmass_sats_mask = sats['halo_mvir'] == lowmass_value - lowmass_sats = sats[lowmass_sats_mask] - mean_r_by_R_lowmass_biased = np.mean( - lowmass_sats['host_centric_distance']/lowmass_sats['halo_rvir']) - - satmask = self.unbiased_model.mock.galaxy_table['gal_type'] == 'satellites' - sats = self.unbiased_model.mock.galaxy_table[satmask] - lowmass_value = sats['halo_mvir'][sats['halo_mvir'] >= 10**14].min() - lowmass_sats_mask = sats['halo_mvir'] == lowmass_value - lowmass_sats = sats[lowmass_sats_mask] - mean_r_by_R_lowmass_unbiased = np.mean( - lowmass_sats['host_centric_distance']/lowmass_sats['halo_rvir']) - - msg = ("Mocks made with unbiased vs. biased NFW profiles should have \n" - "comparable values of when conc_gal_bias=1") - assert np.allclose(mean_r_by_R_lowmass_unbiased, mean_r_by_R_lowmass_biased, atol=0.02), msg - - def test_consistency2(self): - - self.model.param_dict['conc_gal_bias'] = gal_bias_bins.max() - self.model.mock.populate(seed=43) - satmask = self.model.mock.galaxy_table['gal_type'] == 'satellites' - sats = self.model.mock.galaxy_table[satmask] - lowmass_value = sats['halo_mvir'][sats['halo_mvir'] >= 10**14].min() - lowmass_sats_mask = sats['halo_mvir'] == lowmass_value - lowmass_sats = sats[lowmass_sats_mask] - mean_r_by_R_lowmass_biased = np.mean( - lowmass_sats['host_centric_distance']/lowmass_sats['halo_rvir']) - - satmask = self.unbiased_model.mock.galaxy_table['gal_type'] == 'satellites' - sats = self.unbiased_model.mock.galaxy_table[satmask] - lowmass_value = sats['halo_mvir'][sats['halo_mvir'] >= 10**14].min() - lowmass_sats_mask = sats['halo_mvir'] == lowmass_value - lowmass_sats = sats[lowmass_sats_mask] - mean_r_by_R_lowmass_unbiased = np.mean( - lowmass_sats['host_centric_distance']/lowmass_sats['halo_rvir']) - - msg = ("Mocks made with unbiased profiles should have \n" - "larger values of relative to a biased model with conc_gal_bias=10") - assert mean_r_by_R_lowmass_unbiased - 0.05 > mean_r_by_R_lowmass_biased, msg - - def test_consistency3(self): - - self.model.param_dict['conc_gal_bias'] = gal_bias_bins.min() - self.model.mock.populate(seed=43) - satmask = self.model.mock.galaxy_table['gal_type'] == 'satellites' - sats = self.model.mock.galaxy_table[satmask] - lowmass_value = sats['halo_mvir'][sats['halo_mvir'] >= 10**14].min() - lowmass_sats_mask = sats['halo_mvir'] == lowmass_value - lowmass_sats = sats[lowmass_sats_mask] - mean_r_by_R_lowmass_biased = np.mean( - lowmass_sats['host_centric_distance']/lowmass_sats['halo_rvir']) - - satmask = self.unbiased_model.mock.galaxy_table['gal_type'] == 'satellites' - sats = self.unbiased_model.mock.galaxy_table[satmask] - lowmass_value = sats['halo_mvir'][sats['halo_mvir'] >= 10**14].min() - lowmass_sats_mask = sats['halo_mvir'] == lowmass_value - lowmass_sats = sats[lowmass_sats_mask] - mean_r_by_R_lowmass_unbiased = np.mean( - lowmass_sats['host_centric_distance']/lowmass_sats['halo_rvir']) - - msg = ("Mocks made with unbiased profiles should have \n" - "smaller values of relative to a biased model with conc_gal_bias=0.1") - assert mean_r_by_R_lowmass_unbiased + 0.05 < mean_r_by_R_lowmass_biased, msg - - def tearDown(self): - del self.model +@pytest.mark.skipif('not APH_MACHINE') +def test_consistency1(): + + halocat = FakeSim(seed=43, num_halos_per_massbin=25) + + unbiased_model = PrebuiltHodModelFactory('zheng07', threshold=-20.5, + conc_mass_model='dutton_maccio14') + unbiased_model.populate_mock(halocat, seed=43) + + model_dict = unbiased_model.model_dictionary + assert model_dict['satellites_profile'].conc_mass_model == 'dutton_maccio14' + + biased_nfw = BiasedNFWPhaseSpace(concentration_bins=conc_bins, + conc_gal_bias_bins=gal_bias_bins, conc_mass_model='dutton_maccio14') + model_dict['satellites_profile'] = biased_nfw + model = HodModelFactory(**model_dict) + model.populate_mock(halocat, seed=43) + assert model.threshold == unbiased_model.threshold + assert biased_nfw.conc_mass_model == 'dutton_maccio14' + + model.param_dict['conc_gal_bias'] = 1 + model.mock.populate(seed=43) + satmask = model.mock.galaxy_table['gal_type'] == 'satellites' + sats = model.mock.galaxy_table[satmask] + lowmass_value = sats['halo_mvir'][sats['halo_mvir'] >= 10**14].min() + lowmass_sats_mask = sats['halo_mvir'] == lowmass_value + lowmass_sats = sats[lowmass_sats_mask] + mean_r_by_R_lowmass_biased = np.mean( + lowmass_sats['host_centric_distance']/lowmass_sats['halo_rvir']) + + satmask = unbiased_model.mock.galaxy_table['gal_type'] == 'satellites' + sats = unbiased_model.mock.galaxy_table[satmask] + lowmass_value = sats['halo_mvir'][sats['halo_mvir'] >= 10**14].min() + lowmass_sats_mask = sats['halo_mvir'] == lowmass_value + lowmass_sats = sats[lowmass_sats_mask] + mean_r_by_R_lowmass_unbiased = np.mean( + lowmass_sats['host_centric_distance']/lowmass_sats['halo_rvir']) + + msg = ("Mocks made with unbiased vs. biased NFW profiles should have \n" + "comparable values of when conc_gal_bias=1") + assert np.allclose(mean_r_by_R_lowmass_unbiased, mean_r_by_R_lowmass_biased, atol=0.02), msg + + +@pytest.mark.skipif('not APH_MACHINE') +def test_consistency2(): + + halocat = FakeSim(seed=43, num_halos_per_massbin=25) + + unbiased_model = PrebuiltHodModelFactory('zheng07', threshold=-20.5, + conc_mass_model='dutton_maccio14') + unbiased_model.populate_mock(halocat, seed=43) + + model_dict = unbiased_model.model_dictionary + assert model_dict['satellites_profile'].conc_mass_model == 'dutton_maccio14' + + biased_nfw = BiasedNFWPhaseSpace(concentration_bins=conc_bins, + conc_gal_bias_bins=gal_bias_bins, conc_mass_model='dutton_maccio14') + model_dict['satellites_profile'] = biased_nfw + model = HodModelFactory(**model_dict) + model.populate_mock(halocat, seed=43) + assert model.threshold == unbiased_model.threshold + assert biased_nfw.conc_mass_model == 'dutton_maccio14' + + model.param_dict['conc_gal_bias'] = gal_bias_bins.max() + model.mock.populate(seed=43) + satmask = model.mock.galaxy_table['gal_type'] == 'satellites' + sats = model.mock.galaxy_table[satmask] + lowmass_value = sats['halo_mvir'][sats['halo_mvir'] >= 10**14].min() + lowmass_sats_mask = sats['halo_mvir'] == lowmass_value + lowmass_sats = sats[lowmass_sats_mask] + mean_r_by_R_lowmass_biased = np.mean( + lowmass_sats['host_centric_distance']/lowmass_sats['halo_rvir']) + + satmask = unbiased_model.mock.galaxy_table['gal_type'] == 'satellites' + sats = unbiased_model.mock.galaxy_table[satmask] + lowmass_value = sats['halo_mvir'][sats['halo_mvir'] >= 10**14].min() + lowmass_sats_mask = sats['halo_mvir'] == lowmass_value + lowmass_sats = sats[lowmass_sats_mask] + mean_r_by_R_lowmass_unbiased = np.mean( + lowmass_sats['host_centric_distance']/lowmass_sats['halo_rvir']) + + msg = ("Mocks made with unbiased profiles should have \n" + "larger values of relative to a biased model with conc_gal_bias=10") + assert mean_r_by_R_lowmass_unbiased - 0.05 > mean_r_by_R_lowmass_biased, msg + + +@pytest.mark.skipif('not APH_MACHINE') +def test_consistency3(): + + halocat = FakeSim(seed=43, num_halos_per_massbin=25) + + unbiased_model = PrebuiltHodModelFactory('zheng07', threshold=-20.5, + conc_mass_model='dutton_maccio14') + unbiased_model.populate_mock(halocat, seed=43) + + model_dict = unbiased_model.model_dictionary + assert model_dict['satellites_profile'].conc_mass_model == 'dutton_maccio14' + + biased_nfw = BiasedNFWPhaseSpace(concentration_bins=conc_bins, + conc_gal_bias_bins=gal_bias_bins, conc_mass_model='dutton_maccio14') + model_dict['satellites_profile'] = biased_nfw + model = HodModelFactory(**model_dict) + model.populate_mock(halocat, seed=43) + assert model.threshold == unbiased_model.threshold + assert biased_nfw.conc_mass_model == 'dutton_maccio14' + + model.param_dict['conc_gal_bias'] = gal_bias_bins.min() + model.mock.populate(seed=43) + satmask = model.mock.galaxy_table['gal_type'] == 'satellites' + sats = model.mock.galaxy_table[satmask] + lowmass_value = sats['halo_mvir'][sats['halo_mvir'] >= 10**14].min() + lowmass_sats_mask = sats['halo_mvir'] == lowmass_value + lowmass_sats = sats[lowmass_sats_mask] + mean_r_by_R_lowmass_biased = np.mean( + lowmass_sats['host_centric_distance']/lowmass_sats['halo_rvir']) + + satmask = unbiased_model.mock.galaxy_table['gal_type'] == 'satellites' + sats = unbiased_model.mock.galaxy_table[satmask] + lowmass_value = sats['halo_mvir'][sats['halo_mvir'] >= 10**14].min() + lowmass_sats_mask = sats['halo_mvir'] == lowmass_value + lowmass_sats = sats[lowmass_sats_mask] + mean_r_by_R_lowmass_unbiased = np.mean( + lowmass_sats['host_centric_distance']/lowmass_sats['halo_rvir']) + + msg = ("Mocks made with unbiased profiles should have \n" + "smaller values of relative to a biased model with conc_gal_bias=0.1") + assert mean_r_by_R_lowmass_unbiased + 0.05 < mean_r_by_R_lowmass_biased, msg From 4d4424e6e83fafc9e2b90b8098f8a75c5e844e3a Mon Sep 17 00:00:00 2001 From: Andrew Hearin Date: Wed, 22 Mar 2017 17:32:20 -0400 Subject: [PATCH 5/7] Now running some of the mock_observables functions in serial during testing to avoid Travis CI build problems --- .../two_point_clustering/tests/test_marked_tpcf.py | 2 +- .../two_point_clustering/tests/test_tpcf.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/halotools/mock_observables/two_point_clustering/tests/test_marked_tpcf.py b/halotools/mock_observables/two_point_clustering/tests/test_marked_tpcf.py index 0fc210c61..0fb077b31 100755 --- a/halotools/mock_observables/two_point_clustering/tests/test_marked_tpcf.py +++ b/halotools/mock_observables/two_point_clustering/tests/test_marked_tpcf.py @@ -82,7 +82,7 @@ def test_marked_tpcf_cross1(): result = marked_tpcf(sample1, rbins, sample2=sample2, marks1=weights1, marks2=weights2, - period=period, num_threads='max', weight_func_id=weight_func_id) + period=period, num_threads=1, weight_func_id=weight_func_id) def test_marked_tpcf_cross_consistency(): diff --git a/halotools/mock_observables/two_point_clustering/tests/test_tpcf.py b/halotools/mock_observables/two_point_clustering/tests/test_tpcf.py index f8bfea2b2..5f94e2bd8 100644 --- a/halotools/mock_observables/two_point_clustering/tests/test_tpcf.py +++ b/halotools/mock_observables/two_point_clustering/tests/test_tpcf.py @@ -3,7 +3,6 @@ from __future__ import absolute_import, division, print_function, unicode_literals import numpy as np -from multiprocessing import cpu_count import warnings from astropy.tests.helper import pytest from astropy.utils.misc import NumpyRNGContext @@ -48,7 +47,7 @@ def test_tpcf_auto(): result = tpcf(sample1, rbins, sample2=None, randoms=None, period=period, max_sample_size=int(1e4), estimator='Natural', - approx_cell1_size=[rmax, rmax, rmax], num_threads='max') + approx_cell1_size=[rmax, rmax, rmax], num_threads=1) assert result.ndim == 1, "More than one correlation function returned erroneously." @@ -383,7 +382,7 @@ def test_RR_precomputed_natural_estimator_auto(): # functions called by tpcf _sample1_is_sample2 = True PBCs = True - num_threads = cpu_count() + num_threads = 1 do_DD, do_DR, do_RR = True, True, True do_auto, do_cross = True, False @@ -466,7 +465,7 @@ def test_RR_precomputed_Landy_Szalay_estimator_auto(): # functions called by tpcf _sample1_is_sample2 = True PBCs = True - num_threads = cpu_count() + num_threads = 1 do_DD, do_DR, do_RR = True, True, True do_auto, do_cross = True, False From 724cd37b9f2842a27d5023b3959966b2bb323af1 Mon Sep 17 00:00:00 2001 From: Andrew Hearin Date: Wed, 22 Mar 2017 17:37:37 -0400 Subject: [PATCH 6/7] Now no longer running the populate_mock doctest inside leauthaud11_composite_model.rst and tinker13_composite_model.rst documentation tutorials --- .../leauthaud11_composite_model.rst | 140 ++++++++--------- .../tinker13_composite_model.rst | 144 +++++++++--------- 2 files changed, 142 insertions(+), 142 deletions(-) diff --git a/docs/quickstart_and_tutorials/tutorials/model_building/preloaded_models/leauthaud11_composite_model.rst b/docs/quickstart_and_tutorials/tutorials/model_building/preloaded_models/leauthaud11_composite_model.rst index 8013e4d9a..7277c3545 100644 --- a/docs/quickstart_and_tutorials/tutorials/model_building/preloaded_models/leauthaud11_composite_model.rst +++ b/docs/quickstart_and_tutorials/tutorials/model_building/preloaded_models/leauthaud11_composite_model.rst @@ -6,32 +6,32 @@ Leauthaud et al. (2011) Composite Model .. currentmodule:: halotools.empirical_models -This section of the documentation describes the basic behavior of -the ``leauthaud11`` composite HOD model. To see how this composite -model is built by the `~halotools.empirical_models.PrebuiltHodModelFactory` class, -see `~halotools.empirical_models.leauthaud11_model_dictionary`. +This section of the documentation describes the basic behavior of +the ``leauthaud11`` composite HOD model. To see how this composite +model is built by the `~halotools.empirical_models.PrebuiltHodModelFactory` class, +see `~halotools.empirical_models.leauthaud11_model_dictionary`. Overview of the Leauthaud et al. (2011) Model Features ======================================================== -This HOD-style model is based on Leauthaud et al. (2011), arXiv:1103.2077. -The behavior of this model is governed by an assumed underlying stellar-to-halo-mass relation. - -There are two populations, centrals and satellites. -Central occupation statistics are given by a nearest integer distribution -with first moment given by an ``erf`` function; the class governing this -behavior is `~halotools.empirical_models.Leauthaud11Cens`. -Central galaxies are assumed to reside at the exact center of the host halo; -the class governing this behavior is `~halotools.empirical_models.TrivialPhaseSpace`. - -Satellite occupation statistics are given by a Poisson distribution -with first moment given by a power law that has been truncated at the low-mass end; -the class governing this behavior is `~halotools.empirical_models.Leauthaud11Sats`; -satellites in this model follow an (unbiased) NFW profile, as governed by the -`~halotools.empirical_models.NFWPhaseSpace` class. - -Building the Leauthaud et al. (2011) Model +This HOD-style model is based on Leauthaud et al. (2011), arXiv:1103.2077. +The behavior of this model is governed by an assumed underlying stellar-to-halo-mass relation. + +There are two populations, centrals and satellites. +Central occupation statistics are given by a nearest integer distribution +with first moment given by an ``erf`` function; the class governing this +behavior is `~halotools.empirical_models.Leauthaud11Cens`. +Central galaxies are assumed to reside at the exact center of the host halo; +the class governing this behavior is `~halotools.empirical_models.TrivialPhaseSpace`. + +Satellite occupation statistics are given by a Poisson distribution +with first moment given by a power law that has been truncated at the low-mass end; +the class governing this behavior is `~halotools.empirical_models.Leauthaud11Sats`; +satellites in this model follow an (unbiased) NFW profile, as governed by the +`~halotools.empirical_models.NFWPhaseSpace` class. + +Building the Leauthaud et al. (2011) Model ============================================ -You can build an instance of this model using the +You can build an instance of this model using the `~halotools.empirical_models.PrebuiltHodModelFactory` class as follows: >>> from halotools.empirical_models import PrebuiltHodModelFactory @@ -41,55 +41,55 @@ You can build an instance of this model using the Customizing the Leauthaud et al. (2011) Model ================================================= -There are two keyword arguments you can use to customize +There are two keyword arguments you can use to customize the instance returned by the factory: -First, the ``threshold`` keyword argument pertains to the minimum +First, the ``threshold`` keyword argument pertains to the minimum stellar mass of the galaxy sample, in logarithmic units of Msun in h=1 units: >>> model = PrebuiltHodModelFactory('leauthaud11', threshold = 10.75) -Second, the ``redshift`` keyword argument must be set to the redshift of the -halo catalog you might populate with this model. +Second, the ``redshift`` keyword argument must be set to the redshift of the +halo catalog you might populate with this model. >>> model = PrebuiltHodModelFactory('leauthaud11', threshold = 11, redshift = 2) -It is not permissible to dynamically change the ``threshold`` and ``redshift`` -of the model instance. If you want to explore the effects of different -thresholds and redshifts, you should instantiate multiple models. +It is not permissible to dynamically change the ``threshold`` and ``redshift`` +of the model instance. If you want to explore the effects of different +thresholds and redshifts, you should instantiate multiple models. -As described in :ref:`altering_param_dict`, you can always change the model parameters -after instantiation by changing the values in the ``param_dict`` dictionary. For example, +As described in :ref:`altering_param_dict`, you can always change the model parameters +after instantiation by changing the values in the ``param_dict`` dictionary. For example, >>> model.param_dict['alphasat'] = 1.1 -The above line of code changes the power law slope between -halo mass and satellite occupation number, :math:`\langle N_{\rm sat} \rangle \propto M_{\rm halo}^{\alpha}`. -See :ref:`leauthaud11_parameters` for a description of all parameters of this model. +The above line of code changes the power law slope between +halo mass and satellite occupation number, :math:`\langle N_{\rm sat} \rangle \propto M_{\rm halo}^{\alpha}`. +See :ref:`leauthaud11_parameters` for a description of all parameters of this model. Populating Mocks and Generating Leauthaud et al. (2011) Model Predictions =========================================================================== -As with any Halotools composite model, the model instance -can populate N-body simulations with mock galaxy catalogs. -In the following, we'll show how to do this -with fake simulation data via the ``halocat`` argument. +As with any Halotools composite model, the model instance +can populate N-body simulations with mock galaxy catalogs. +In the following, we'll show how to do this +with fake simulation data via the ``halocat`` argument. >>> from halotools.sim_manager import FakeSim >>> halocat = FakeSim() >>> model = PrebuiltHodModelFactory('leauthaud11') ->>> model.populate_mock(halocat = halocat) +>>> model.populate_mock(halocat) # doctest: +SKIP -See `ModelFactory.populate_mock` for information about how to -populate your model into different simulations. -See :ref:`galaxy_catalog_analysis_tutorial` for a sequence of worked examples -on how to use the `~halotools.mock_observables` sub-package -to study a wide range of astronomical statistics predicted by your model. +See `ModelFactory.populate_mock` for information about how to +populate your model into different simulations. +See :ref:`galaxy_catalog_analysis_tutorial` for a sequence of worked examples +on how to use the `~halotools.mock_observables` sub-package +to study a wide range of astronomical statistics predicted by your model. -Studying the Leauthaud et al. (2011) Model Features +Studying the Leauthaud et al. (2011) Model Features ====================================================== -In addition to populating mocks, the ``leauthaud11`` model also gives you access to +In addition to populating mocks, the ``leauthaud11`` model also gives you access to its underlying analytical relations. Here are a few examples: >>> import numpy as np @@ -114,49 +114,49 @@ Now suppose you wish to know the mean halo mass of a central galaxy with known s Parameters of the Leauthaud et al. (2011) model ================================================= -The best way to learn what the parameters of a model do is to -just play with the code: change parameter values, make plots of how the -underying analytical relations vary, and also of how the -mock observables vary. Here we just give a simple description of the meaning -of each parameter. You can also refer to the original -Leauthaud et al. (2011) publication, arXiv:1103.2077, and also the original -Behroozi et al. (2010) publication, arXiv:1001.0015, -for further details. A succinct summary also appears in Section 2.4 of arXiv:1512.03050. +The best way to learn what the parameters of a model do is to +just play with the code: change parameter values, make plots of how the +underying analytical relations vary, and also of how the +mock observables vary. Here we just give a simple description of the meaning +of each parameter. You can also refer to the original +Leauthaud et al. (2011) publication, arXiv:1103.2077, and also the original +Behroozi et al. (2010) publication, arXiv:1001.0015, +for further details. A succinct summary also appears in Section 2.4 of arXiv:1512.03050. To see how the following parameters are implemented, see `Leauthaud11Cens.mean_occupation` and `Behroozi10SmHm.mean_stellar_mass`. -* param_dict['smhm_m0_0'] - Characteristic stellar mass at redshift-zero in the :math:`\langle M_{\ast} \rangle(M_{\rm halo})` map. +* param_dict['smhm_m0_0'] - Characteristic stellar mass at redshift-zero in the :math:`\langle M_{\ast} \rangle(M_{\rm halo})` map. -* param_dict['smhm_m0_a'] - Redshift evolution of the characteristic stellar mass. +* param_dict['smhm_m0_a'] - Redshift evolution of the characteristic stellar mass. -* param_dict['smhm_m1_0'] - Characteristic halo mass at redshift-zero in the :math:`\langle M_{\ast} \rangle(M_{\rm halo})` map. +* param_dict['smhm_m1_0'] - Characteristic halo mass at redshift-zero in the :math:`\langle M_{\ast} \rangle(M_{\rm halo})` map. -* param_dict['smhm_m1_a'] - Redshift evolution of the characteristic halo mass. +* param_dict['smhm_m1_a'] - Redshift evolution of the characteristic halo mass. -* param_dict['smhm_beta_0'] - Low-mass slope at redshift-zero of the :math:`\langle M_{\ast} \rangle(M_{\rm halo})` map. +* param_dict['smhm_beta_0'] - Low-mass slope at redshift-zero of the :math:`\langle M_{\ast} \rangle(M_{\rm halo})` map. -* param_dict['smhm_beta_a'] - Redshift evolution of the low-mass slope. +* param_dict['smhm_beta_a'] - Redshift evolution of the low-mass slope. -* param_dict['smhm_delta_0'] - High-mass slope at redshift-zero of the :math:`\langle M_{\ast} \rangle(M_{\rm halo})` map. +* param_dict['smhm_delta_0'] - High-mass slope at redshift-zero of the :math:`\langle M_{\ast} \rangle(M_{\rm halo})` map. -* param_dict['smhm_delta_a'] - Redshift evolution of the high-mass slope. +* param_dict['smhm_delta_a'] - Redshift evolution of the high-mass slope. -* param_dict['smhm_gamma_0'] - Transition between low- and high-mass behavior at redshift-zero of the :math:`\langle M_{\ast} \rangle(M_{\rm halo})` map. +* param_dict['smhm_gamma_0'] - Transition between low- and high-mass behavior at redshift-zero of the :math:`\langle M_{\ast} \rangle(M_{\rm halo})` map. -* param_dict['smhm_gamma_a'] - Redshift evolution of the transition. +* param_dict['smhm_gamma_a'] - Redshift evolution of the transition. -* param_dict['u'scatter_model_param1'] - Log-normal scatter in the stellar-to-halo mass relation. +* param_dict['u'scatter_model_param1'] - Log-normal scatter in the stellar-to-halo mass relation. To see how the following parameters are implemented, see `Leauthaud11Sats.mean_occupation` and `Behroozi10SmHm.mean_stellar_mass`. -* param_dict['alphasat'] - Power law slope of the relation between halo mass and :math:`\langle N_{\rm sat} \rangle`. +* param_dict['alphasat'] - Power law slope of the relation between halo mass and :math:`\langle N_{\rm sat} \rangle`. -* param_dict['betasat'] - Controls the amplitude of the power law slope :math:`\langle N_{\rm sat} \rangle`. +* param_dict['betasat'] - Controls the amplitude of the power law slope :math:`\langle N_{\rm sat} \rangle`. -* param_dict['bsat'] - Also controls the amplitude of the power law slope :math:`\langle N_{\rm sat} \rangle`. +* param_dict['bsat'] - Also controls the amplitude of the power law slope :math:`\langle N_{\rm sat} \rangle`. -* param_dict['betacut'] - Controls the low-mass cutoff of :math:`\langle N_{\rm sat} \rangle`. +* param_dict['betacut'] - Controls the low-mass cutoff of :math:`\langle N_{\rm sat} \rangle`. -* param_dict['bcut'] - Also controls the low-mass cutoff of :math:`\langle N_{\rm sat} \rangle`. +* param_dict['bcut'] - Also controls the low-mass cutoff of :math:`\langle N_{\rm sat} \rangle`. diff --git a/docs/quickstart_and_tutorials/tutorials/model_building/preloaded_models/tinker13_composite_model.rst b/docs/quickstart_and_tutorials/tutorials/model_building/preloaded_models/tinker13_composite_model.rst index 59394ed31..99004bcfb 100644 --- a/docs/quickstart_and_tutorials/tutorials/model_building/preloaded_models/tinker13_composite_model.rst +++ b/docs/quickstart_and_tutorials/tutorials/model_building/preloaded_models/tinker13_composite_model.rst @@ -6,36 +6,36 @@ Tinker et al. (2013) Composite Model .. currentmodule:: halotools.empirical_models -This section of the documentation describes the basic behavior of -the ``tinker13`` composite HOD model. To see how this composite -model is built by the `~halotools.empirical_models.PrebuiltHodModelFactory` class, -see `~halotools.empirical_models.tinker13_model_dictionary`. +This section of the documentation describes the basic behavior of +the ``tinker13`` composite HOD model. To see how this composite +model is built by the `~halotools.empirical_models.PrebuiltHodModelFactory` class, +see `~halotools.empirical_models.tinker13_model_dictionary`. -.. _tinker13_model_features_overview: +.. _tinker13_model_features_overview: Overview of the Tinker et al. (2013) Model Features ======================================================== -This HOD-style model is based on Tinker et al. (2013), arXiv:1308.2974. -The behavior of this model is governed by an assumed underlying stellar-to-halo-mass relation -that is distinct for star-forming and quiescent populations. - -There are two populations, centrals and satellites. -Central occupation statistics are given by a nearest integer distribution -with first moment given by an ``erf`` function; the class governing this -behavior is `~halotools.empirical_models.Tinker13Cens`. -Central galaxies are assumed to reside at the exact center of the host halo; -the class governing this behavior is `~halotools.empirical_models.TrivialPhaseSpace`. - -Satellite occupation statistics are given by a Poisson distribution -with first moment given by a power law that has been truncated at the low-mass end; -the classes governing this behavior are `~halotools.empirical_models.Tinker13QuiescentSats` -and `~halotools.empirical_models.Tinker13ActiveSats`; -satellites in this model follow an (unbiased) NFW profile, as governed by the -`~halotools.empirical_models.NFWPhaseSpace` class. - -Building the Tinker et al. (2013) Model +This HOD-style model is based on Tinker et al. (2013), arXiv:1308.2974. +The behavior of this model is governed by an assumed underlying stellar-to-halo-mass relation +that is distinct for star-forming and quiescent populations. + +There are two populations, centrals and satellites. +Central occupation statistics are given by a nearest integer distribution +with first moment given by an ``erf`` function; the class governing this +behavior is `~halotools.empirical_models.Tinker13Cens`. +Central galaxies are assumed to reside at the exact center of the host halo; +the class governing this behavior is `~halotools.empirical_models.TrivialPhaseSpace`. + +Satellite occupation statistics are given by a Poisson distribution +with first moment given by a power law that has been truncated at the low-mass end; +the classes governing this behavior are `~halotools.empirical_models.Tinker13QuiescentSats` +and `~halotools.empirical_models.Tinker13ActiveSats`; +satellites in this model follow an (unbiased) NFW profile, as governed by the +`~halotools.empirical_models.NFWPhaseSpace` class. + +Building the Tinker et al. (2013) Model ========================================== -You can build an instance of this model using the +You can build an instance of this model using the `~halotools.empirical_models.PrebuiltHodModelFactory` class as follows: >>> from halotools.empirical_models import PrebuiltHodModelFactory @@ -45,88 +45,88 @@ You can build an instance of this model using the Customizing the Tinker et al. (2013) Model ============================================= -There are several keyword arguments you can use to customize -the instance returned by the factory. +There are several keyword arguments you can use to customize +the instance returned by the factory. -The ``threshold`` keyword argument and the ``redshift`` keyword -argument behave in the exact same way as they do in the ``leauthaud11`` model. -See :ref:`leauthaud11_composite_model` for further details. +The ``threshold`` keyword argument and the ``redshift`` keyword +argument behave in the exact same way as they do in the ``leauthaud11`` model. +See :ref:`leauthaud11_composite_model` for further details. -In the ``tinker13`` model, the quiescent fraction of central galaxies is -specified at a set of control points via the ``quiescent_fraction_abscissa`` -and ``quiescent_fraction_ordinates`` keywords. Linear interpolation is used to -for the values of the quenched fraction evaluated at distinct values from the control points. -So, for example, if you wanted to initialize your model so that the quenched fraction -at :math:`M_{\rm vir}/M_{\odot} = 10^{12}, 10^{13}, 10^{14}, 10^{15}` is +In the ``tinker13`` model, the quiescent fraction of central galaxies is +specified at a set of control points via the ``quiescent_fraction_abscissa`` +and ``quiescent_fraction_ordinates`` keywords. Linear interpolation is used to +for the values of the quenched fraction evaluated at distinct values from the control points. +So, for example, if you wanted to initialize your model so that the quenched fraction +at :math:`M_{\rm vir}/M_{\odot} = 10^{12}, 10^{13}, 10^{14}, 10^{15}` is :math:`0.25, 0.5, 0.75, 0.9`: >>> model = PrebuiltHodModelFactory('tinker13', quiescent_fraction_abscissa = [1e12, 1e13, 1e14, 1e15], quiescent_fraction_ordinates = [0.25, 0.5, 0.75, 0.9]) -As described in :ref:`altering_param_dict`, you can always change the model parameters -after instantiation by changing the values in the ``param_dict`` dictionary. For example, +As described in :ref:`altering_param_dict`, you can always change the model parameters +after instantiation by changing the values in the ``param_dict`` dictionary. For example, >>> model.param_dict['quiescent_fraction_ordinates_param1'] = 0.35 -There will be one ``param_dict`` parameter for each entry of -the input ``quiescent_fraction_ordinates``. -Once you instantiate the model you are not permitted to change the abscissa. -To do that, you need to instantiate another model. +There will be one ``param_dict`` parameter for each entry of +the input ``quiescent_fraction_ordinates``. +Once you instantiate the model you are not permitted to change the abscissa. +To do that, you need to instantiate another model. Populating Mocks and Generating Tinker et al. (2013) Model Predictions ========================================================================= -As with any Halotools composite model, the model instance -can populate N-body simulations with mock galaxy catalogs. -In the following, we'll show how to do this -with fake simulation data via the ``halocat`` argument. +As with any Halotools composite model, the model instance +can populate N-body simulations with mock galaxy catalogs. +In the following, we'll show how to do this +with fake simulation data via the ``halocat`` argument. >>> from halotools.sim_manager import FakeSim >>> halocat = FakeSim() >>> model = PrebuiltHodModelFactory('tinker13') ->>> model.populate_mock(halocat = halocat) +>>> model.populate_mock(halocat) # doctest: +SKIP -See `ModelFactory.populate_mock` for information about how to -populate your model into different simulations. -See :ref:`galaxy_catalog_analysis_tutorial` for a sequence of worked examples -on how to use the `~halotools.mock_observables` sub-package -to study a wide range of astronomical statistics predicted by your model. +See `ModelFactory.populate_mock` for information about how to +populate your model into different simulations. +See :ref:`galaxy_catalog_analysis_tutorial` for a sequence of worked examples +on how to use the `~halotools.mock_observables` sub-package +to study a wide range of astronomical statistics predicted by your model. -Studying the Tinker et al. (2013) Model Features +Studying the Tinker et al. (2013) Model Features =================================================== -In addition to populating mocks, the ``tinker13`` model also gives you access to -its underlying analytical relations. For the most part, the ``tinker13`` model simply -inherits the methods of the ``leauthaud11`` model, which you can read about -in :ref:`leauthaud11_composite_model`. However, there are slight differences -due as ``tinker13`` also models quiescent designation. +In addition to populating mocks, the ``tinker13`` model also gives you access to +its underlying analytical relations. For the most part, the ``tinker13`` model simply +inherits the methods of the ``leauthaud11`` model, which you can read about +in :ref:`leauthaud11_composite_model`. However, there are slight differences +due as ``tinker13`` also models quiescent designation. >>> import numpy as np >>> halo_mass = np.logspace(11, 15, 100) -Whereas in ``leauthaud11`` there was a ``mean_occupation_centrals`` method, -in ``tinker13`` there are instead methods for ``mean_occupation_active_centrals`` -and ``mean_occupation_quiescent_centrals``. +Whereas in ``leauthaud11`` there was a ``mean_occupation_centrals`` method, +in ``tinker13`` there are instead methods for ``mean_occupation_active_centrals`` +and ``mean_occupation_quiescent_centrals``. >>> mean_ncen_q = model.mean_occupation_quiescent_centrals(prim_haloprop = halo_mass) >>> mean_ncen_a = model.mean_occupation_active_centrals(prim_haloprop = halo_mass) -Similar comments apply to ``mean_stellar_mass`` and ``mean_log_halo_mass`` -for centrals and satellites alike. +Similar comments apply to ``mean_stellar_mass`` and ``mean_log_halo_mass`` +for centrals and satellites alike. .. _tinker13_parameters: Parameters of the Tinker et al. (2013) model ================================================= -For satellite galaxies, the ``tinker13`` model inherits all of -the parameters of the ``leauthaud11`` model twice: one set of parameters -for the star-forming satellites, a second set for the quiescent satellites. -Please refer to :ref:`leauthaud11_parameters` for details. -The same duplicate parameter inheritance applies for centrals. -Additionally, as described in :ref:`tinker13_model_features_overview`, -there are parameters specifying the quiescent fraction of -centrals at the set of control points determined by the -``quiescent_fraction_abscissa`` keyword passed to the constructor. +For satellite galaxies, the ``tinker13`` model inherits all of +the parameters of the ``leauthaud11`` model twice: one set of parameters +for the star-forming satellites, a second set for the quiescent satellites. +Please refer to :ref:`leauthaud11_parameters` for details. +The same duplicate parameter inheritance applies for centrals. +Additionally, as described in :ref:`tinker13_model_features_overview`, +there are parameters specifying the quiescent fraction of +centrals at the set of control points determined by the +``quiescent_fraction_abscissa`` keyword passed to the constructor. From 348163d4051a5720f53af8dbed833befa9639b8f Mon Sep 17 00:00:00 2001 From: Andrew Hearin Date: Wed, 22 Mar 2017 18:18:06 -0400 Subject: [PATCH 7/7] Commented out mc_generate_phase_space execution in nfw_profile_source_notes.rst --- .../phase_space_models/nfw_profile_source_notes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source_notes/empirical_models/phase_space_models/nfw_profile_source_notes.rst b/docs/source_notes/empirical_models/phase_space_models/nfw_profile_source_notes.rst index 5bb04f453..38a5f7b5d 100644 --- a/docs/source_notes/empirical_models/phase_space_models/nfw_profile_source_notes.rst +++ b/docs/source_notes/empirical_models/phase_space_models/nfw_profile_source_notes.rst @@ -221,7 +221,7 @@ method can be used to create an Astropy `~astropy.table.Table` storing a collect >>> from halotools.empirical_models import NFWPhaseSpace >>> nfw = NFWPhaseSpace() ->>> data = nfw.mc_generate_nfw_phase_space_points(Ngals = 100, mass = 1e13, conc = 10) +>>> data = nfw.mc_generate_nfw_phase_space_points(Ngals = 100, mass = 1e13, conc = 10) # doctest: +SKIP In the source code, the generation of these points happens in two steps. First, *x, y, z* points are drawn using the `~NFWPhaseSpace.mc_halo_centric_pos` method defined in the `~MonteCarloGalProf` orthogonal mix-in class. Following the same methodology described in :ref:`monte_carlo_nfw_spatial_profile`, the `~NFWPhaseSpace.mc_halo_centric_pos` method uses inverse transform sampling together with the `~NFWPhaseSpace.cumulative_mass_PDF` function to draw random realizations of dimensionless NFW profile radii; these dimensionless radii are then scaled according to the halo mass and radius definition selected by the keyword arguments passed to the `~NFWPhaseSpace` constructor. See the :ref:`monte_carlo_galprof_spatial_positions` section of the :ref:`monte_carlo_galprof_mixin_tutorial` for a detailed explanation of how this method works.