BiasedNFWPhaseSpace crashes when populating halo catalog
johannesulf opened this issue · 3 comments
The following simple code crashes with BiasedNFWPhaseSpace but works fine with NFWPhaseSpace. It's probably related to the fact that BiasedNFWPhaseSpace creates more lookup tables.
from halotools.sim_manager import FakeSim
from halotools.empirical_models import HodModelFactory
from halotools.empirical_models import TrivialPhaseSpace, Zheng07Cens
from halotools.empirical_models import BiasedNFWPhaseSpace, Zheng07Sats
halocat = FakeSim()
cens_occ_model = Zheng07Cens()
cens_prof_model = TrivialPhaseSpace()
sats_occ_model = Zheng07Sats()
sats_prof_model = BiasedNFWPhaseSpace()
model = HodModelFactory(
centrals_occupation=cens_occ_model,
centrals_profile=cens_prof_model,
satellites_occupation=sats_occ_model,
satellites_profile=sats_prof_model)
model.populate_mock(halocat = halocat)
Traceback (most recent call last):
File "test.py", line 20, in <module>
model.populate_mock(halocat = halocat)
File "/home/research/Projects/halotools/env/lib/python3.7/site-packages/halotools/empirical_models/factories/hod_model_factory.py", line 1209, in populate_mock
ModelFactory.populate_mock(self, halocat, **kwargs)
File "/home/research/Projects/halotools/env/lib/python3.7/site-packages/halotools/empirical_models/factories/model_factory_template.py", line 236, in populate_mock
self.mock.populate(**mockpop_kwargs)
File "/home/research/Projects/halotools/env/lib/python3.7/site-packages/halotools/empirical_models/factories/hod_mock_factory.py", line 346, in populate
func(table=self.galaxy_table[gal_type_slice], seed=seed, **d)
File "/home/research/Projects/halotools/env/lib/python3.7/site-packages/halotools/empirical_models/factories/model_factory_template.py", line 292, in decorated_func
return func(*args, **kwargs)
File "/home/research/Projects/halotools/env/lib/python3.7/site-packages/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/nfw_phase_space.py", line 110, in assign_phase_space
MonteCarloGalProf.mc_pos(self, table=table, seed=seed)
File "/home/research/Projects/halotools/env/lib/python3.7/site-packages/halotools/empirical_models/phase_space_models/analytic_models/monte_carlo_helpers.py", line 439, in mc_pos
x, y, z = self.mc_halo_centric_pos(*profile_params, **kwargs)
File "/home/research/Projects/halotools/env/lib/python3.7/site-packages/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/nfw_phase_space.py", line 718, in mc_halo_centric_pos
return MonteCarloGalProf.mc_halo_centric_pos(self, *concentration_array, **kwargs)
File "/home/research/Projects/halotools/env/lib/python3.7/site-packages/halotools/empirical_models/phase_space_models/analytic_models/monte_carlo_helpers.py", line 354, in mc_halo_centric_pos
x, y, z = self.mc_solid_sphere(*profile_params, **kwargs)
File "/home/research/Projects/halotools/env/lib/python3.7/site-packages/halotools/empirical_models/phase_space_models/analytic_models/satellites/nfw/nfw_phase_space.py", line 684, in mc_solid_sphere
return MonteCarloGalProf.mc_solid_sphere(self, *concentration_array, **kwargs)
File "/home/research/Projects/halotools/env/lib/python3.7/site-packages/halotools/empirical_models/phase_space_models/analytic_models/monte_carlo_helpers.py", line 299, in mc_solid_sphere
*profile_params, seed=seed)
File "/home/research/Projects/halotools/env/lib/python3.7/site-packages/halotools/empirical_models/phase_space_models/analytic_models/monte_carlo_helpers.py", line 213, in _mc_dimensionless_radial_distance
rad_prof_func_table_indices.flatten())
File "/home/research/Projects/halotools/env/lib/python3.7/site-packages/halotools/empirical_models/model_helpers.py", line 267, in call_func_table
out[ix] = f(abscissa[ix])
IndexError: index 1061093 is out of bounds for axis 0 with size 81875
Hmmm, when I run the same code using an actual catalog, rather than FakeSim, no exception is raised. So this looks like it might be a subtle bug. Have you noticed this come up in other real halo catalogs?
This is closely related to #920. I have some prototype code I'm turning into a PR in which the entire digitization of profiles is eliminated. It's just taking some time because there is kind of a lot of machinery to scrap.
Yes, I had the same bug in an actual halo catalog.
This bug was most likely introduced by cddfd5f. The crash only occurs for BiasedNFWPhaseSpace where the lookup table has two dimensions (conc, conc_gal_bias) instead of one (conc) like NFWPhaseSpace.
The fix is probably as simple as...
self.rad_prof_func_table_indices[np.array(digitized_param_list, dtype='intp')] -> self.rad_prof_func_table_indices[tuple(digitized_param_list)]