Skip to content

Commit 62724e7

Browse files
authored
Merge pull request #971 from aphearin/zero_halos_support
Include support for empty user-supplied halo catalogs.
2 parents ce9bf4e + cbe3190 commit 62724e7

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

halotools/sim_manager/tests/test_user_supplied_halo_catalog.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,3 +463,22 @@ def tearDown(self):
463463
shutil.rmtree(self.dummy_cache_baseloc)
464464
except:
465465
pass
466+
467+
468+
def test_support_for_empty_halo_catalogs():
469+
"""Regression test for #960."""
470+
Nhalos = 0
471+
Lbox = 100
472+
redshift = 0.0
473+
halo_x = np.linspace(0, Lbox, Nhalos)
474+
halo_y = np.linspace(0, Lbox, Nhalos)
475+
halo_z = np.linspace(0, Lbox, Nhalos)
476+
halo_mass = np.logspace(10, 15, Nhalos)
477+
halo_id = np.arange(0, Nhalos, dtype=np.int)
478+
good_halocat_args = (
479+
{'halo_x': halo_x, 'halo_y': halo_y,
480+
'halo_z': halo_z, 'halo_id': halo_id, 'halo_mass': halo_mass}
481+
)
482+
halocat = UserSuppliedHaloCatalog(Lbox=Lbox, particle_mass=100, redshift=0.,
483+
**good_halocat_args)
484+
assert halocat.halo_table['halo_x'].shape == (0, )

halotools/sim_manager/user_supplied_halo_catalog.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,8 @@ def _parse_constructor_kwargs(self, **kwargs):
177177
halo_id = np.array(kwargs['halo_id'])
178178
assert type(halo_id) is np.ndarray
179179
Nhalos = custom_len(halo_id)
180-
assert Nhalos > 1
181180
except KeyError:
182-
msg = ("\nThe UserSuppliedHaloCatalog requires a ``halo_id`` keyword argument "
183-
"storing an ndarray of length Nhalos > 1.\n")
181+
msg = ("\nThe UserSuppliedHaloCatalog requires a ``halo_id`` keyword argument.")
184182
raise HalotoolsError(msg)
185183

186184
halo_table_dict = (

0 commit comments

Comments
 (0)