Skip to content

Commit

Permalink
Include support for empty user-supplied halo catalogs. Resolves #960
Browse files Browse the repository at this point in the history
  • Loading branch information
aphearin committed Jan 7, 2020
1 parent ce9bf4e commit cbe3190
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 19 additions & 0 deletions halotools/sim_manager/tests/test_user_supplied_halo_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, )
4 changes: 1 addition & 3 deletions halotools/sim_manager/user_supplied_halo_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down

0 comments on commit cbe3190

Please sign in to comment.