From cbe3190f93a3e1adb9adf13d9a9af37dec96f004 Mon Sep 17 00:00:00 2001 From: Andrew Hearin Date: Tue, 7 Jan 2020 12:22:50 -0600 Subject: [PATCH] Include support for empty user-supplied halo catalogs. Resolves #960 --- .../tests/test_user_supplied_halo_catalog.py | 19 +++++++++++++++++++ .../sim_manager/user_supplied_halo_catalog.py | 4 +--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/halotools/sim_manager/tests/test_user_supplied_halo_catalog.py b/halotools/sim_manager/tests/test_user_supplied_halo_catalog.py index 95bba46cf..256256a0d 100644 --- a/halotools/sim_manager/tests/test_user_supplied_halo_catalog.py +++ b/halotools/sim_manager/tests/test_user_supplied_halo_catalog.py @@ -463,3 +463,22 @@ def tearDown(self): shutil.rmtree(self.dummy_cache_baseloc) except: pass + + +def test_support_for_empty_halo_catalogs(): + """Regression test for #960.""" + Nhalos = 0 + Lbox = 100 + redshift = 0.0 + halo_x = np.linspace(0, Lbox, Nhalos) + halo_y = np.linspace(0, Lbox, Nhalos) + halo_z = np.linspace(0, Lbox, Nhalos) + halo_mass = np.logspace(10, 15, Nhalos) + halo_id = np.arange(0, Nhalos, dtype=np.int) + good_halocat_args = ( + {'halo_x': halo_x, 'halo_y': halo_y, + 'halo_z': halo_z, 'halo_id': halo_id, 'halo_mass': halo_mass} + ) + halocat = UserSuppliedHaloCatalog(Lbox=Lbox, particle_mass=100, redshift=0., + **good_halocat_args) + assert halocat.halo_table['halo_x'].shape == (0, ) diff --git a/halotools/sim_manager/user_supplied_halo_catalog.py b/halotools/sim_manager/user_supplied_halo_catalog.py index 1e5a6ef1d..1a0cadbd9 100644 --- a/halotools/sim_manager/user_supplied_halo_catalog.py +++ b/halotools/sim_manager/user_supplied_halo_catalog.py @@ -177,10 +177,8 @@ def _parse_constructor_kwargs(self, **kwargs): halo_id = np.array(kwargs['halo_id']) assert type(halo_id) is np.ndarray Nhalos = custom_len(halo_id) - assert Nhalos > 1 except KeyError: - msg = ("\nThe UserSuppliedHaloCatalog requires a ``halo_id`` keyword argument " - "storing an ndarray of length Nhalos > 1.\n") + msg = ("\nThe UserSuppliedHaloCatalog requires a ``halo_id`` keyword argument.") raise HalotoolsError(msg) halo_table_dict = (